Commit Graph

835 Commits

Author SHA1 Message Date
Karel Zak 1eee1acb24 script: add --echo
It some cases it makes sense to disable ECHO flag also when script
used in pipe. This new option allows to keep full control in user's
hands.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-25 12:39:52 +01:00
Karel Zak 95d255a819 scriptlive: terminate session at end of the log
We need a proper way how to inform child (shell) that the game is
over. It seems the best is to send EOF to child rather than
immediately break PTY mainloop where we have poll(), because shell can
still produce data etc.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-22 13:03:35 +01:00
Karel Zak 4169bcb766 script: fix ECHO use, improve shell exec
For tools like su(1) is ECHO flag unexpected for use-case like

	echo 'date' | su - user

but script(1) need the echo to keep input recorded.

The patch also return execlp() use to script(1) code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-21 12:28:51 +01:00
Karel Zak 456bcbca6b agetty: add support for /run/issue and /usr/lib/issue
Addresses: https://github.com/karelzak/util-linux/issues/828
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-12 10:26:35 +01:00
Karel Zak 8e1b131e0a build-sys: use parse-date() only for hwclock
The parse-date.y is used only for hwclock, let's keep it together.
Note that the file (originally from gnulib) has GPLv3 license, so it's
better to make it obvious that we use it really only for hwclock (also
GPL).

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-07 09:02:23 +01:00
Karel Zak 787226dc28 include/strutils: add strdup_between_structs()
* improve strdup_to_offset() readability

* add strdup_between_offsets() and strdup_between_structs() to have
  better support for use-cases when we copy structs

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-31 12:25:08 +01:00
Patrick Steinhardt b2a1a69155 lib/path: fix missing header for `struct stat`
In commit b1418ed14 (lib/path: add ul_path_stat(), fix absolute paths,
2019-10-15), a new function `ul_path_stat()` was added to "path.h". This
new function prototype causes a compiler warning on musl libc based
systems due to one of the parameters having the unknown type `struct
stat` due to the <sys/stat.h> header not being included.

Fix the warning by including the header.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2019-10-17 12:46:33 +02:00
Karel Zak 488f65fcb8 lib/fileutils: add close_all_fds()
The classic way which is based on file-descriptors table size is
pretty expensive (due to table size) and forces code to do many
unnecessary close() calls. It seems better to use /proc/self/fds and
close used descriptors only.

Addresses: https://github.com/karelzak/util-linux/issues/883
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-17 10:44:57 +02:00
Karel Zak b1418ed146 lib/path: add ul_path_stat(), fix absolute paths
* add ul_path_stat()

* make sure all paths for ul_path_..() functions are always
interpreted relatively to the context directory and prefix. This is
difference between ul_path_ API and standard libc "at" functions. We
do not use any exception for absolute paths. The reason is that we
need to read from prefixed paths although application assume absolute
path (/dev/sda1 means /prefix/dev/sda1 if a /prefix is defined).

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-15 11:59:16 +02:00
Karel Zak bdd4335706 lib/pty-session: make wait_child callback optional
Now the code is duplicate on many places, but all we usually need is to
remember child status. It seems good enough to have very simple
callback child_die() to inform application about a change.

The patch also add PID to all signal related callbacks.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-08 13:11:54 +02:00
Karel Zak 4f7f723b31 lib/pty-session: add loggin callback to code, follow return codes
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-08 13:11:54 +02:00
Karel Zak 04f0c95f93 lib/pty-session: add log callbacks
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-08 13:11:54 +02:00
Karel Zak ab61a03881 lib/pty: save sigmask, add API to free all resources
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-08 13:11:54 +02:00
Karel Zak 4d5b2fed8f lib/pty: allow use callback from mainloop
This allows to control mainloop behavior from PTY applications. For
example you can write to child (shell) process independently on the
current stdin.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-08 13:11:54 +02:00
Karel Zak 6954895cae lib/pty-session: add generic PTY container code
The idea is to consolidate script(1), scriptlive(1) and su(1) --pty
and use the same code everywhere.

TODO: add callbacks for stdin/out logging (necessary for script(1)).

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-08 13:11:54 +02:00
Karel Zak 23afadca57 include/strutils: add strrealloc() 2019-10-08 13:11:53 +02:00
Elliott Mitchell 2bb3aa36b2 cleanup: Remove some spurious spaces
Sorry detail-oriented people tend to wipe these out if they notice them.
Add in automated tools and lots of excess end-of-line spaces get wiped
out.

