Commit Graph

61 Commits

Author SHA1 Message Date
Ruediger Meier 789ac55e4f misc: revert to the old USAGE_HELP strings
This reverts the include/c.h part of cc7cb070.

As discussed on ml. Our current strings are imported from
coreutils and not too bad. Also the old strings are still
hardcoded at many places.

So let's revert the change, then consolidate these strings
really everywhere and then think again whether and how we
should change them.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 21:04:34 +02:00
Karel Zak c3a4cfc579 misc: consolidate usage() "Available columns"
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-26 14:09:53 +02:00
Karel Zak d6ec64e824 Merge branch '170622' of github.com:jwpi/util-linux
* '170622' of github.com:jwpi/util-linux:
  Docs: move option naming to howto-contribute.txt
  Docs: update howto-usage-function.txt
  Docs: add a comment for constants to boilerplate.c
  include/c.h: add USAGE_COMMANDS and USAGE_COLUMNS
2017-06-26 13:56:45 +02:00
Ruediger Meier a2248466e4 misc: no more errtryh()
Nowadays all our regular commands have --help options.
test_uuidd does not use translations anyways.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-25 02:22:53 +02:00
J William Piggott 6e2d5a4460 include/c.h: add USAGE_COMMANDS and USAGE_COLUMNS
* login-utils/lslogins.c: all uses changed
* misc-utils/findmnt.c: likewise
* sys-utils/blkzone.c: likewise
* disk-utils/sfdisk.c: likewise
* sys-utils/lscpu.c: likewise
* sys-utils/lsmem.c: likewise
* sys-utils/wdctl.c: likewise

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-24 13:57:12 -04:00
J William Piggott cc7cb070d9 hwclock: update --help content and grammar
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-20 19:55:08 -04:00
J William Piggott 513bfbefa2 hwclock: add usage() functions heading
Make a functions heading, similar to the existing options heading.

* include/c.h: define USAGE_FUNCTIONS
* Documentation/boilerplate.c: add USAGE_FUNCTIONS
* sys-utils/hwclock.c add functions header to usage()

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-20 19:50:38 -04:00
Karel Zak 790119b885 agetty: fix characters reorder in login prompt
The current agetty uses TIOCSTI ioctl to return already read chars
from login name back to the terminal (without read() before
tcsetattr() we will lost data already written by user). The ioctl
based solution is fragile due to race -- we can return chars when
terminal already contains another new chars. The result is reordered
chars in login name.

The solution is to use extra buffer for already read data.

Reported-by: Michael Tretter <m.tretter@pengutronix.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-27 14:54:39 +02:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Karel Zak 3077b37101 include/c.h: add errtryhelp()
Add code to print:

	Try '<progname> --help' for more information.

