Commit Graph

83 Commits

Author SHA1 Message Date
Karel Zak 17fc8693cd include/c: add drop_permissions(), consolidate UID/GID reset
Fixes: https://github.com/karelzak/util-linux/issues/1354
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-21 12:25:31 +02:00
Karel Zak 01085557eb include/c: add __format__ attribute
Reported-by: Jan Pazdziora <jpazdziora@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-18 16:29:16 +02:00
Frantisek Sumsal c40b3cd03d text-utils: correctly detect ASan under clang
__SANITIZE_ADDRESS__ is not defined when compiling with clang, so cover
both use cases with a special set of macros
2021-02-01 11:59:47 +01:00
Karel Zak 7397f2c1f9 build-sys: add restrict keyword fallback
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-22 13:28:02 +01:00
Evgeny Vereshchagin 0be452a82a build-system: stop looking for %ms and %as
Looks like those specifiers haven't been used since 6c9ab254ae
(where sscanf was removed) was merged. This should help to get
util-linux to compile with MSan. Currently it's failing with
```
...
configure: error: libmount selected, but required scanf string alloc modifier not available
...
configure:20240: ./conftest
==116617==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x496fd6 in main /home/vagrant/util-linux/conftest.c:171:6
    #1 0x7f5eb85ea1a2 in __libc_start_main (/lib64/libc.so.6+0x271a2)
    #2 0x41c2cd in _start (/home/vagrant/util-linux/conftest+0x41c2cd)

SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/vagrant/util-linux/conftest.c:171:6 in main
Exiting
configure:20240: $? = 77
...
configure:20265: $? = 0
configure:20265: ./conftest
MemorySanitizer: bad pointer 0x000000496e60
==116627==MemorySanitizer CHECK failed: /builddir/build/BUILD/compiler-rt-9.0.1.src/lib/msan/../sanitizer_common/sanitizer_allocator_secondary.h:177 "((IsAligned(reinterpret_cast<uptr>(p), page_size_))) != (0)" (0x0, 0x0)
    #0 0x41d1d8 in MsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/home/vagrant/util-linux/conftest+0x41d1d8)
    #1 0x484e1e in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/home/vagrant/util-linux/conftest+0x484e1e)
    #2 0x42066c in __msan::MsanDeallocate(__sanitizer::StackTrace*, void*) (/home/vagrant/util-linux/conftest+0x42066c)
    #3 0x424bc9 in free (/home/vagrant/util-linux/conftest+0x424bc9)
    #4 0x496fae in main /home/vagrant/util-linux/conftest.c:173:2
    #5 0x7f2245f311a2 in __libc_start_main (/lib64/libc.so.6+0x271a2)
    #6 0x41c2cd in _start (/home/vagrant/util-linux/conftest+0x41c2cd)

configure:20265: $? = 77
configure: program exited with status 77
...
| }
configure:22568: result: no
configure:22926: error: libmount selected, but required scanf string alloc modifier not available
```

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2020-08-06 14:27:20 +00:00
Karel Zak f1970cc557 docs: improve size arguments description in --help output
Let's add "Arguments:" section to the --help output and describe
{K,M,G...}iB suffixes there.

Addresses: https://github.com/karelzak/util-linux/pull/917
Co-Author: ed <ed@s5h.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-05 11:01:36 +01:00
Karel Zak 67f938bfba include/c: add USAGE_ARGUMENT
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-05 10:17:18 +01:00
Karel Zak 40f8c5e47e include: add some missing licence stuff to header files
It's mostly wrappers for compatibility and another trivial stuff etc.
Let's keep it as public domain to make it more portable to LGPL, GPL
and BSD code.

Signed-off-by: Karel Zak <kzak@redhat.com>
CC: Sami Kerola <kerolasa@iki.fi>
CC: Ruediger Meier <ruediger.meier@ga-group.nl>
2020-01-13 10:39:52 +01:00
Sami Kerola 218b1dd6f9
misc: fix typos [codespell]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-09-12 19:41:46 +01: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
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 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
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
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 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 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
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
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
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
Ruediger Meier a2248466e4 misc: no more errtryh()
Nowadays all our regular commands have --help options.
test_uuidd does not use translations anyways.

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

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

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

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

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

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

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

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

and exit.

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

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

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

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

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

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

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

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

Multiple of these:

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

And nearly 300 times reported:

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

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

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

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

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

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

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

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

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

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-22 11:03:09 +02:00