Addresses: https://github.com/karelzak/util-linux/pull/849
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-01 13:01:43 +02:00
Quentin Rameau cd083615b4 lib/pwdutils: add xgetpwuid 2019-09-26 15:55:39 +02:00
Karel Zak b2ce7d5827 include/all-io: remove unnecessary condition [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-20 16:00:13 +02:00
Karel Zak 7618b3be4b build-sys: fix UTIL_LINUX_PT_SGI_H macro [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-20 15:31:31 +02:00
Sami Kerola 218b1dd6f9
misc: fix typos [codespell]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-09-12 19:41:46 +01:00
James Peach cef4decf04 unshare: add --keep-caps option
Add the --keep-caps option to unshare to preserve capabilities that
are granted when creating a new user namespace. This allows the child
process to retain privilege within the new user namespace without also
being UID 0.
2019-09-09 20:23:08 -07:00
Patrick Steinhardt 530220b6bf include/closestream: fix assignment to read-only standard streams
In order to avoid closing standard streams multiple times, commit
52aa1a661 (include/closestream: avoid close more than once, 2019-06-13)
introduced code to set the standard output and error streams to `NULL`.
As musl libc defines standard streams as constant pointers, the change
causes compiler errors on systems with that libc. According to ISO C89,
being able to assign to the standard text streams is not a requirement
for any C implementation, see footnote 238 in chapter §7.19.5.6:

    The primary use of the freopen function is to change the file
    associated with a standard text stream (stderr, stdin, or stdout),
    as those identifiers need not be modifiable lvalues to which the
    value returned by the fopen function may be assigned.

This commit implements a new function `flush_standard_stream` that tries
to reliably flush standard streams without actually closing them. By not
calling fclose(3P), we can neatly avoid the issue of accessing standard
streams in an unspecified state and thus remove the infringing `NULL`
assignments.

Properly flushing standard streams without fclose(3P) proves to be more
intricate than one may expect, though, as some filesystems like NFS may
defer flushing until they see a close(3P) of the underlying descriptor.
One may call fsync(3P) to remedy that, but this may incur a heavy
performance penalty in some scenarios. To work around the issue and
still get proper errors, we duplicate the stream's file descriptor and
close that one instead, which is sufficient to cause a flush.

Note that both `close_stdout` and `close_stdout_atexit` are misnamed
after this change, as we do not actually close the streams now. In order
to avoid unnecessary code churn, we still retain their current names.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2019-09-02 11:55:56 +02:00
Sami Kerola 273ebba11d include/xalloc: reindent function bodies to unify indentation
The file used unusual 7 spaces indent step in some of the functions.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-21 15:00:16 +02:00
Sami Kerola aba9e76e25 include/xalloc: use multiline function declarations
There are two things happening in this commit.  1) Move each function
attribute to it's own line 2) move function return value after attributes so
that function inputs and outputs are on same line.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-21 15:00:16 +02:00
Rosen Penev 76b680b1a9
Remove isascii usage
There is a c_isascii function that can be used.

isascii is deprecated and not available with some libcs like uClibc-ng
where it can be compile time disabled.
2019-08-08 12:12:55 -07:00
Sami Kerola f3aded3fdb
include/xalloc: ensure xstrdup() and xstrndup() returns nonnull attribute
Turned out lsblk is passing null as argument to xstrdup(), so fix that and
add assert() to make sure promise of not returning null is kept in future.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-07-14 11:52:13 +01:00
Karel Zak bddcf5b816 Merge branch 'topic/wdctl' 2019-06-17 15:48:28 +02:00
Karel Zak b3dd29d1b8 wdctl; read from /sys if necessary
The device can be inaccessible for non-root user or busy (already used
by another process). In this case it seems better to read information
from /sys.

Note that /sys does not provide struct watchdog_info.options, so we
cannot print list of supported watchdog features.

Addresses: https://github.com/karelzak/util-linux/issues/804
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-17 15:47:39 +02:00
Karel Zak 8c8df42146 wdctl: default to /dev/watchdog0
Let's use miscdev /dev/watchdog as fallback only. We need (if possible)
cdev /dev/watchdog0 as this device has entry in /sys/class/watchdog.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-17 15:47:39 +02:00
Karel Zak 52aa1a6611 include/closestream: avoid close more than once
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-17 15:46:10 +02:00
Karel Zak a6d9d23b5f lib/ttyutils: introduce get_terminal_stdfd()
Let's use separate function to detect what is the current terminal.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-27 12:49:12 +02:00
Karel Zak 1a56f15b0f libfdisk: (sgi) improve checksum calculation [-Waddress-of-packed-member]
Let's keep compilers and static analyzers happy. The idea is to use
memcpy() to copy from buffer to variable and use all label as unsigned
char rather than vectorize by uint32_t.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-22 17:42:48 +02:00
Karel Zak 34b0a305f6 include/c: use __has_attribute
The __has macros are more portable (supported by gcc as well as
clang).

The old __GNUC_PREREQ is deprecated and it should be removed in
future. (Well, the __has macros are supported since gcc 5, so we
should be patient as some old stable distros (e.g. RHEL 7) use gcc
4.x).

This patch helps clang to correctly analyze our xalloc.h stuff.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-21 16:27:17 +02:00
Sami Kerola d2a1ee4e56
include/strutils: fix potential null pointer dereference
Recent lscpu fix caused gcc -Wnull-dereference to go off that this change
addresses.

Reference: b94acada9e
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-16 22:05:07 +01:00
Sami Kerola b94acada9e
lscpu: move trailing null after removing characters from a string
From the test input string ':' characters are removed:

    cat x86_64-epyc_7451/sys/devices/system/cpu/vulnerabilities/spectre_v2
    Mitigation: Full AMD retpoline, IBPB: conditional, STIBP: disabled, RSB filling

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-16 11:45:47 +01:00
Karel Zak 084365f1a1 build-sys: use __SANITIZE_ADDRESS__ rather than custom USE_CLOSE_ATEXIT
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-07 12:59:52 +02:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Karel Zak 31c66833cb include/closestream: add close_stdout_atexit()
It seems better to have a way to control when atexit(close_stdout()) is
used, because close stdout means that for example ASAN (or another
into binary integrated tool) is not able to print the final summary.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 13:42:34 +02:00
Karel Zak 3c4ff2dc9d include/strutils: add functions to replace and remove chars from string
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-11 13:13:06 +02:00
Karel Zak 7761bd3bb6 lib/fileutils: add xreaddir()
Remove duplicate code and keep only one implementation in
include/fileutils.h.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-11 13:11:53 +02:00
Karel Zak 6c9ab254ae libmount: don't use sscanf() for swaps parsing
Addresses: https://github.com/karelzak/util-linux/issues/780
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-08 15:16:23 +02:00
Karel Zak 86673b3a46 libmount: don't use sscanf() for mountinfo parsing
Addresses: https://github.com/karelzak/util-linux/issues/780
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-08 14:45:56 +02:00
Sami Kerola fcb89ba7bb include/path.h: remove duplicate header inclusion
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-18 13:21:46 +01:00
Sami Kerola e73456dfbb include: add no return function attribute
This warning is repeated 112 times when compiling with all warnings.

xalloc.h:23:1: warning: function '__err_oom' could be declared with
attribute 'noreturn' [-Wmissing-noreturn]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-18 13:21:23 +01:00
Karel Zak 07b94c9f32 lib/strutils: support two decimal places in size_to_human_string() output
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-12 14:20:55 +01:00
Karel Zak 5db5962339 lib/colors: force to "never" mode on non-terminal output
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-04 14:14:37 +01:00
Karel Zak 75d239ffd8 lib/loopdev: set blocksize when create a new device
The partition scanner in kernel depends on blocksize. We need to set
the blocksize before we call LOOP_SET_STATUS64 (this ioctl triggers
the scanner).

This patch extends the internal API to save blocksize into loopdev
context to be usable later for loopcxt_setup_device().

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-01-22 11:37:35 +01:00
Karel Zak 9fcc893624 lib/loopdev: differentiate between setter()s and ioctl calls
Now the internal API uses loopcxt_set_...() to set context variables
as well as to call ioctls. This patch introduces loopcxt_ioctl_...()
to makes things more obvious to readers.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-01-22 11:12:42 +01:00
Sami Kerola ee6e39305c
include: add indirect monotonic clock id specifier
Avoid repeated ifdef checks in code by adding a project specific
preprocessor definition.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-01-12 08:46:53 +00:00
Sami Kerola d393c00c6c
timeutils: match today day and this year correctly
Assumption all years since 1970 have been exactly 365 days long has it's
problems when leap years happen.  Lets use struct tm fields that are
provided by localtime_r(), making year and day to be correctly compared even
when it's late new years eve somewhere else than UTC-0.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-01-12 08:46:29 +00:00
Karel Zak c455cdb30d choom: fix negative adjust score usage
It's really bad idea to use uint64_t (ul_path_write_u64(()) when write
signed number.

Addresses: https://github.com/karelzak/util-linux/issues/723
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-10 14:26:04 +01:00
Karel Zak d046b67541 Merge branch '2018wk48' of https://github.com/kerolasa/util-linux
* '2018wk48' of https://github.com/kerolasa/util-linux:
  include/c: check returns_nonnull function attribute with __GNUC_PREREQ
2018-12-10 11:58:04 +01:00
Karel Zak 7ca122ba84 include/list: add list_entry_is_first() and list_count_entries()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak c9ea91d41e lib/path: allow to close dirfd
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak 93c687d895 lib/sysfs: add function to detect partitioned devices
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 6df5acf970 lib/timer: add fallback if timer_create() not available
* add struct ul_timer as API abstraction to hide differences between
timer_create() and setitimer()

* add setitimer() detection to ./configure.ac

* add fallback code to use setitimer() if timer_create() not available
  (for example on OSX)

Addresses: https://github.com/karelzak/util-linux/issues/584
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-03 11:23:33 +01:00
Ruediger Meier 1866fa6a59 include/c: re-add type checking in container_of()
This reverts parts of commit eb06d5d4, which seems to be based on
Linux kernel commit c7acec71. Unlike the original kernel patch we did
not add that even stronger type checking by using macro BUILD_BUG_ON_MSG.
So basically we removed a useful warning when compiling such
broken code:

      struct st {
            int a;
            char b;
      };
      struct st t = { .a = 1, .b = 2 };
      struct st *x = container_of(&t.a, struct st, b);
      printf("%p %p\n", (void *)&t, (void *)x);

Moreover we also introduced a new compiler warning for intel/icc:
   "arithmetic on pointer to void or function type"

Let's just revert the update of container_of() because adding a
kernel-like BUILD_BUG_ON_MSG would be too much noise and also
problematic (see kernel commit c03567a8). Also note that the original
problem addressed by the kernel commit seems to be only reproducible
with gcc 4.9, not with any later gcc nor clang,icc. Moreover, currently
we have no such use-case in the UL sources anyways.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-12-03 10:29:56 +01:00
Sami Kerola 3ccbdf7aa4
include/c: check returns_nonnull function attribute with __GNUC_PREREQ
Karel pointed out previous commit could have been better in github feedback,
so lets use the version check macro instead of compare versions directly.

Previous-commit: f1b327f8d5
Reference: https://github.com/karelzak/util-linux/pull/704#issuecomment-432605211
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-12-02 16:28:22 +00:00
Sami Kerola f1b327f8d5
include/c: use returns_nonnull function attribute in xalloc.h
Let the compiler optimize based on the knowledge that the return value will
never be null.

Reference: https://patchwork.ozlabs.org/patch/281112/#631159
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-11-21 20:54:18 +00:00
Justin Chen e1686b25ac rtcwake: use poweroff if shutdown is not found
Some systems do not have the shutdown command. Use poweroff as an
alternative.

Signed-off-by: Justin Chen <justinpopo6@gmail.com>
2018-11-06 12:34:02 +01:00
Karel Zak a338eb4a46 include/c: add str2memcpy() and mem2strcpy()
str2memcpy() - copy zero terminated string to optionally terminated buffer

mem2strcpy() - copy from buffer to zero terminated string

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-03 17:03:11 +02:00
Sevan Janiyan 671295131e include/ttyutils: define values if missing.
Upstreamed from pkgsrc.

Addresses: https://github.com/karelzak/util-linux/pull/695
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-03 15:43:45 +02:00
Sevan Janiyan 7d5976f89a include/c: add NAME_MAX compat
Upstreamed from pkgsrc.

Addresses: https://github.com/karelzak/util-linux/pull/695
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-03 15:43:36 +02:00
Karel Zak 5b82289b60 lib/strutils: return from xstrmode()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-09-14 16:26:38 +02:00
Ludwig Nussel 4866b71786 Add built in fallbacks for motd file
Use several locations for built in default for motd to allow for
e.g. run time generated motd without having to modify config files.
login.c already splits by colon.

/usr/share/misc/motd
  - chould be shipped by distributions
/run/motd
  - potentially run time created file with dynamic information
/etc/motd
  - for the admin fill with local information

Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
2018-09-07 09:47:25 +02:00
Karel Zak 78c66fc61d lib/mangle: const quialifier cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 15:31:42 +02:00
Karel Zak eb06d5d4b2 include/list, include/c: update and container_of()
* update container_of() to version without "const" qualifier

* use container_of() in list_entry()

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 15:22:35 +02:00
Karel Zak 47afae0caa libblkid: const qualifier cleanup
* use "const" in functions where we don't modify arguments

* use "const" when cast from const buffer to any struct (superblock etc.)

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 15:05:32 +02:00
Karel Zak 34708190d1 include/all-io: const cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 14:53:25 +02:00
Karel Zak 8a7aeeda67 include/strutils: remove unnecessary cast
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 12:52:09 +02:00
Karel Zak 2cb147e026 include/path: make sure PATH_MAX is defined
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 14:24:01 +02:00
Karel Zak 83bbeb77c1 lib/path: allow dir-path formatting
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:49:03 +02:00
Karel Zak 5a89aa99a7 lsblk: use prefix for DM name
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:19:28 +02:00
Karel Zak ab628c7c18 lib/sysfs: cleanup function names
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:19:28 +02:00
Karel Zak 9023b20123 lib/path: add ul_prefix_fopen(), improve cpuset funcs
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:07:46 +02:00
Karel Zak 7eb8e47bcd lib/path: add ul_path_read_buffer()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:07:46 +02:00
Karel Zak e74e5401e1 lib/path: add ul_path_get_abspath()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:07:46 +02:00
Karel Zak 8c3d9cad1e lib/sysfs: add sysfs_blkdev_get_parent()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:07:46 +02:00
Karel Zak bcf445fd68 lib/path lib/sysfs: add debug
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:07:46 +02:00
Karel Zak 7604f85fb6 lib/loopdev: use new ul_path_* API
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:07:46 +02:00
Karel Zak 83029ea577 lib/sysfs: add ul_new_sysfs_path() shortcut
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:07:46 +02:00
Karel Zak 5387c01517 lib/sysfs: new implementation
* reuse ul_path_* API

* allow to use prefix for sysfs paths, so we can use snapshots from
  sysfs for regression tests

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 12:56:16 +02:00
Karel Zak 1ed21c80ed lib/path: new implementation
The goal is to avoid duplicate code in path.c and sysfs.c and make it
possible to define prefix for paths for all sysfs and procfs based
utils. Now we have /proc snapshots (for tests) for lscpu only. It
would be nice to have the same (for sysfs) for lsblk and another tools.

* very simple API to read numbers, strings and symlinks

* based on openat()

     pc = ul_new_path("/sys/block/sda");
     ul_path_read_u64(pc, &size, "size");
     ul_path_read_u64(pc, &lsz, "queue/logical_block_size");

* printf-like API to generate paths, for example:

     ul_path_readf_u64(pc, &num, "sda%d/size", partno)

* allow to define prefix to redirect hardcoded paths to another
  location, for example:

     pc = ul_new_path("/sys/block/sda");
     ul_path_set_prefix(pc, "/my/regression/dump");
     ul_path_read_u64(pc, &num, "size");

  to read /my/regression/dump/sys/block/sda/size

* allow to extend the API by "dialects", for example for sysfs:

     pc = ul_new_path(NULL);
     sysfs_blkdev_init_path(pc, devno, NULL);

  and use ul_path_* functions to read from @pc initialized by
  sysfs_blkdev_init_path()

* add test_path binary

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 11:58:10 +02:00
Sami Kerola 33b2e30284 include/pt-mbr.h: fix integer overflow
gcc -fsanitize=undefined gives following warning.

include/pt-mbr.h:27:51: runtime error: left shift of 248 by 24 places cannot
be represented in type 'int'

It looks like char is converted internally to int before bit-shift, and that
type overflows when char value is greater than 127.  Following code snippet
will show the effect what is stored when undefined behaviour happens.

    #include <stdio.h>
    #include <inttypes.h>
    int main(int argc, unsigned char **argv)
    {
        char p[] = { 170, 170, 170, 170 };
        unsigned int uint = p[3];
        uint64_t res = 0;
        /* overflow */
        res = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
        printf("%" PRIu64 "\n", res);
        /* this is fine */
        res = 0;
        res = p[0] | (p[1] << 8) | (p[2] << 16) | (uint << 24);
        printf("%" PRIu64 "\n", res);
        return 0;
    }

I tested gcc 8.1.0, clang 6.0.0, and tcc 0.9.27 and they all printed the
same values.

    $ ./a.out
    18446744073709551530
    4294967210

Because output is result of undefined behavior what is stored may change in
future, and other compilers / version might do something different.  In the
case of what pt-mbr.h the destination data type size was commonly 32 bits in
size, that truncated excess rubbish from bitshift.  Needless to say that was
not very robust code.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-28 13:36:38 +02:00
Karel Zak 4d9b788d64 script: add more info to script header
This patch introduces [...] to store extra information about terminal
to the typescript header. For example:

  Script started on 2018-05-14 12:52:32+02:00 [TERM="xterm-256color" TTY="/dev/pts/3" COLS="190" LINES="53"]

or

  Script started on 2018-05-14 12:54:01+02:00 [<not executed on terminal>]

if stdout is not terminal.

Addresses: https://github.com/karelzak/util-linux/issues/583
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-14 12:51:50 +02:00
Sami Kerola bf99940f64 lib/canonicalize: fix truncation warning
lib/canonicalize.c: In function ‘canonicalize_dm_name’:
lib/canonicalize.c:42:45: warning: ‘%s’ directive output may be truncated
writing up to 255 bytes into a region of size 244 [-Wformat-truncation=]
   snprintf(path, sizeof(path), "/dev/mapper/%s", name);

Notice that this warnign fix does not improve code enormously.  The earlier
snprintf() truncation will not happen a bit earlier when fgets() is called.
In that sense this change merely makes one easy to silence warning to
disappear, and therefore improve change of noticing useful messaging as such
crops up.

[kzak@redhat.com: - use macro rather than hardcoded string for mapper path]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-10 11:20:56 +02:00
Sami Kerola b211467f77 closestream: remove dummy function __fpending()
Exclude __fpending() from build when function is not available.  This is
more obvious than adding a dummy function and expecting compiler to
eliminate it as dead code.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-03-27 13:51:02 +02:00
Tony Asleson 80ec018c6a libblkid: ignore private Stratis devices
[kzak@redhat.com: - tiny coding style changes]

References: 20e1c3dc03
Signed-off-by: Tony Asleson <tasleson@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-09 13:34:42 +01:00
Ruediger Meier 73afd3f8e8 misc: fix typos using codespell
Some more funny typos, please review carefully.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-02-16 11:12:52 +01:00
Karel Zak cf654e1c3e include/c: add errexec()
The new errexec() macro consolidate and unify the way how util-linux
tools react to failed exec()-like functions:

 * exit code 126 when program located, but not usable
 * exit code 127 when could not find program to exec

The exit codes are compatible with coreutils.

Note that all the change is located in c.h; the file exitcodes.h
contains API specific (mkfs, fsck, ...) codes only.

Addresses: https://github.com/karelzak/util-linux/pull/311
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 14:58:52 +01:00
Karel Zak 117d079199 lib/exec_shell: cleanup function attributes
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 12:25:39 +01:00
Rafal Luzynski 4e12a62e88 cal: Use ALTMON_* correctly
cal: use ALTMON_* and _NL_ABALTMON_* constants to display
months in a standalone form correctly.  These constants have just
been newly added to glibc.  ALTMON_x has been used in BSD family
since 1990s and has been accepted as the future POSIX extension.
_NL_ABALTMON_* is exclusively a GNU extension but it is expected
to be added to POSIX in future.

More info: https://sourceware.org/bugzilla/show_bug.cgi?id=10871
2018-01-22 11:50:50 +01:00
Karel Zak a15dca2f6d include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()
Let's make it possible to use debug.h without environment variables.

Suggested-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-17 13:58:29 +01:00
Karel Zak 7bd0c1ae18 include/debug: improve debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-12 13:46:49 +01:00
Karel Zak 66643f3151 include/debug: print info when addresses suppressed
Suggested-by: Peter Cordes <peter@cordes.ca>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-12 13:37:05 +01:00
Karel Zak 6d00cfb233 include/debug: don't print pointer address for SUID programs
* introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing

* use __UL_DEBUG_FL_NOADDR when SUID

* move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK
  to provide access to the current mask from ul_debugobj(). It's better
  than modify all ul_debugobj() calls and use the global mask as
  argument.

* remove never used UL_DEBUG_DEFINE_FLAG

Reported-by: halfdog <me@halfdog.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-12 11:01:26 +01:00
Karel Zak 42dea85c5a lib/md5: use ul_/UL_ prefix
The symbols names are too generic.

Addresses: https://github.com/karelzak/util-linux/issues/548
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-12 12:06:15 +01:00
Karel Zak 3bd55be742 lib/sha1: use ul_/UL_prefix for symbols
Unfortunately, the symbols are visible in statically compiled libuuid
and the names are too generic.

Addresses: https://github.com/karelzak/util-linux/issues/548
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-12 11:29:02 +01:00
Sami Kerola 0b7e477188 lib/signames: remove unused function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-28 14:39:17 +01:00
Karel Zak 365ed9f639 lib/mbsalign: add mbs_invalid_encode()
Like mbs_safe_encode(), but it does not care about control chars.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-22 14:41:10 +01:00
Karel Zak d9a388d30c build-sys: add missing include
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-16 14:41:01 +01:00
John Groves 277e777fe8 lib: Add simple crc32c() function
Source: freebsd/sys/libkern/crc32.c
This code is an unmodified fragment from the source.  Will fixup
comments / naming in next commit

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-16 11:44:39 +01:00
J William Piggott 4111bb3ab5 lib/timeutils: add common ISO timestamp masks
* Start the ISO format flags at bit 0 instead of bit 1.

* Remove unnecessary _8601 from ISO format flag names to
  avoid line wrapping and to ease readability.

* ISO timestamps have date-time-timzone in common, so move
  the TIMEZONE flag to bit 2 causing all timestamp masks
  to have the first three bits set and the last four bits
  as timestamp 'options'.

* Change the 'SPACE' flag to a 'T' flag, because it makes
  the code and comments more concise.

* Add common ISO timestamp masks.

* Implement the ISO timestamp masks in all applicable code
  using the strxxx_iso() functions.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-11-10 16:34:55 -05:00
J William Piggott 9fd0a7a96c lib/timeutils: add get_gmtoff()
This new function returns the GMT offset relative to its
argument. It is used in this patch to fix two bugs:

1) On platforms that the tm struct excludes tm_gmtoff,
   hwclock assumes a one hour DST offset. This can cause
   an incorrect kernel timezone setting. For example:

 Master branch tested with tm_gmtoff illustrates the correct offset:
$ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday
Calling settimeofday(1507494204.192398, -660)

 Master branch tested without tm_gmtoff has an incorrect offset:
$ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday
Calling settimeofday(1507494249.193852, -690)

 Patched tested without tm_gmtoff has the correct offset:
$ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday
Calling settimeofday(1507494260.194208, -660)

2) ISO 8601 'extended' format requires all time elements
   to use a colon (:).

Current invalid ISO 8601:
$ hwclock
2017-10-08 16:25:17.895462-0400

Patched:
$ hwclock
2017-10-08 16:25:34.141895-04:00

Also required by this change:
login-utils/last.c: increase ISO out_len and in_len by one to
                    accommodate the addition of the timezone colon.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-11-10 16:14:04 -05:00
J William Piggott 8c5a21f218 lib/timeutils: ISO_8601_BUFSIZ too small
Although iso-8601 specifies years as 4 digits, it allows
them to be wider.

The current POSIX year width is limited by 'int tm_year'
at 10 digits plus a negative sign.

That, and the possibility of nanosecond time makes the
widest POSIX iso-8601 time 41 characters. Plus the \0
string terminator yields a buffer size of 42.

Before truncated output:
/sbin/hwclock --utc --noadjfile --predict --date '-2147483765 years'
-2147481748-09-25 20:29:45.0000

