Stanislav Brabec [Wed, 17 Aug 2016 10:54:40 +0000 (12:54 +0200)]
losetup: Prevent AUTOCLEAR detach race
Kernel needs some time to delete a device after losetup --detach. If
the losetup --find --nooverlay is called just after losetup --delete,
it can sometimes attempt to recycle the device that is just being
released. To prevent this race, clear the AUTOCLEAR flag of the
device.
[kzak@redhat.com: - rebase to the new version of the code]
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 17 Aug 2016 10:28:33 +0000 (12:28 +0200)]
losetup: add --nooverlap options
This patch introduces overlap detections and loop devices
re-use for losetup(8). We already support this feature for mount(8)
where it's enabled by default (because we mount filesystems and it's
always mistake to share the same filesystem between more loop
devices).
Stanislav has suggested to enable this feature also for losetup by
default. I'm not sure about it, IMHO it's better to keep losetup(8)
simple and stupid by default, and inform users about possible problems
and solutions in the man page.
The feature forces losetup to scan all loop devices always when new
one is requested. This maybe disadvantage (especially when we use
control-loop to avoid /sys or /dev scans) on system with huge number
of loop devices.
Co-Author: Stanislav Brabec <sbrabec@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 16 Aug 2016 10:09:00 +0000 (12:09 +0200)]
Merge branch 'misc' of https://github.com/kerolasa/lelux-utiliteetit
* 'misc' of https://github.com/kerolasa/lelux-utiliteetit:
pg: stop building the command by default
kill: remove pid command-name to option alias
misc: always check setenv(3) return value
Sami Kerola [Mon, 8 Aug 2016 21:08:16 +0000 (22:08 +0100)]
pg: stop building the command by default
The pg command is marked deprecated in POSIX since 1997, and this project
has thought the same since Feb 2013. Time has come to stop shipping this
binary by default.
Ruediger Meier [Thu, 11 Aug 2016 15:30:20 +0000 (17:30 +0200)]
travis: fix OSX, glibtoolize could not find sed
Since a few days travis OSX seems to have a bad libtool package:
$ glibtoolize --version
/usr/local/bin/glibtoolize: line 406: /usr/local/Library/ENV/4.3/sed: No such file or directory
Exporting SED is a simple fix. Otherwise we could have also re-installed libtool:
brew uninstall libtool
brew install libtool
libmount: Preserve empty string value in optstr parsing
Recent mount (since the switch to libmount in v2.22) drops the '=' in
mount options that are set to an empty value. For example, the command
line below will be affected:
# mount -o rw,myopt='' -t tmpfs tmpfs /mnt/tmp
Fix that by preserving an empty string in the options passed to the
mount(2) syscall when they are present on the command line.
Add test cases to ensure empty string handling is working as expected
and in order to prevent regressions in the future.
Also tested manually by stracing mount commands (on a kernel which
accepts a special extra option, for testing purposes.)
tests: Use proper word splitting when executing tests
Use the shell special variable "$@" instead of the inferior $* to
execute the test command in ts_valgrind. The expansion of "$@" respects
proper word splitting and makes it possible to pass the command empty
arguments. It might also prevent surprises with quoting in corner
cases.
Tested that `make check` passes.
Valgrind run with `make check TS_OPTS='--nonroot --memcheck'` passes.
Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Chris Metcalf [Tue, 9 Aug 2016 09:31:41 +0000 (11:31 +0200)]
taskset: clarify that masks are always hex in man page
The man page confusingly says that the mask is "typically"
hexadecimal, when in fact it is always hexadecimal. Fix the
language, and provide an additional example with no leading "0x".
Also, provide an example using the --cpu-list option.
Signed-off-by: Chris Metcalf <cmetcalf@mellanox.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Mon, 8 Aug 2016 15:23:54 +0000 (17:23 +0200)]
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>
--show-pt-geometry existed since cf3f26bf (2006), and it is used by third party
tools. To prevent failure of these tools, add a minimal compatibility code.
lscpu: print correct number of threads per core if possible
lscpu calculates the number of threads per core by dividing the number
of online cpus with the number of cores. This may or may not give the
correct number of threads per core depending on the number of online
CPUs (and which CPUs are online).
At least on s390 there is a new "max thread id" field within
/proc/cpuinfo present which reliably allows us to tell the number of
threads per core. Let's use this instead, like we already have also
special treatment to figure out the number core per socket etc. on
s390.
lscpu: only try to read sysfs attributes of present CPUs
lscpu can skip all CPUs which are possible but not present. For
configurations where a lot of CPUs are possible but only few CPUs are
present this saves a lot of pointless glibc/system calls.
With the --physical option lscpu will use the IDs that are reported by
the kernel (e.g. core id for the CORE column) instead of calculating
them on it's own.
This has the advantage that it is possible to tell on which physical
hardware CPUs a Linux instance runs. The logical IDs that lscpu
generates on it own are based on comparing of CPU masks and may or may
not be identical with the physical IDs.
If the kernel was unable to retrieve an ID for a topology element then
the corresponding sysfs file will normally contain "-1". In the
extended and parsable output a dash "-" will be displayed for such
cases.
Stanislav Brabec [Thu, 14 Jul 2016 13:29:44 +0000 (15:29 +0200)]
libmout: Reuse loop device safely
Add a safety check to mnt_context_setup_loopdev(). Only a loop device with equal
offset and sizelimit will be reused. If any overlapping loop device exists,
MNT_ERR_LOOPOVERLAP is returned.
Stanislav Brabec [Thu, 14 Jul 2016 13:29:09 +0000 (15:29 +0200)]
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).
Karel Zak [Tue, 2 Aug 2016 13:26:49 +0000 (15:26 +0200)]
Merge branch 'oclint' of git://github.com/kerolasa/lelux-utiliteetit
* 'oclint' of git://github.com/kerolasa/lelux-utiliteetit:
libblkid: fix debugging macro [oclint]
agetty: move unreachable code to pre-processor #else segment [oclint]
setterm: fix declarations shadowing variables in the global scope [oclint]
misc: fix declarations shadowing variables in the global scope [oclint]
dmesg: drop core at impossible case in read_buffer() [oclint]
libmount, look: remove dead code [oclint]
syspriv: flip inverted logic [oclint]
logger: simplify if clause [oclint]
libblkid: simplify if clause [oclint]
lslogins: simplify if clause and move definition and comments [oclint]
switch_root: simplify code and reduce indentation [oclint]
misc: simplify if clauses [oclint]
Sami Kerola [Wed, 27 Jul 2016 10:17:47 +0000 (11:17 +0100)]
getops: improve getopt-parse.bash example
Use correct names of example scripts in the script. Remove use of
backticks, they require quoting that makes the example harder to follow.
Split one-liners to one-command-at-a-time expressions. Add continue keyword
to avoid additional case statement matching. Be strict with quoting.
Reported-by: Benno Schulenberg <bensberg@justemail.net> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Sami Kerola [Sun, 3 Jul 2016 19:57:23 +0000 (20:57 +0100)]
libblkid: fix debugging macro [oclint]
The oclint was complaining 'empty do/while statement' that turned out to be
true and I started to think it is best to use the same DBG() macro as in
other source files for this library.
Sami Kerola [Mon, 4 Jul 2016 21:12:55 +0000 (22:12 +0100)]
libblkid: simplify if clause [oclint]
Move negative and positive testing of 'has' variable to top level, and test
flag bit mask on second level. This way the 'has' needs to be checked only
once.
Sami Kerola [Mon, 4 Jul 2016 21:16:54 +0000 (22:16 +0100)]
lslogins: simplify if clause and move definition and comments [oclint]
The if clause change is pretty trivial. Moving the macro near to where it
is used makes sense to people who want to read the code. And finally the
comment about user list was at wrong spot.
all old versions to v2.20 -- returns 0
from v2.20 to v2.26 -- returns 1
since v2.26 -- returns 0
I think re-read errors should not be interpreted as fatal errors,
because it's pretty common that you want to modify only one partition
(e.g. resize) and then another partitions are probably still in use
and re-read all PT does not make sense.
What we need is to improve granularity for re-read and calls it only
when really necessary (all PT modified) and otherwise call BLKPG
(add/delete/resize) ioctls.
Reported-by: Nikhil Valluru <vvnikhil@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Sami Kerola [Mon, 18 Jul 2016 20:49:27 +0000 (21:49 +0100)]
logger: remove trailing spaces when outputing to journal
Issues:
1. Whitespace-ish \r is not stripped, while it should be.
2. In journal \r is considered unprintable.
Lennart: "it is the duty of the client side to drop the trailing whitespace,
which "logger" doesn't do".
Reported-by: Ivan Babrou <ibobrik@gmail.com> Explained-by: Lennart Poettering <lennart@poettering.net>
Reference: https://github.com/systemd/systemd/issues/3416 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Casting the value to be checked to size_t renders the check useless.
If st_size is SIZE_MAX+1, it will be truncated to 0 and the check
succeeds. In fact, this check can never be false because every value
stored in a size_t is smaller or equal to SIZE_MAX.
I think this adjustment was meant to fix a compiler warning for 64 bit
systems for which sizeof(off_t) is sizeof(size_t), but the signedness
differs.
Going unconditionally to the greatest possible unsigned int type if
st_size is positive (off_t is signed) will fix this issue.
Karel Zak [Thu, 14 Jul 2016 11:07:25 +0000 (13:07 +0200)]
Merge branch 'write-improvements' of git://github.com/kerolasa/lelux-utiliteetit
* 'write-improvements' of git://github.com/kerolasa/lelux-utiliteetit:
lib: try to find tty in get_terminal_name()
write: stop removing and adding /dev/ in front of tty string
write: tell when effective gid and tty path group mismatch
write: improve coding style
write: remove PUTC macro
write: make timestamp to be obviously just a clock time
write: remove unnecessary utmp variables
write: improve function and variable names
write: add control structure to clarify what is going on
write: run atexit() checks at the end of execution
write: use xstrncpy() from strutils.h
write: set atime value in term_chk() only when needed
write: remove pointless fileno(3) calls
write: get rid of function prototypes
write: remove unused variable
Sami Kerola [Sat, 2 Jul 2016 09:28:55 +0000 (10:28 +0100)]
sulogin: remove __nonnull__ function attribute
This change fixes compiler option -Werror=nonnull option warning:
login-utils/sulogin-consoles.c: In function 'append_console':
login-utils/sulogin-consoles.c:324:14: warning: nonnull argument 'consoles'
compared to NULL [-Wnonnull-compare]
The NULL check done with list_empty() looks valid, so it is best to remove
the function attribute that allows compiler to optimize the check away.
We also need to detect non-empty recursion in the EBR chain. It's
possible to create standard valid logical partitions and in the last one
points back to the EBR chain. In this case all offsets will be non-empty.
Unfortunately, it's valid to create logical partitions that are not in
the "disk order" (sorted by start offset). So link somewhere back is
valid, but this link cannot points to already existing partition
(otherwise we will see recursion).
This patch forces libblkid to ignore duplicate logical partitions, the
duplicate chain segment is interpreted as non-data segment, after 100
iterations with non-data segments it will break the loop -- no memory
is allocated in this case by the loop.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1349536
References: http://seclists.org/oss-sec/2016/q3/40 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Mon, 11 Jul 2016 13:33:46 +0000 (15:33 +0200)]
chrt: add fallback to be usable on kernels without sched_{get,set}attr
We have fallback for compilation with/without proper glibc and kernel
headers, but it's not enough, because people can switch between
kernels with and without the syscalls. (For example RT kernels for
RHEL/CentOS).
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1353340 Signed-off-by: Karel Zak <kzak@redhat.com>
Sami Kerola [Sat, 14 May 2016 18:50:41 +0000 (19:50 +0100)]
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.
Sami Kerola [Sat, 14 May 2016 18:39:37 +0000 (19:39 +0100)]
write: stop removing and adding /dev/ in front of tty string
Add both path and tty name representations of tty's to control structure,
that point to same string beginning from different depths. This way there
is no need to removing and adding /dev/ in front of tty string all the time.
Secondly this change makes it possible to use of get_terminal_name() from
ttyutils.c.
Sami Kerola [Sat, 7 May 2016 22:44:17 +0000 (23:44 +0100)]
write: tell when effective gid and tty path group mismatch
Most commonly this error happens when write(1) executable does not have
correct group ownership and setgid bit. The earlier message was unclear
what exactly was wrong.
$ mesg
is y
$ write testuser
write: you have write permission turned off
Alternatively the 'getegid() == s.st_gid' could be considered unnecessary.
Afterall if to write to destination tty is denied that does not go unnoticed
at thet time when tty is opened.
Reviewed-by: Benno Schulenberg <bensberg@justemail.net> Signed-off-by: Sami Kerola <kerolasa@iki.fi>