Commit Graph

835 Commits

Author SHA1 Message Date
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
Karel Zak 24d746f705 build-sys: add missing header file
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-23 15:59:58 +01:00
Karel Zak 7e26832d70 Merge remote-tracking branch 'jwpi/hwclock-date7'
* jwpi/hwclock-date7:
  lib: add parse-date documentation
  hwclock: use parse_date function
  build-sys: add parse-date.y
  lib: add parse-date.y
2017-03-23 12:36:47 +01:00
Sami Kerola fdf8e1f595 include: fix compiler warning
./include/optutils.h:12:18: warning: null pointer dereference [-Wnull-dereference]
  for (o = opts; o->name; o++)
                 ~^~~~~~
In file included from libfdisk/src/dos.c:12:0:
./include/pt-mbr.h:25:47: warning: potential null pointer dereference [-Wnull-dereference]
  return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
         ~^~~

Well these should be impossible, so add assert() to catch possible bugs.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-13 14:48:14 +01:00
J William Piggott 7088bd8832 lib: add parse-date.y
* include/timeutils.h
    Add parse-date API

* lib/parse-date.y - new file
    Lib function that parses a date string into a timespec struct.
    Derived from gnulib-dd7a871 parse-datetime.y with these changes:
            * reduced to a single function API renamed to parse_date()
            * removed gnulib dependencies
            * removed debugging
            * converted to util-linux coding style

* include/cctype.h - new file
    Like ctype.h only hard coded to the 'C' locale.
    Used by lib/parse-date.y.
    Derived from gnulib-dd7a871 c-ctype.h with these changes:
            * removed gnulib dependencies
            * converted to util-linux coding style
            * add requisite util-linux constants

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-03-04 10:49:41 -05:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Karel Zak 8ad7f6b96a build-sys: add missing file
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-16 15:27:07 +01:00
Karel Zak 299ef2c457 lib/mbsedit: add simple buffer editor
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-16 13:47:44 +01:00
Sami Kerola bd0786895d
hwclock: improve coding style
Make string constants to be symbolical declarations.  Use longer variable
name for rtc and cmos function pointer values.  Exclude code that is
architecture specific with preprocessor directives.  And remove message
duplication.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola b72a75e993
lib: add timegm() portability function to lib/timeutils.c
Local timegm() is a replacement function in cases it is missing from libc
implementation.  Hopefully the replacement is never, or very rarely, used.

CC: Ruediger Meier <ruediger.meier@ga-group.nl>
Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-03 22:31:18 +00:00
Karel Zak 61cbc8a3f5 lib/strutils: return end pointer by isdigit_string()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-28 12:39:30 +01:00
Karel Zak 5d74cf0092 lib/list: remove LIST_HEAD macro
* the variable definition with hidden type is always horrible, for
  example:

	  int func() {
	    LIST_HEAD(foo);
	    ...
	  }

  the more readable is:

          int func() {
            struct list_head foo;

            INIT_LIST_HEAD(&foo);
            ...
          }

* the name LIST_HEAD conflict with /usr/include/sys/queue.h

* we use it only on two places in sulogin

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-05 11:54:59 +01: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
Ruediger Meier 81580f79fa agetty: remove obsolete HAVE_UPDWTMP fallback
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-07 12:35:24 +01:00
Heiko Carstens 54394eab03 lib,strutils: add strtoux[16|32|64]_or_err functions
Add helper functions which allow to parse hexadecimal numbers.
Based on a patch from Clemens von Mann.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2016-11-09 10:02:32 +01:00
Gustavo Zacarias 7f0d4d56a2 lib/crc32: prefix public functions
Make the publicly-visible crc32 library functions prefixed by ul_, such
as crc32() -> ul_crc32().
This is because it clashes with the crc32() function from zlib.
For newer versions of glib (2.50+) zlib and libblkid are required
dependencies and otherwise results in build failure when building
statically.

Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
2016-10-19 12:11:59 +02:00
Karel Zak 0b27fcc189 lib/randutils: remove unnecessary function
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-04 16:18:16 +02:00
Sami Kerola 0b404f0845 lib/strutils: make left and right trims more robust
Do not follow null pointer, and stop going any further when
ltrim_whitespace() is at the end of a string.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-09-29 11:49:08 +02:00
Igor Gnatenko 0e0943c15b debug: use const void * for ul_debugobj()
We don't modify data it's pointing out and we should not modify it.