Patched:
./hwclock --utc --noadjfile --predict --date '-2147483765 years'
-2147481748-09-25 20:17:21.000000-0456

./hwclock --utc --noadjfile --predict --date '-2147483766 years'
hwclock: invalid date '-2147483766 years'

Comparable to coreutils 'date' command:
date -Ins --date '-2147483765 years'
-2147481748-09-25T19:49:31,578899297-0456

date -Ins --date '-2147483766 years'
date: invalid date '-2147483766 years'

The 'date' output illustrates the full 41 character POSIX iso-8601

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-11-10 15:49:45 -05:00
Karel Zak 1fc82a1360 agetty: add support for /etc/issue.d
The /etc/issue file has been originally designed to inform users
about the system (version, name, etc.).

In last years is growing number of additional tools (containers,
maintenance tools and interfaces, ...) and many admins and downstream
maintainer want to add some tool specific hints to the issue file, but
it mess to share one file between more packages and/or scripts. The
solution is /etc/issue.d directory.

The directory is extension to the standard system /etc/issue. The
/etc/issue file has to exist, otherwise the directory will be ignored.
It means "rm /etc/issue" (or --onissue) is still the way how keep our
system silent independently on 3rd-party installed files in the
/etc/issue.d directory.

The content of the files in the directory are printed after content of
the /etc/issue. The files are printed in version-sort order and .issue
file extension is required (00-foo.issue 01-bar.issue ...).