and exit.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 11:33:40 +01:00
Karel Zak 075d2c0754 include: move sys/sysmacros.h to c.h
The file is no portable (#ifdef HAVE_SYS_SYSMACROS_H is necessary),
but needed on many places. It seems better to keep it in c.h.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-08 14:29:45 +01:00
Ruediger Meier 40733239a7 include: provide MAP_ANONYMOUS on OSX
Hope there are no side effect when defining _DARWIN_C_SOURCE
globally.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 16:54:05 +01:00
Karel Zak f7ac9e71b1 login, mount: fix __SC_GETPW_R_SIZE_MAX usage
sysconf(_SC_GETPW_R_SIZE_MAX) returns initial suggested size for pwd
buffer (see getpwnam_r man page or POSIX). This is not large enough in
some cases.

Yes, this sysconf option is misnamed (should be _SC_GETPW_R_SIZE_MIN).

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-15 12:33:34 +01:00
Karel Zak 2c6567799d build-sys: add --disable-assert
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 13:40:44 +02:00
Guillem Jover f51275eedb include/c: Define F_DUPFD_CLOEXEC on kFreeBSD systems if missing
The kernel of FreeBSD version 10 and higher supports this fcntl command,
but the system libc, in this case glibc, might not yet know about it.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2015-06-08 12:10:04 +02:00
Sami Kerola d763c23081 include/c: define UL_ASAN_BLACKLIST address_sanitizer function attribute
The UL_ASAN_BLACKLIST allows AddressSanitizer to be switched off for
functions that cannot be checked.

Reference: http://dxr.mozilla.org/mozilla-central/source/mfbt/Attributes.h
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 11:32:38 +01:00
Karel Zak 764b697c56 libfdisk: fix bug in cmp_numbers() and partitions sorting
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-04 13:06:03 +01:00
Karel Zak 19ff8ff7c4 libfdisk: fix cfdisk freespace analyze
The problem is how fdisk_partition_cmp_start() compare numbers, the
function returns result from "a->start - b->start", unfortunately the
numbers are uint64, but function returns "int".

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-04 10:27:39 +01:00
Sami Kerola 2a0d2a8e11 include: fix compiler warnings
This change has motivation to make -Wall -pedantic compiler options to
spit a little bit less noise, which with luck will increase change to
notice real issues.

Multiple of these:

warning: ISO C forbids braced-groups within expressions [-Wpedantic]

And nearly 300 times reported:

include/c.h:75:41: warning: struct has no named members [-Wpedantic]
 #define UL_BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:35 +02:00
Benno Schulenberg 82b219f706 include/c: do not gettextize a wordless string
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-05-06 11:09:26 +02:00
Benno Schulenberg 68411ba260 include/c: remove a duplicate include
Also tweak some comments.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-05-06 11:09:21 +02:00
Sami Kerola ff1aaf9966 include/c.h: add macro to print definitions as string
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-05-04 11:42:03 +01:00
Karel Zak a5bd793996 include/c.h: prefer nanosleep() over usleep()
Let's use nanosleep() although if usleep() exists. The nanosleep
function does no interact with signals and other timers.

The patch introduces xusleep() as replacement to libc (or our fallback)
usleep(). Yes, we don't want to use struct timespec + nanosleep()
everywhere in code as nano-time resolution is useless for us.

The patch also enlarges delays in some busy wait loops. It seems
enough to try read/write 4x per second.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-24 13:04:14 +01:00
Karel Zak c9678832b1 include/xalloc: add warn_unused_result to allocation functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-09 10:44:06 +02:00
Karel Zak 2ffad204c0 include/c: add macro UL_CLOEXECSTR
... to make "e" for fopen() portable to systems without O_CLOEXEC.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-03 16:11:19 +02:00
Sami Kerola 2ba83ec2e0 docs: arch is gone, use delpart as usage() function example
The arch.c was removed in commit 27abd809.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-03-26 10:53:30 +01:00
Werner Fink b33f24b250 sulogin: make usleep() workaround work
Simply fix a compile problem found during debugging console.c

Signed-off-by: Werner Fink <werner@suse.de>
2012-12-18 15:07:58 +01:00
Karel Zak 2a31396a9c include/c: move usleep() fallback to c.h
To make it available everywhere in code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-22 11:03:09 +02:00
Karel Zak 4ca5163aa4 include/c: remove MAXHOSTNAMELEN macro
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-19 16:58:11 +02:00
Sami Kerola 1ee4dff724 include/c: add get_hostname_max() inline function
Using sysconf(_SC_HOST_NAME_MAX) does not work everywhere.  At such even
header values for hostname length should be preferred, and if nothing
else works guess the maxium being 64 bytes.

Based-on-code-by: Karel Zak <kzak@redhat.com>
CC: Mike Frysinger <vapier@gentoo.org>
References: http://www.spinics.net/lists/util-linux-ng/msg07050.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-19 14:50:27 +02:00
Karel Zak 9199f5cd0a dmesg: add fileback for SEEK_DATA
Reported-by: Bernhard Voelker <mail@bernhard-voelker.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-24 14:06:25 +02:00
Karel Zak 3a9c3f3fb7 include/c: move fallback for MAXHOSTNAMELEN to c.h
Reported-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-29 10:08:25 +02:00
maximilian attems ae278c88cf include: [c.h] protect container_of
fixes lots of warning noise:
../../../include/c.h:112:0: warning: "container_of" redefined [enabled
by default]
/usr/lib/klibc/include/stddef.h:52:0: note: this is the location of the
previous definition

Signed-off-by: maximilian attems <max@stro.at>
2012-05-23 10:31:07 +02:00
Karel Zak aa1f95c3d0 losetup: make xgetpass more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-17 17:02:34 +01:00
Davidlohr Bueso 5b9df0280a lists: add list sorting routine
We need a list sorting function, just to mention one example user that could
benefit is the lib/tt code to sort columns.

This patch adds list_sort() which uses the Merge Sort algorithm, behaving
nicely in O(nlog(n)), heavily based on the kernel's implementation[1].  The
private data (void *priv) passed to the comparison function as been removed to
adopt a qsort(3)-like syntax, and IMHO we don't really need it anyways.

[1]: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=lib/list_sort.c;h=d7325c6b103f0be078ff3672c35c468ed35738f1;hb=HEAD

[kzak@redhat.com: - use size_t in list_sort()]

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-12-16 12:37:07 +01:00
Karel Zak 640fc1b819 build-sys: check scanf %ms modifier
Without the check libmount builds on systems that has older than 2.7
glibc are silently unsuccessful.  The missing %ms modifier will, at
least, result on such system missing output of findmnt and lsblk
commands.  If either %ms or %as modifiers are present the libmount
build is disabled.

Based on patch from: Sami Kerola <kerolasa@iki.fi>

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-10-10 14:42:40 +02:00
Sami Kerola bfda68fdb1 build-sys: rename BUILD_BUG_ON_ZERO definition
Definition name is changed to UL_BUILD_BUG_ON_ZERO to avoid collision
with a system header.

../include/c.h:72:1: warning: "BUILD_BUG_ON_ZERO" redefined
In file included from /usr/include/sys/sysinfo.h:25,
                 from dmesg.c:16:
/usr/include/linux/kernel.h:34:1: warning: this is the location of the previous definition

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-10-10 13:57:16 +02:00
Petr Uzel 960cf5737e misc: use %m in format string instead of %s and strerror(errno)
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2011-09-27 15:46:07 +02:00
Karel Zak 9fc7bf00ad Merge branch 'sys-utils' of https://github.com/kerolasa/lelux-utiliteetit
* 'sys-utils' of https://github.com/kerolasa/lelux-utiliteetit: (29 commits)
  docs: add non-return function and if shorthand tips
  build-sys: fixes to USAGE_* macros
  ipcrm: check IPC syscalls
  ipcrm: add --verbose option
  ipcmk: allow high speed ipc creation
  ipcrm: add --all option
  docs: add long options to ipcs.1 man page
  docs: add long options to ipcrm.1 man page
  docs: add long options to ipcmk.1 man page
  docs: add --version to setarch.8
  docs: mention long options in ctrlaltdel.8
  ctrlaltdel: add version & help options
  docs: mention long options in pivot_root.8
  pivot_root: add version & help option
  ipcs: comment & white space clean up
  ipcs: include-what-you-use header check
  ipcs: add long options
  ipcrm: include-what-you-use header check
  ipcrm: refactor new and old main to share code
  ipcrm: exit if unknown error occurs
  ...
2011-09-27 12:56:48 +02:00
Sami Kerola 6f162034d0 build-sys: fixes to USAGE_* macros
The USAGE_BEGIN_TAIL is removed as unnecessary.

In between command specific options and --help & --version
USAGE_SEPARATOR is inserted. For now the separator is empty line.

The USAGE_MAN_TAIL is changed to take an argument.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-09-17 15:07:52 +02:00
Karel Zak e9d00e66fb include,c.h: include fcntl.h before check for O_CLOEXEC [smatch scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-12 13:53:10 +02:00
Sami Kerola cd7accd446 arch: start using arch as a usage() example
The arch command is hijacked to be example of howto write usage
as defined in Documentation/howto-usage-function.txt

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-08-28 10:50:36 +02:00
maximilian attems 4d49851351 include: [c.h] Include stdlib.h unconditionaly
No point in hiding it down in an ifdef maze,
as it may get used by exit(3).

Signed-off-by: maximilian attems <max@stro.at>
2011-08-02 13:58:46 +02:00
maximilian attems 4b2b671697 include: [c.h] move up declaration of program_invocation_short_name before usage
fixes:
../include/c.h: In function ‘errmsg’:
../include/c.h:111:26: error: ‘program_invocation_short_name’ undeclared
(first use in this function)
../include/c.h:111:26: note: each undeclared identifier is reported only
once for each function it appears in

Signed-off-by: maximilian attems <max@stro.at>
2011-08-02 13:58:24 +02:00
Davidlohr Bueso 7cf78990fc include: [c.h] add definition wrappers for old libc versions
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-29 10:35:40 +02:00
Sami Kerola 37f44962dd include: [c.h]: remove strings.h include dublicate
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-03-08 13:08:54 +01:00
Sami Kerola c764e1a41d include: [c.h]: typeof to __typeof__ fix
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-03-08 13:08:48 +01:00
Fabian Groffen eb76ca98b0 build-sys: provide alternatives for err, errx, warn and warnx
Solaris lacks err, errx, warn and warnx.  This also means the err.h header
doesn't exist.  Removed err.h include from all files, and included err.h from
c.h instead if it exists, otherwise alternatives are provided.

Signed-off-by: Fabian Groffen <grobian@gentoo.org>
2011-02-14 17:45:24 +01:00
Karel Zak 4799c95f94 include: [c.h]: add fallback for old libs without O_CLOEXEC
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-02-11 10:49:50 +01:00
Karel Zak c25dc28dff include: [c.h]: add unused attribute to ignore_result()
unfortunately, gcc 4.6

	void fn (void) {
		int foo;
		foo = bar ();
	}

evaluates that foo is never used. The __attribute__((unused)) is
necessary...

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-02-09 20:40:06 +01:00