Timestamps in kernel log comes from monotonic clocksource which does not
tick when system suspended. Suspended time easily sums into hours and days
rendering human readable timestamps in dmesg useless.
Adjusting timestamps accouring to current delta between boottime and
monotonic clocksources produces accurate timestamps for messages printed
since last resume. Which are supposed to be most interesting.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
All simple function to parse --lock <mode> and $LOCK_BLOCK_DEVICE,
and to flock the fd.
The supported <mode> is:
"1" or "yes" - LOCK_EX
"0" or "no" - do nothing
"nonblock" - LOCK_EX | LOCK_NB
The function tries LOCK_NB before the solo LOCK_EX and prints
inform user that it will wait, for example:
session A:
# sfdisk --lock /dev/sdc
session B:
# sfdisk --lock /dev/sdc
sfdisk: /dev/sdc: device already locked, waiting to get lock ...
^C
# sfdisk --lock=nonblock /dev/sdc
sfdisk: /dev/sdc: device already locked
Addresses: https://github.com/karelzak/util-linux/issues/921
Signed-off-by: Karel Zak <kzak@redhat.com>
Lsblk throws the following error for nvmeNcXnY devices.
lsblk: nvme1c1n1: unknown device name
This is because nvmeNcXnY devices are hidden and do not have
the file /sys/block/<nvmeNcXnY>/dev.
Following patch was added
https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=d51f05bfecb299a830897106460bf395be440c0a
Which made lsblk read from /sys/block/<nvmeNcXnY>/device/dev
which do exist for nvmeNcXnY devices.
After the above patch, the unknown error goes away.
However, another error is encountered in the very next step.
nvme1c1n1: failed to initialize sysfs handler
This is because lsblk looks for /sys/dev/block/242:1
(nvmeNcXnY major:minor) pathname which usually exists for other
block devices but not for the nvmeNcXnY devices as they are hidden.
Below patch does not even print this error for hidden devices
and exits silently.
[kzak@redhat.com: - add prefix to make sysfs_devname_is_hidden()
usable for /sys dumps
- use the function in initialize_device() more early]
Signed-off-by: Ritika Srivastava <ritika.srivastava@oracle.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
It seems that directories like /etc/motd.d are already used by PAM or
by another stuff. Let's keep it in admin/distro hands and do not
change the current default.
Signed-off-by: Karel Zak <kzak@redhat.com>
The current standard is to use directories to make it easy for
distributions to share resources. This patch also add /etc/motd.d
and /run/motd.d to the default MOTD_FILE=.
Addresses: https://github.com/karelzak/util-linux/issues/10341
Signed-off-by: Karel Zak <kzak@redhat.com>
We already have mbs_safe_nwidth() but it assumes that all "bad" chars
will be encoded by \x<hex>. Now we need also function that do not care
about encoding.
Signed-off-by: Karel Zak <kzak@redhat.com>
* 'map-user' of https://github.com/mat8913/util-linux:
unshare: Support names for map-user/group options
lib/pwdutils: add xgetgrnam
unshare: allow custom uid/gid mappings in userns
This patch prevents to call the function strlen() with a NULL string
argument that leads to a segmentation fault.
Signed-off-by: Gaël PORTAY <gael.portay@collabora.com>
This adds support to unshare for time namespaces. With the newly added
options '-t, --time' and '--monotonic' and '--boottime' it is now
possible to change CLOCK_MONOTONIC and CLOCK_BOOTTIME in a new time
namespace.
The time namespace has been merged in kernel version 5.6 and an easy way
to test it is using CLOCK_BOOTTIME and the uptime command:
# uptime
11:08:26 up 20:28, 1 user, load average: 0.00, 0.00, 0.00
# ./unshare --fork --time --boottime 100000000 uptime
11:08:29 up 1158 days, 6:15, 1 user, load average: 0.00, 0.00, 0.00
Signed-off-by: Adrian Reber <areber@redhat.com>
Let's consolidate the code, we need to use it in libfdisk too. It
seems better to keep it generic and libblkid independent.
This patch also removes blkid_encode_alloc(), this function is overkill.
Signed-off-by: Karel Zak <kzak@redhat.com>
* 'various-fixes' of https://github.com/kerolasa/util-linux:
kill: include sys/types.h before checking SYS_pidfd_send_signal
libfdisk: fix pointer wraparound warning
hwclock: update yacc file
script: fix minor warning
getopt: use examples installation directory in man page
fstrim: randomize timer start time across 100 minutes
various: use threadsafe versions of time functions [lgtm scan]
write: fix potential string overflow
Including sys/types.h must happen before SYS_pidfd_send_signal is checked,
because that header defines variable in normal conditions. When sys/types.h
does not have SYS_pidfd_send_signal then fallback is defined in config.h
that is included by default, and has therefore worked fine before and after
this change.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Deprecating calls to not-thread safe asctime(), ctime(), and localtime()
calls is pretty close to pointless change. Lets do it to reduce lgtm scan
warnings with justification it's nicer to use static analysis tools when
they have very few positives.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
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>
* fix double free
* keep strrealloc() semantic compatible with classic realloc() (do not
free original pointer on failed memory allocation).
* remove unnecessary goto
Signed-off-by: Karel Zak <kzak@redhat.com>
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>
Move the helper functions that parse ISO data & sector size info into
a separate, shared header.
These will addtionally be used by libblkid's iso9660 parser.
Signed-off-by: Daniel Drake <drake@endlessm.com>
* 'kill-pidfd' of https://github.com/kerolasa/util-linux:
kill: use pidfd system calls to implement --timeout option
build-sys: add missing NR underscore to UL_CHECK_SYSCALL()
At times there is need in scripts to send multiple signals to a process.
Often these cases require some amount of waiting before follow-up signal
should be sent.
One common case is process termination, where first script tries to kill
process gracefully but if that does not work SIGKILL is sent. Functionality
like that is commonly done by periodically checking if signalled pid exist
or not, and if it does another signal is sent possibly to an unrelated
process that reused pid number. That means polling a pid is prone to a data
race. Also if the first signal immediately kills the process one polling
interval is lost in sleep.
Another example when multiple signal need to be sent is various daemon
process control situations, such as Upgrading Executable on the Fly (see
reference). This happens to be the case that inspired change author to make
sequential signaling a little bit easier.
Reference: http://nginx.org/en/docs/control.html#upgrade
Pull-request: https://github.com/karelzak/util-linux/pull/902
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
It some cases it makes sense to disable ECHO flag also when script
used in pipe. This new option allows to keep full control in user's
hands.
Signed-off-by: Karel Zak <kzak@redhat.com>
We need a proper way how to inform child (shell) that the game is
over. It seems the best is to send EOF to child rather than
immediately break PTY mainloop where we have poll(), because shell can
still produce data etc.
Signed-off-by: Karel Zak <kzak@redhat.com>
For tools like su(1) is ECHO flag unexpected for use-case like
echo 'date' | su - user
but script(1) need the echo to keep input recorded.
The patch also return execlp() use to script(1) code.
Signed-off-by: Karel Zak <kzak@redhat.com>
The parse-date.y is used only for hwclock, let's keep it together.
Note that the file (originally from gnulib) has GPLv3 license, so it's
better to make it obvious that we use it really only for hwclock (also
GPL).
Signed-off-by: Karel Zak <kzak@redhat.com>
* improve strdup_to_offset() readability
* add strdup_between_offsets() and strdup_between_structs() to have
better support for use-cases when we copy structs
Signed-off-by: Karel Zak <kzak@redhat.com>
In commit b1418ed14 (lib/path: add ul_path_stat(), fix absolute paths,
2019-10-15), a new function `ul_path_stat()` was added to "path.h". This
new function prototype causes a compiler warning on musl libc based
systems due to one of the parameters having the unknown type `struct
stat` due to the <sys/stat.h> header not being included.
Fix the warning by including the header.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
The classic way which is based on file-descriptors table size is
pretty expensive (due to table size) and forces code to do many
unnecessary close() calls. It seems better to use /proc/self/fds and
close used descriptors only.
Addresses: https://github.com/karelzak/util-linux/issues/883
Signed-off-by: Karel Zak <kzak@redhat.com>
* add ul_path_stat()
* make sure all paths for ul_path_..() functions are always
interpreted relatively to the context directory and prefix. This is
difference between ul_path_ API and standard libc "at" functions. We
do not use any exception for absolute paths. The reason is that we
need to read from prefixed paths although application assume absolute
path (/dev/sda1 means /prefix/dev/sda1 if a /prefix is defined).
Signed-off-by: Karel Zak <kzak@redhat.com>
Now the code is duplicate on many places, but all we usually need is to
remember child status. It seems good enough to have very simple
callback child_die() to inform application about a change.
The patch also add PID to all signal related callbacks.
Signed-off-by: Karel Zak <kzak@redhat.com>
This allows to control mainloop behavior from PTY applications. For
example you can write to child (shell) process independently on the
current stdin.
Signed-off-by: Karel Zak <kzak@redhat.com>
The idea is to consolidate script(1), scriptlive(1) and su(1) --pty
and use the same code everywhere.
TODO: add callbacks for stdin/out logging (necessary for script(1)).
Signed-off-by: Karel Zak <kzak@redhat.com>