The change is backwardly compatible.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-07 11:32:32 +01:00
Karel Zak 61b9233995 lib/mangle: return size of the decoded buffer
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-01 15:33:04 +01:00
Nik Nyby a7da792223 Fix typo in carefulputc.h
Signed-off-by: Nik Nyby <nikolas@gnu.org>
2017-10-25 00:19:19 -04:00
Karel Zak d182565be1 lib/path: make path_set_prefix() independent on cpu_set_t
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-23 15:45:01 +02:00
Karel Zak c61e986fd0 lib/signames: remove signame array from header file
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-23 13:18:57 +02:00
Niklas Hambüchen b6e1977db4 signames: Make input char buffers const 2017-10-14 04:46:13 +02:00
Niklas Hambüchen 6855f6e80b kill: Extract signal names into signames.h/signames.c 2017-10-14 04:46:13 +02:00
Stanislav Brabec a1a41597bf losetup: Add support for logical block size
Kernel since 4.14 supports setting of logical block size[1]. It allows to
create loop devices that report logical block size different from 512.

Add support for this feature to losetup.

References:
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/block/loop.c?id=89e4fdecb51cf5535867026274bc97de9480ade5

[kzak@redhat.com: - fix loopcxt_get_blocksize()
                  - remove lo_blocksize from loop_info64]

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Omar Sandoval <osandov@fb.com>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-27 14:30:02 +02:00
Karel Zak e163adb83b build-sys: fix non-blkid compilation
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-19 13:48:52 +02:00
Karel Zak 1742c8d84c lib/pwdutils: add xgetlogin()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 4f5f35fc83 login: add xgetpwnam()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
J William Piggott 08e3c9e662 hwclock: update usage()
Improve usage strings for debug and version.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-09-05 12:33:19 +02:00
Philip Prindeville 0047626887 libuuid: add support for hash-based UUIDs
Adding V3 and V5 UUIDs per RFC-4122.