Also remove casting to void * as gcc will do it automatically (before
we had to cast it explicitly to avoid warning on discarding 'const'
qualifier).

Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2016-09-21 08:22:35 +02:00
Karel Zak ff471d89a1 libsmartcols: support multi-line cells based on line breaks
Now libsmartcols completely control when and how wrap long
lines/cells. This is sometimes user unfriendly and it would be nice to
support multi-line cells where wrap is based on \n (new line char).

This patch add new column flag SCOLS_FL_WRAPNL.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-09-06 10:51:25 +02:00
Karel Zak a55d646bd3 lib/randutils: add xsrand() and rand_get_number()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-09-06 10:19:52 +02:00
Karel Zak e215d467ca lib/pager: cleanup and extend API
* clean up function names

* add functions to temporary redirect to the pager and then restore
  original terminal output

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-26 12:07:25 +02:00
Stanislav Brabec bfd4e1f758 loopdev: Implememt loopcxt_set_status()
Implement stand-alone loopcxt_set_status(). It allows manipulation with some
loop device parameters even if it is initialized.

Its function is limited by the kernel implementation, and only a small subset of
changes is allowed.

For more see linux/drivers/block/loop.c:loop_set_status()

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-17 12:49:06 +02:00
Karel Zak 090d8c763a include/closestream: define exit codes
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-16 13:35:06 +02:00
Karel Zak 05d8868d86 include/env: minor fixes and clean ups
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-16 12:35:57 +02:00
Sami Kerola 984a60965a
misc: always check setenv(3) return value
At least glibc setenv(3) can fail when system runs out of memory.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-08-12 21:25:36 +01:00
Franco Fichtner 0773ad14a3 pathnames: guard clashing definitions on FreeBSD 2016-08-11 15:03:50 +02:00
Karel Zak d4e89dea4e libmount: ignore redundant slashes
///aaa/bbb and /aaa/bbb/ are the same paths. This is important
especially with NFS where number of slashes are not the same in
the /proc/self/mountinfo and fstab or utab. The regular URI is

 euler://tmp

but /proc contains

 euler:/tmp

Reported-by: Ales Novak <alnovak@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-08 17:23:54 +02:00
Karel Zak c444a71b1b lib/loopdev: cleanup sizelimit check
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-04 10:49:46 +02:00
Stanislav Brabec 211e1d4609 Implement loopcxt_check_conflict()
Add a function that searches for a possible conflicting (i. e. overlaying loop
device).

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-03 11:53:28 +02:00
Stanislav Brabec 74a4705a99 Add sizelimit to internal API
Fully safe checks of loop device need to check sizelimit. To prevent need of two
nearly equal functions, introduce sizelimit parameter to several internal
functions:
loopdev_is_used()
loopdev_find_by_backing_file()
loopcxt_is_used()
loopcxt_find_by_backing_file()

If sizelimit is zero, fall back to the old behavior (ignoring of sizelimit).

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-03 11:53:28 +02:00
Karel Zak 1ca2661bb8 libsmartcols: Corrected JSON escaping
Based on patch set https://github.com/karelzak/util-linux/pull/331
from Fordi.

