Ivan Delalande [Wed, 21 Jun 2017 23:43:05 +0000 (16:43 -0700)]
dmesg: print only 2 hex digits for each hex-escaped byte
As buf is passed as a signed char buffer in fwrite_hex, fprintf will
print every byte from 0x80 as a signed-extended int causing each of
these bytes to be printed as "\xffffff80" and such, which can be pretty
confusing. Force fprintf to use the argument as a char to make it print
only 2 digits, e.g. "\x80".
Karel Zak [Wed, 21 Jun 2017 08:53:28 +0000 (10:53 +0200)]
wipefs: exit on failed erase
The current behavior is to report error and continue, it seems strange:
# blockdev --setro /dev/sdc
# wipefs -a /dev/sdc
wipefs: /dev/sdc: failed to erase xfs magic string at offset 0x00000000: Operation not permitted
/dev/sdc: 4 bytes were erased at offset 0x00000000 (xfs): 58 46 53 42
^^^^^^^^^^^
not true
The patch calls err() to exit.
Reported-by: Vratislav Podzimek <vpodzime@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Alex Ivanov [Thu, 15 Jun 2017 08:26:25 +0000 (11:26 +0300)]
fstrim: prefer earlier mounted filesystems
fstrim --all is broken in a way that if there is a bind mount for some filesystem,
that filesystem will not be trimmed. This is especially critical for e.g.
NixOS distribution, which needs bind mount within root fs:
https://github.com/NixOS/nixos/blob/master/modules/system/boot/stage-2-init.sh#L55
Currently for a given filesystem during "de-duplication by source and root" phase,
an early mounted fs path is filtered (e.g. "/"), while later mounted fs path is kept
(e.g. "/nix/store") though anyway discarded later (since it's an overlaying mount).
This leads to skipped trimming.
So flip this behaviour. Should also help for other types of overlaying mounts.
Pali Rohár [Wed, 14 Jun 2017 21:15:14 +0000 (23:15 +0200)]
libblkid: udf: Fix detection of UDF images with block size 1024 and 4096
When detecting block size of UDF filesystem, try to use also block size
512, 1024, 2048 and 4096. This would allow blkid to detect UDF filesystem
in image file created from 4K hard disk (which should have UDF block size
4096).
Before this patch only UDF images with block size of 512 and 2048 were
detected as only block size from blkid_probe_get_sectorsize() and 2048 were
used (blkid_probe_get_sectorsize() returns for disk images 512).
Karel Zak [Tue, 13 Jun 2017 10:15:11 +0000 (12:15 +0200)]
lscpu: cleanup DMI detection return codes
Michal wrote:
There is weird mix of logic in lscpu-dmi.c which sometimes returns 0 and
sometimes -1 on error. Since most checks are if (rc) goto done; this
bails out early on error skipping some detection methods. Further, in
lscpu.c all following detections are guarder by if(hyper) so returning
-1 causes all following methods to be skipped.
Reported-by: Michal Suchanek <msuchanek@suse.de> Signed-off-by: Karel Zak <kzak@redhat.com>
NeilBrown [Mon, 5 Jun 2017 02:32:58 +0000 (12:32 +1000)]
umount: never 'stat' the path when "-c" is given.
It is currently not possible to reliably and automatically
unmount an NFS filesystem. If the server is not available, the
umount command will hang.
The hang can be avoided by using "-l" or "-f", but neither
of these are appropriate for automatic use such as by an
automounter (e.g automountd or systemd).
"-l" will unmount even if the filesystem is in use, which
an automounter generally doesn't want. If the filesystem
is in use, then the umount should fail.
"-f" can cause the filesystem to abort pending transactions
which might break filesystem semantics. This can be useful
in the hands of a sysadmin, but not when used by an
automatic tool.
umount has another option, "-c" aka "--no-canonicalize"
which avoids some "stat" calls.
Currently this doesn't avoid all calls to
canonicalize_path()
as
mnt_context_prepare_umount() ->
lookup_umount_fs() ->
mnt_context_find_umount_fs() ->
mnt_context_get_mtab_for_target() ->
mnt_resolve_path() ->
canonicalize_path_and_cache() ->
canonicalize_path()
leads to that function being called.
The "-c" option could be taken to mean "I know what I'm
doing, this really is the path to a mount point, I just want
you to unmount it". Given that, it seems suitable to
extend this to avoid all 'stat' calls on the mountpoint.
It is already appropriate for any automount program to pass
"-c" to "umount", so they can be changed to do so at any
time.
With the patch below, "-c" will result in the mountpoint
never being "stat"ed, so umount won't hang on an
inaccessible server.
This isn't quite sufficient, for NFS at least, as the usage
of libmount in umount.nfs still calls 'stat' on the mount
point.
"-c" isn't passed to the umount helper, but it is reasonable
for such helpers to assume "-c" because "umount" will have
canonicalized the path when that is appropriate.
So, this patch treats "-c" much like "-l" and "-f" when
deciding whether it is safe to 'stat' the path.
Karel Zak [Fri, 23 Jun 2017 12:26:47 +0000 (14:26 +0200)]
agetty: fix login name DEL/CTRL^U issue
agetty refresh prompt (/etc/issue file etc.) when requested by inotify
or netlink. For this purpose we monitor some file descriptors by
select().
The terminal input file descriptor is switched to non-canonical mode before
select(). The goal is to be informed about user activity before
new-line. The FD is immediately switched back to canonical mode when
activity is detected. The side effect is that all not-read-yet chars in
the input buffer are lost ... so we need to call read() before switch
to canonical mode to save the chars.
The original implementation has been based on TIOCSTI ioctl. It
returns already read chars back to the terminal input buffer to make
them useful for canonical mode. The problem was race (agetty writes to
input buffer in the same time as user) and result was reordered chars
in login name... so useless.
This issue has been later fixed by extra buffer (commit 790119b8850ae13bb4254c5096a54b2aeb355b20) for already read data. And
TIOCSTI ioctl has been removed. Unfortunately this solution is also
wrong, because the buffer is maintained only by agetty and
inaccessible for terminal when user edit (by DEL/CTRL^U) login name in
canonical mode.
The solution is simple -- just don't try to be smart and keep terminal
in canonical mode all time (so terminal controls DEL, CTRL^U, etc) and
flush input buffer (=discard unread data) and ask user for login name
again after prompt reload.
The agetty reload is very rarely situation and for user it's pretty
obvious that he has to type login name again (as all terminal has been
clear+redraw).
Addresses: https://github.com/karelzak/util-linux/issues/454
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1464148 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Thu, 1 Jun 2017 10:30:14 +0000 (12:30 +0200)]
Merge branch 'travis-test' of https://github.com/rudimeier/util-linux
* 'travis-test' of https://github.com/rudimeier/util-linux:
tests: check for timeout command
Revert "tests: use stdbuf when stderr and stdout is randomly ordered"
Karel Zak [Thu, 1 Jun 2017 08:49:12 +0000 (10:49 +0200)]
Merge branch 'travis-test' of https://github.com/rudimeier/util-linux
* 'travis-test' of https://github.com/rudimeier/util-linux:
misc: fix some warnings
tests: handle non glibc error message for fallocate
tests: use stdbuf when stderr and stdout is randomly ordered
build-sys: fix library order when linking
tests: avoid diff of diffs
tests: grep's short option -A is more portable
Ruediger Meier [Wed, 31 May 2017 21:58:11 +0000 (23:58 +0200)]
misc: fix some warnings
sys-utils/prlimit.c: In function 'do_prlimit':
sys-utils/prlimit.c:367:16: warning: format '%ju' expects argument of type 'uintmax_t', but argument 2 has type 'rlim_t {aka long long unsigned int}' [-Wformat=]
printf("<%ju", new->rlim_cur);
lib/plymouth-ctrl.c: In function 'open_un_socket_and_connect':
lib/plymouth-ctrl.c:88:20: warning: passing argument 2 of 'connect' from incompatible pointer type [-Wincompatible-pointer-types]
ret = connect(fd, &su, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(su.sun_path+1));
^
In file included from lib/plymouth-ctrl.c:35:0:
/usr/include/sys/socket.h:314:5: note: expected 'const struct sockaddr *' but argument is of type 'struct sockaddr_un *'
int connect (int, const struct sockaddr *, socklen_t);
login-utils/last.c: In function 'list':
login-utils/last.c:506:54: warning: pointer targets in passing argument 4 of 'dns_lookup' differ in signedness [-Wpointer-sign]
r = dns_lookup(domain, sizeof(domain), ctl->useip, p->ut_addr_v6);
^
login-utils/last.c:291:12: note: expected 'int32_t * {aka int *}' but argument is of type 'unsigned int *'
static int dns_lookup(char *result, int size, int useip, int32_t *a)
^~~~~~~~~~
In file included from sys-utils/hwclock-cmos.c:92:0:
sys-utils/hwclock.h:67:32: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
extern double time_diff(struct timeval subtrahend, struct timeval subtractor);
misc-utils/test_uuidd.c: In function 'create_nthreads':
misc-utils/test_uuidd.c:187:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
proc->pid, (int) th->tid, th->index));
Ruediger Meier [Wed, 31 May 2017 19:02:12 +0000 (21:02 +0200)]
build-sys: fix library order when linking
We got some errors on Alpine Linux where $LTLIBINTL is non-empty:
./.libs/libcommon.a(libcommon_la-blkdev.o): In function `open_blkdev_or_file':
lib/blkdev.c:282: undefined reference to `libintl_gettext
collect2: error: ld returned 1 exit status
This patch does not change any wording or grammar. It
only shuffles the order of things and adds a table of
contents. For example: it moves coding related bullet
points into the Coding Style Chapter; it groups email
related Chapters together, and so fourth.
Signed-off-by: J William Piggott <elseifthen@gmx.com>
Karel Zak [Wed, 31 May 2017 08:52:44 +0000 (10:52 +0200)]
build-sys: prefer ncurses-config rather than pkg-config
If you have installed:
ii libncurses5:i386 5.9+20140913-1+b1 i386 shared libraries for terminal handling
ii libncurses5-dev:i386 5.9+20140913-1+b1 i386 developer's libraries for ncurses
ii libncursesw5:i386 5.9+20140913-1+b1 i386 shared libraries for terminal handling (wide character support)
then pkg-config blindly follows ncursesw although there are not header
files for this library. It seems better to use pkg-config as fallback
solution only.
Karel Zak [Tue, 30 May 2017 15:10:40 +0000 (17:10 +0200)]
cal: ncurses cleanup
* use proper paths to term.h
* keep ncurses support optional
* link with TINFO_LIBS (-ltinfo), or fallback to NCURSES_LIBS (-ltinfo -lncurses)
* don't include unnecessary ncurses.h (term.h is enough)
Karel Zak [Tue, 30 May 2017 15:10:40 +0000 (17:10 +0200)]
lib/colors: ncurses cleanup
* use proper paths to term.h
* keep ncurses support optional
* link with TINFO_LIBS (-ltinfo), or fallback to NCURSES_LIBS (-ltinfo -lncurses)
* don't include unnecessary ncurses.h (term.h is enough)
Karel Zak [Tue, 30 May 2017 15:01:00 +0000 (17:01 +0200)]
build-sys: make ncurses detection more robust
It seems Debina 8 is a little bit incompatible with us:
* ncurses-config is packaged in ncurses-bin where is *no* any
development files! It means the script returns paths to not installed
files (IMHO packaging bug)
Fixed, we need to check for header files too.
* term.h is "everywhere" on Fedora:
<term.h>
<ncurses/term.h>
<ncursesw/term.h>
Debian is more strict and uses <ncurses[w]/term.h> only.
Fixed, we need #ifdef storm to use the correct path
* libtinfo-dev does not contains any header files
Fixed, we have to always require installed ncurses devel stuff to compile,
but we can link with -ltinfo only (cal, ul, more, ...)
Sami Kerola [Sat, 27 May 2017 09:03:55 +0000 (10:03 +0100)]
libfdisk: fix variable shadowing
libfdisk/src/context.c: In function 'fdisk_assign_device':
libfdisk/src/context.c:549:7: warning: declaration of 'rc' shadows a previous local [-Wshadow]
libfdisk/src/context.c:542:10: note: shadowed declaration is here
[kzak@redhat.com: - add rc to debug message]
Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
Sami Kerola [Thu, 18 May 2017 21:19:34 +0000 (22:19 +0100)]
rename: make --no-act to imply --verbose
It is reasonable to assume use of --no-act means one wants to always see
what would have happen if rename is done. To say same slightly differently,
if there is sn use case for silent rename --no-act run I cannot think one.
Pali Rohár [Wed, 17 May 2017 18:36:40 +0000 (20:36 +0200)]
libblkid: udf: Change algorithm for reporting UUID
Ensure that reported UUID always contains only lowercase hexadecimal digits
and is always 16 characters length, padded with zero digits.
Volume Set Identifier is converted to UTF-8 before generating UUID from it.
As it could potentially contain any Unicode character. So correctly handle
both 8bit and 16bit OSTA Compressed Unicode encodings.
Disks which have only lowercase hexadecimal digits in Volume Set Identifier
would have same UUID as before this patch.