[kzak@redhat.com: - fix symbols file]

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-05 11:26:39 +02:00
Sami Kerola 367f40806e
rfkill: make programming style to match util-linux project
Use the usual facilities, add translation strings, move global variables at
the beginning of the file, make usage() look as expected, add standard
command-line option parsing.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 20:32:48 +01:00
Vaclav Dolezal 6c183c283b fdisk: use strutils to trim whitespace from input
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-08-29 15:26:39 +02:00
Sami Kerola 6766397932
include: move pamfail.h to auth.c
This removes one small header file, and makes inline function to static to
only file it is used in.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-05 09:58:18 +01:00
Andreas Henriksson 8df545592d build: use --runstatedir instead of --localstatedir
The util-linux code was previously aligned to use @localstatedir@ and
the util-linux build system was set to override the default to use /run.

Current GNU Coding Standards introduced the @runstatedir@ variable
for this purpose. Lets use that instead.

The GNU default for @runstatedir@ is ${localstatedir}/run so util-linux
still override the default to be /run to preserve the status quo from
before. The only difference is that you'll now pass --runstatedir to
override the location on the command line instead of --localstatedir.

(FWIW, Debhelper in compat 11 will automatically start passing
--runstatedir=/run to all autotools configured builds. It already
passes --localstatedir=/var (to avoid it ending up with the GNU default
/usr/local/var) which breaks the util-linux build system code that
tries to default it to /run. This change will thus allow util-linux
and debhelper to work better together and avoid the need for a
package-specific override.)