Addresses: https://github.com/karelzak/util-linux/issues/330
Co-Author: Bryan Elliott <fordiman@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-02 12:05:05 +02:00
Sami Kerola 285c1f3a3e
lib: try to find tty in get_terminal_name()
Try all standard terminal input/output file descriptors when finding tty
name in get_germinal_name().  This should make all invocations of the
function as robust as they can get.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-03 23:35:10 +01:00
Sami Kerola c161694682
libcommon: add ISO_8601_GMTIME that will print UTC-0 timestamps
When timestamps are intented to be conversable back from string to binary it
is best to stick with UTC-0 timezone.  This is needed in utmpdump(1).

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-06-26 21:58:18 +01:00
Karel Zak e19916c89d include/widechar: add fallback for WEOF
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-03 14:50:48 +02:00
Karel Zak 92312207e7 include/widechar: add missing fallbacks
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-03 14:41:04 +02:00
Karel Zak 638402edb0 lib/sysfs: be more smart for non-scsi devices
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-02 14:40:13 +02:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Karel Zak 0966b16b22 build-sys: add missing include/plymouth-ctrl.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-24 14:50:07 +02:00
Karel Zak eee665bb5a lib/timeutils: add strtime_short()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-24 13:21:26 +02:00
Karel Zak 33c7ffa303 include/timeutils: rewrite iso formatting functions
- use buffers rather than allocate memory
- support .usec and ,usec convention
- use strftime for timezone (we need to care about daylight
  saving time)

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-24 10:58:52 +02:00
Karel Zak 01b47d46d7 include/timeutils: use pointer for time_t
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-23 11:56:31 +02:00
Werner Fink fe3f7e17aa sulogin: agetty: use the plymouth local protocol instead the plymouth binary
for stopping plymouthd.  That do not depend on the existence of
the plymouth binary if it e.g. becomes uninstalled or an other
service is providing plymouthd facilities.

[kzak@redhat.com: - fix compiler warnings [-Wpointer-sign]
                  - use sizeof() for write_all()
                  - cast to char* for read_all]

Signed-off-by: Werner Fink <werner@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-20 11:21:10 +02:00
Karel Zak 3c201431ee lib/timeutils: add strxxx_iso() functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-11 15:31:02 +02:00
Karel Zak deb1c90327 libmount: remove duplicate code
For petty long time we have strdup_to_struct_member() macro to avoid
duplicate code when strdup() strings in setter functions. Let's use it
for libmount.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-22 13:59:06 +02:00
Karel Zak 2238214ddc libmount: try absolute target before canonicalize
The path canonicalization is expensive and in many cases unwanted due
to problems with readlink() on unreachable NFS and automounters.

This patch add a possibility to search also by $(CWD)/<path> if the
<path> is relative to reduce number of situation when we convert the
path to the canonical absolute path.

The common use-case:

	# cd /some/long/path
	# umount ./mountpoint

old version:

15543: libmount:      TAB: [0x560a99a54230]: lookup TARGET: './test'
15543: libmount:    CACHE: [0x560a99a54290]: canonicalize path ./test
15543: libmount:    CACHE: [0x560a99a54290]: add entry [ 1] (path): /mnt/test: ./test
15543: libmount:      TAB: [0x560a99a54230]: lookup canonical TARGET: '/mnt/test'
15543: libmount:      CXT: [0x560a99a54050]: umount fs: /mnt/test

new version:

15597: libmount:      TAB: [0xabf230]: lookup TARGET: './test'
15597: libmount:      TAB: [0xabf230]: lookup absolute TARGET: '/mnt/test'
15597: libmount:      CXT: [0xabf050]: umount fs: /mnt/test

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-13 12:29:16 +02:00
Kent Overstreet 7ce27dc517 libblkid: Update for newer bcache superblocks
Later version of bcache add different checksum types, and allow for superblocks
greater than 4k - skipping the checksum check (as in most other probes) is the
easiest solution.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2016-03-23 10:52:38 +01:00
Karel Zak ca8c69a9f2 Merge branch '2016-03-02/cgns' of https://github.com/hallyn/util-linux
* '2016-03-02/cgns' of https://github.com/hallyn/util-linux:
  Implement support for cgroup namespaces
2016-03-21 21:08:05 +01:00
Karel Zak 40f00b4f8e libmount: improve conversion from root= to the devname
Currently the code supports /dev/name or PARTUUID= only. We also
need to support 'maj:min' and 'hexhex' notations.

Reported-by: George Spelvin <linux@horizon.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-15 14:07:34 +01:00
Karel Zak 322e553a1c Merge branch 'port-osx' of https://github.com/rudimeier/util-linux
* 'port-osx' of https://github.com/rudimeier/util-linux:
  fdisk: fix warning, uninitialized variable
  logger: fix compiler warning, const facilitynames
  include/bitops: avoid fallbacks for more systems
  include/bitops: add casts to bswap functions
