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>
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.
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>
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>
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.
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>
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>
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>
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>
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>
Recent lscpu fix caused gcc -Wnull-dereference to go off that this change
addresses.
Reference: b94acada9e
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
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>
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>
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>
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>
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>
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>
* 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>
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>
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>
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>
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>
* 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>
* 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>
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>
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>
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>
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>
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>
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>
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
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>
* 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>
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>
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>
* 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
* '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
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>
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>
* 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>
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>
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>
* '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
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>
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>
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>
./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>
* 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>
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>
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>
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>
* 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>
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>
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>