Relevant historic commits:
 * commit 07a16b9d1e
   "build-sys: change --localstatedir to /run"
 * commit 80c51185d5
   "uuidd: use run configured state directory"
 * commit 01c5b78794
   "agetty: use configured run state directory"

[kzak@redhat.com: - add $runstatedir fallback for autoconf < 2.70
                  - check for unmodified $localstatedir]

CC: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-31 15:24:46 +02:00
Karel Zak 87d04a3339 partx: move partx.h to include/
Let's make the ioctls usable also for libfdisk.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:34:55 +02:00
Karel Zak 884659b32a libblkid: don't use CDROM_GET_CAPABILITY ioctl for DM devices
For some reason kernel commit e980f62353c697cbf0c4325e43df6e44399aeb64
add extra warning when the ioctl is used for DM devices. It seems we
can avoid this ioctl when the device has dm/uuid.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1469532
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-12 14:35:53 +02:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Karel Zak 07fd6640c8 Merge branch 'path-fixes' of https://github.com/rudimeier/util-linux
* 'path-fixes' of https://github.com/rudimeier/util-linux:
  hwclock: don't ifdef printf arguments
  setpriv: align --help
  tools: add segfault detection for checkusage.sh
  misc: avoid some dead initialization warnings
  lscpu: make clang analyzer happy
  lsmem: fix, using freed memory
  lib/path: add error handling to path_vcreate()
  lib/path: fix crash, pathbuf overflow
2017-06-29 15:29:33 +02:00
Ruediger Meier 81435af3be lsmem: fix, using freed memory
Simply avoiding strdup(). Error handling improved.