2016-03-09 13:12:50 +01:00
Sami Kerola 652822e08b misc: remove path name definitions that are unused
After this commit the following produces zero matches.

$ for i in \
_PATH_DEV_TTY \
_PATH_INITTAB \
_PATH_MNTTAB_DIR \
_PATH_MOUNTED_LOCK \
_PATH_MOUNTED_TMP \
_PATH_RC \
_PATH_REBOOT \
_PATH_SECURE \
_PATH_SECURETTY \
_PATH_SHUTDOWN_CONF \
_PATH_SINGLE \
_PATH_UMOUNT \
_PATH_USERTTY
do git grep $i; done

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-03-09 11:44:05 +01:00
Ruediger Meier d20eb029d5 include/bitops: avoid fallbacks for more systems
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-08 14:55:38 +01:00
Ruediger Meier d01c0adb83 include/bitops: add casts to bswap functions
Based on kernel sources include/uapi/linux/swab.h.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-08 14:55:17 +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 e210cfc8c8 lib: include sys/stat.h for struct stat
Compiler warning:
'struct stat' will not be visible outside of this function [-Wvisibility]

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:17:12 +01:00
Ruediger Meier dc0495166f build-sys: add and use openat build conditionals
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 15:37:25 +01:00
Ruediger Meier 1a048dc5e2 lib: move fopen_at() to fileutils.h, remove at.h
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 15:36:00 +01:00
Ruediger Meier 2208b3ccb2 lib: remove openat fallback functions (include/at.h)
I have validated that we are still compatible at least back to
  - openSUSE 11.4
  - SLE 11
  - RHEL/CentOS 6
  - OSX 10.10.x, (Xcode 6.3)
  - FreeBSD 10.2

Confirmed incompatibility:
  - OSX 10.9.x, (Xcode 6.2)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 15:33:56 +01:00
Serge Hallyn f9e7b66dbd Implement support for cgroup namespaces
Currently these are supported in #for-next.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2016-03-02 17:53:42 -08:00
Ruediger Meier 4d751c008e lib: provide fallback if mkostemp(3) missing
It's missing on OSX.

CC: Yuriy M. Kaminskiy <yumkam@gmail.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-29 13:05:18 +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
Ruediger Meier b0b24b11f8 lib: rename strmode() and setmode()
On BSD they are part of the standard C library.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 12:53:48 +01:00
Karel Zak 4683cf3673 lib/color: add more ESC seq.
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-17 12:51:15 +01:00
Karel Zak 57867795aa libsmartcols: support multibyte titles, rename wrap to padding
- let's support multibyte table titles
- use lib/mbalign.c to align the title
- rename title_wrap to title_padding (we already use "wrap" on another
  places for another things)

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-22 16:51:59 +01:00
Karel Zak 6426f926ee lib/mbsalign: fix warnings when compile without widechars
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-13 10:08:13 +01:00
Boris Egorov 43b4f7ea5f lib/tty: Pass default width to get_terminal_width()
Almost any code calling get_terminal_width() checks returned width for
non-positive values and sets it to some default value (say, 80). So,
let's pass this default value directly to the function.

[kzak@redhat.com: - get_terminal_width() refactoring]

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-06 12:22:07 +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 624996a950 libmount: add cgroup2 pseudo FS
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-08 12:16:27 +01:00
Karel Zak 4ba2a6e515 Merge branch 'races' of git://github.com/kerolasa/lelux-utiliteetit 2015-12-02 10:27:43 +01:00
Karel Zak e069296ed8 include: add missing header file
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-01 15:44:26 +01:00
Karel Zak 04a5cb58b6 namei: move icache to lib/
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-11-27 13:56:01 +01:00
Karel Zak 0e756daeb6 lslocks: use stuff from lib/procutils
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-11-25 14:17:22 +01:00
Sami Kerola 8fe1e638fa
lib/blkdev: add open_blkdev_or_file() function
Purpose of this function is to open a path that is potentially pointing to a
block device or file without races.  The function also proper open(3) flags
are used to check the device is not busy, and finally warning is been
printed if a block device happens to be misaligned.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-22 20:56:05 +00:00
Sami Kerola 3f684db0d9
include/fileutils: add is_same_inode() check
Check if a file descriptor and path or stat structure are represent the same
file.  This function is needed for TACTOU avoidance.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-22 20:55:34 +00:00
Casper Ti. Vector dcbba45cc5 include: remove now useless linux_reboot.h. 2015-11-19 12:07:41 +01:00
Ming Lei faeef4d2e9 losetup: support list direct io
So that user can see if DIO is set for current loop device.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
2015-11-19 11:27:36 +01:00
Ming Lei 64c3bb3cb7 losetup: support ioctl cmd of LOOP_SET_DIRECT_IO
From v4.4, linux kernel starts to support direct I/O and
AIO to backing file for loop driver, so allow losetup to
enable the feature by using LOOP_SET_DIRECT_IO ioctl cmd.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
2015-11-19 11:27:36 +01:00
Sami Kerola 82cac34889
ctrlaltdel: display setting when ran without arguments
This is more useful than printing an error.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-10-18 18:03:57 +01:00
Karel Zak 3ebfa6882a include/pt-mbr-partnames: remove '|' from partition type name
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-10-09 13:13:59 +02:00
Jörg Jenderek 3e9a2bbb94 fdisk: to recognize Intel Rapid Start hibernation partition
I use Intel Rapid Start Technology on my PC. According to their User Guide
"Rapid_Start_Technology_User_Guide_v1.4.pdf" I create a partition with id=84
for hibernation by this Technology.

Unfortunately the software fdisk (util-linux-2.27) classifies that partition as
"OS/2 hidden C:".  That is not wrong, but on website
https://en.wikipedia.org/wiki/Partition_type is written, that id 0x84 beside
using for hiding drive C: this type is a also used as hibernation partition for
Microsoft  APM and also for Intel Rapid Start

So I patched 2 header files so that fdisk recognize this partition type variation.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-10-09 13:07:31 +02:00
Jörg Jenderek b12b07e361 fdisk: to recognize partition type 0xEA (Rufus)
i used a partitioning+formatting tool product rufus 2.2. of
https://rufus.akeo.ie/ This software has an extra format option for older BIOS.
With this fix the main partition is created with some alignments and for the
remaining unallocated space a small extra and empty partition with
identification 0xEA is created.

On the List of partition identifiers for PCs at
http://www.win.tue.nl/~aeb/partitions/partition_types-1.html is is said that
there is a freedesktop proposal to use also type ea as boot partition

Unfortunately the software fdisk (util-linux-2.27) can not classify that
partition.  I send for the fdisk program my 2 patches so that fdisk recognize
this partition type.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-10-02 12:34:01 +02:00
Karel Zak de8d3863c8 lib/strv: add strv_extendv()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-10-01 14:43:05 +02:00
Karel Zak 7020de0be8 lib/crc32: don't require to modify GPT header
This patch introduces smart crc32 function that is able to exclude
specified. The advantage is that we does not have to modify GPT header
(set the current in-header crc field to zero) when we count crc32.

This allows to keep GPT header in read-only buffers and simplify code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-24 09:26:42 +02:00
Karel Zak bde91c85bd chsh, chfn, vipw: fix filenames collision
The utils when compiled WITHOUT libuser then mkostemp()ing
"/etc/%s.XXXXXX" where the filename prefix is argv[0] basename.

An attacker could repeatedly execute the util with modified argv[0]
and after many many attempts mkostemp() may generate suffix which
makes sense. The result maybe temporary file with name like rc.status
ld.so.preload or krb5.keytab, etc.

Note that distros usually use libuser based ch{sh,fn} or stuff from
shadow-utils.

It's probably very minor security bug.