This was the Clang Analyzer warning:

    Memory Error, Use-after-free
    sys-utils/lsmem.c:259:3: warning: Use of memory after it is freed
                    err(EXIT_FAILURE, _("Failed to open %s"), path);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 14:04:18 +02:00
Ruediger Meier 9f3d0fce66 docs: remove some old history from manpages
We assume that users will have a kernel >= 2.6.0 and removel
references to earlier kernels. There are still a few ones
left.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 12:56:22 +02:00
Ruediger Meier e230ae7b68 lib/path: fix crash, pathbuf overflow
Before:

$ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)"
Segmentation fault (core dumped)

After:

$ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)"
lscpu: invalid argument to --sysroot: File name too long

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 21:39:35 +02:00
Ruediger Meier 551b9cd3f9 misc: update --help content again
We change

 -h, --help     display this help and exit
 -V, --version  output version information and exit

to

 -h, --help     display this help
 -V, --version  print version

Some thoughts about this:

  * use "display" for --help because it matches better if we
    would add pager support (like git --help)
  * "print" for --version to be different
  * "this" for --help is important to make clear that running
    --help would not give you any better information than the
    one you see already
  * remove "information and exit" because it's bloat for the
    short-help, everybody knows what it does if it exists

In the manpages we should use the old, longer but more correct
descriptions, inclusive a reminder if --help/--version are only
working when used as the only option. Note the term "version
information" indicates that we don't only print a single version
number.

CC: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:29:37 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
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
Karel Zak dfdb1ca818 Merge branch 'fix-exit-codes' of https://github.com/rudimeier/util-linux
* 'fix-exit-codes' of https://github.com/rudimeier/util-linux:
  misc: fix optutils.h related exit codes
  misc: fix xalloc.h related exit codes
  misc: fix more strutils related exit codes
  lib: fix strutils.h, remove STRTOXX_EXIT_CODE
  misc: fix some broken exit codes
2017-06-26 13:47:04 +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
Ruediger Meier 9c8b9fbacc lib: fix strutils.h, remove STRTOXX_EXIT_CODE
As discussed on the mailing list. We fix all places
where the non-working define STRTOXX_EXIT_CODE was used.

Regarding tunelp, also see 7e3c80a7.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 22:40:12 +02: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 8493eedd15 include: update pathnames.h
* use /dev/rtc0 (/dev/rtc was for the 'old' driver)
* remove hwclock Award workaround and alpha cmos paths
* relocate _PATH_BTMP from hwclock to login-utils
* add a comment for _PATH_BTMP and fix other login-utils comments
* add a comment for proc/cpuinfo
* remove empty shutdown.c comment from 4d43977f

Review changes
* remove 'used in' comments
* white space fixes

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-20 19:51:26 -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
Ruediger Meier 7f387c5c21 libfdisk: cleanup sun label checksum usuage
We are using now the formerly unused function sun_pt_checksum(). This
cleanup was motivated by clang compiler warning, see below. Also nice
that we are now always using uint16_t instead of short.

Warning was:

../libfdisk/src/sun.c:177:35: warning: taking address of packed member 'csum' of class or structure 'sun_disklabel' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                while(ush < (unsigned short *)(&sunlabel->csum))

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-13 18:06:36 +02:00
Karel Zak f46a8d7e66 lib/ttyutils: return terminal lines too
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-12 11:38:38 +02:00
Sebastian Rasmussen 25c7b43ee2 lib/colors: Fix bug where help text was not being translated.
This affected cfdisk, fdisk, sfdisk, cal, dmesg and hexdump.
2017-05-28 13:30:45 +08:00
Karel Zak 79055689a2 include/exitcodes: remove mount(8) exit codes
All defined by libmount now.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-27 14:26:45 +02:00
Karel Zak 97fc6ccf79 Merge branch '170415' of github.com:jwpi/util-linux
* '170415' of github.com:jwpi/util-linux:
  optutils.h: don't print non-graph characters
  hwclock: improve audit control
  hwclock: --set and --predict segmentation fault
  hwclock: make epoch functions alpha only
  hwclock: improve default function handling
2017-04-26 11:17:46 +02:00
Karel Zak 7095232d21 libfdisk: fix NLS support
The current libfdisk code uses gettext() to translate strings. It
means it follows the default text domain (as set by textdomain(3)
usually in the main program). This is useless for public shared
library.

We have call private bindtextdomain() and use dgettext() with private
domain name to be independent on the main program. For this purpose
include/nls.h supports UL_TEXTDOMAIN_EXPLICIT to use dgettext().

Note that libfdisk will continue to use util-linux.po, rather than
keep the texts in the separate file.

The nls.h has to be included only from fdiskP.h to be sure that
nls.h works as expected for the library.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-25 17:05:09 +02:00
J William Piggott 9bf13750cb optutils.h: don't print non-graph characters
There is no eloquent way to exclude/include arch dependent arguments
from the ul_excl_t array. So when an arch dependent argument is left
undefined err_exclusive_options() was printing out-of-bounds values.
This commit cause them to be skipped instead.

err_exclusive_options() shouldn't be printing out-of-bounds values
in any case.

Also change the error massage from 'options' to 'arguments' as some
programs, like hwclock, distinguish between options and functions.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-04-18 22:39:05 -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