Addresses: CVE-2015-5224
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-24 10:05:55 +02: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
Benno Schulenberg 62eea9ce12 textual: adjust grammar and punctuation of some messages
Also equalize three messages to one other one,
and fix a typo in USE_COLORS_BY_DEFAULT.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-08-03 11:18:56 +02:00
Karel Zak 0bef6f759b libsmartcols: don't link with tinfo
Let's move color names to sequence translation to separate file to
make it usable without all the stuff in lib/colors.c.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-24 12:57:46 +02:00
Karel Zak 16c9f32f07 include/xalloc: add err_oom()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-20 11:48:09 +02:00
Karel Zak f6c01f4eed lib/procutils: add proc_get_cmdline()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-20 11:48:09 +02:00
Karel Zak 1e0cd7ae9e include/all-io: read_all() don't retry on EOF
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-20 11:48:09 +02:00
Karel Zak a6bf40ee77 lslogins: merge read_utmp() code
The code is used only in lslogins, so it does not make sense to
maintain it in libcommon.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-16 11:26:14 +02:00
Sami Kerola 3e5a54554d rtcwake: improve read_clock_mode()
Make skipping two lines more robust, and add message about unexpected
adjfile contents when running with --verbose.

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +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
Guillem Jover 8e86d93d1e lib/fileutils: Add new dup_fd_cloexec function
This function duplicates and marks a file descriptor as close-on-exec.
Takes care of build and run-time support for the fcntl F_DUPFD_CLOEXEC
command, and other errors.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2015-06-08 12:10:02 +02:00
Karel Zak 6a768b5516 libsmartcols: keep JSON field names lower-case
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-05 11:58:42 +02:00
Karel Zak 6c62abc42b lib/sysfs: rename devname functions, cleanup
Well, I don't have mental power to use function names like

 sysfs_devname_to_dev_name()

so this patch renames to

 sysfs_devname_sys_to_dev()
 sysfs_devname_dev_to_sys()

It also cleanups usage of the functions. We have to be sure that
sysfs.c code returns regular devnames. The existence of the sysfs
devnames (with '!') should be completely hidden in sysfs specific
code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-28 12:09:41 +02:00
Stanislav Brabec 759b120d85 lib/sysfs: Fix /dev to /sys node name translation
d0dc6c1 introduced translation of /sys names to /dev names, as required
by the kernel linux/drivers/base/core.c: device_get_devnode(). But there
are other places of code that use /dev names in /sys. They need reverse
translation from '/' to '!'.

For example, fdisk -l returns empty list since a22c6eb for device nodes
in subdirectories (used e. g. by cciss driver).

Introduce yet another helper sysfs_dev_name_to_devname() and use it where
appropriate.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2015-05-28 10:27:20 +02:00
Stanislav Brabec d0dc6c17c5 Fix /sys to /dev node name translation
linux/drivers/base/core.c: device_get_devnode() defines a translation of
'!' in sysfs nodes to '/' in /dev nodes. The same translation has to be
done to properly support device nodes with slash (e. g. device nodes of
cciss driver and several other drivers).

Introduce new helper sysfs_devname_to_devno() and use it where
appropriate.

Fixes for example lsblk -f on devices using cciss driver.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2015-05-26 11:42:38 +02:00
Karel Zak 548b9714e8 lib/strv: add new functions (from systemd)
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-15 14:57:04 +02:00
Karel Zak 40b175084f lib/strutils: fix string_add_to_idarray() int vs. size_t
The function uses "int" as argument, but for array size (and index) is better
to use unsigned type (size_t). If we mix "size_t" in util (e.g. fdisk)
and "int" in lib/strutils.c then result is unexpected behavior on
ppc64.

	# sfdisk --list -o DEVICE,START,SIZE /dev/sdb
	Disk /dev/sdb: 50 MiB, 52428800 bytes, 102400 sectors
	Units: sectors of 1 * 512 = 512 bytes
	Sector size (logical/physical): 512 bytes / 4096 bytes
	I/O size (minimum/optimal): 4096 bytes / 32768 bytes
	Disklabel type: gpt
	Disk identifier: 3B8559DB-33AF-43E9-BEFC-C331D829B539
	lt-sfdisk: libfdisk/src/label.c:178: fdisk_label_get_field: Assertion `id > 0' failed.

The patch cleanup all code to use size_t everywhere.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-22 11:08:05 +02:00