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>
Sami Kerola [Sat, 7 May 2016 20:07:44 +0000 (21:07 +0100)]
write: make timestamp to be obviously just a clock time
By looking the code one will had hard time knowing that a slice of ctime()
from characters 11 to 16 is HH:MM time format. Use of strftime("%H:%M")
makes this a lot less mysterious.
In same go make \007 hex printouts to be \a that is the same thing: alarm.
Sami Kerola [Sat, 7 May 2016 11:50:01 +0000 (12:50 +0100)]
write: remove unnecessary utmp variables
glibc documentation tells getutent() calls are not thread safe, and
recommends to copy the context of the structures when information is wished
to be stored. This leads to excessive copying, that in this case is not
relevant. write(1) is single threaded program and there is no reason to
assume this would change in future.
Reference: http://www.gnu.org/software/libc/manual/html_node/Manipulating-the-Database.html Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Sami Kerola [Sat, 7 May 2016 07:33:57 +0000 (08:33 +0100)]
write: run atexit() checks at the end of execution
Earlier use of _exit() caused program to terminate abnormally from atexit()
perspective and standard file descriptor close checks did not run resulting
to blindness if writes were successful, or not. Easy fix is to avoid
running _exit() altogether.
Sami Kerola [Fri, 6 May 2016 23:20:32 +0000 (00:20 +0100)]
write: use xstrncpy() from strutils.h
Earlier if the tty path was exactly length of the maximum ut_line then last
character of the path was overwrote by \0. This is in practise theoretical
bug, as it is unheard that a tty device path could be 32 characters long.
Karel Zak [Fri, 1 Jul 2016 11:51:59 +0000 (13:51 +0200)]
Merge branch 'utmpdump' of git://github.com/kerolasa/lelux-utiliteetit
* 'utmpdump' of git://github.com/kerolasa/lelux-utiliteetit:
docs: add file format note to utmpdump manual page
tests: utmpdump add subsecond accuracy test
tests: challenge utmpdump localization go-around
tests: fix utmpdump timestamps to be in iso format
utmpdump: use iso-8601 timestamp format with subsecond accuracy
libcommon: add ISO_8601_GMTIME that will print UTC-0 timestamps
utmpdump: use always UTC-0 timezone in textual output
libblkid: Add metadata signature check for IMSM on 4Kn drives
Drives with 512 and 4K sectors have different offset for
metadata signature. Without signature detected on 4Kn drives
those drives will not be recognized as raid member. This
patch adds checking for IMSM signature for 4Kn drives.
Sami Kerola [Mon, 27 Jun 2016 19:38:27 +0000 (20:38 +0100)]
docs: add file format note to utmpdump manual page
Tell that the old textual format that does not use full utmp time precision,
and has issues with timezones. Warn also that the textual format may become
incompatible, although there are no plans in foreseeable future to do so.
Sami Kerola [Sun, 15 May 2016 09:42:25 +0000 (10:42 +0100)]
tests: challenge utmpdump localization go-around
The utmpdump timestamps are unambiguous, they always use UTC-0 regardless of
localization. If thesse tests starts to fail after this change then the
timezone forcing is not working.
Sami Kerola [Sun, 15 May 2016 09:32:20 +0000 (10:32 +0100)]
tests: fix utmpdump timestamps to be in iso format
The utmpdump-circle is slightly modified to use old timestamp format as
basis of conversion and to do cyclic conversion via new format. This is
better from test coverage point of view.
Sami Kerola [Sun, 15 May 2016 09:25:48 +0000 (10:25 +0100)]
utmpdump: use iso-8601 timestamp format with subsecond accuracy
Newer 'struct utmp' is using 'struct timeval' to represent login and logout
times, so include the maximum accuracy to textual utmp format. Notice that
this change does not remove support of converting earlier textual formats
back to binary. But conversions from binary to former format will no longer
be available.
Sami Kerola [Sun, 15 May 2016 08:50:40 +0000 (09:50 +0100)]
utmpdump: use always UTC-0 timezone in textual output
Converting a time structure from text format that has timezone markup is
practically impossible. See reference links for more information. This
leads to situation where multiple utmpdump(1) conversions from binary to
text and back make timestamps to shift amount of timezone offset to UTC-0.
The easiest way to make multiple conversions to work without timeshifts is
to always use UTC-0 timezone. Downside of this approach is that the textual
format is less human readable than local timestamps would be.
Reference: http://www.catb.org/esr/time-programming/#_strptime_3_and_getdate_3
Reference: http://man7.org/linux/man-pages/man3/strptime.3.html Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Torsten Hilbrich [Mon, 20 Jun 2016 05:09:10 +0000 (07:09 +0200)]
liblkid: Add length check in probe_nilfs2 before crc32
The bytes variable is read from the file system to probe and must be
checked before used as length parameter in the crc32 call.
The following problems may occur here:
- bytes smaller than sumoff + 4: underflow in length calculation
- bytes larger than remaining space in sb: overflow of buffer
This fixes a problem where an encrypted volume had the correct magic
values 0x3434 at offset 0x406 and the following uint16_t (which is
read into the nilfs_super_block.s_bytes struct) was parsed as 1.
Then crc32 was called with the length value 18446744073709551597
causing a segmentation fault.
Heiko Carstens [Wed, 22 Jun 2016 07:26:01 +0000 (09:26 +0200)]
lscpu: fix MMHZ column entry within man page
The indentation for the MMHZ column within the man page is wrong. Also
there doesn't exist any column with the name MMHZ. The correct names
would be MAXMHZ and MINMHZ.
Therefore rename MMHZ to MAXMHZ and add the missong MINMHZ entry.
Heiko Carstens [Wed, 22 Jun 2016 07:26:00 +0000 (09:26 +0200)]
lscpu: update s390-lpar-drawer testcase
I noticed that the "cpu" line within /proc/cpuinfo has a different
meaning on powerpc and sparc than on s390.
On s390 it represents the cpu number while on powerpc and sparc it
represent the model name. Given that the s390 kernel patch which adds
the "cpu" line to /proc/cpuinfo hasn't been merged into the kernel
yet, I changed that line to "cpu number" to avoid the unnecessary
conflict.
Therefore this patch updates the testcase, which mainly changes the
contents of /proc/cpuinfo.
Heiko Carstens [Wed, 22 Jun 2016 07:25:59 +0000 (09:25 +0200)]
lscpu: show additional caches (s390)
The Linux kernel exposes the cache topology via sysfs. However on
virtualized machines like s390 the cache topology contains only cpu
private caches.
For shared caches it is not known which cpus share them. The
hypervisor would have to update this information whenever a virtual
cpu would be scheduled on a different physical cpu and make the guest
aware of that change. Given that there is hardly any benefit, if it
all, this isn't done.
However it is still of interest to know about the non-private
caches. Therefore this information is available via /proc/cpuinfo at
least on s390.
This patch adds additional lines to the summary output for all shared
caches for which information can be found in /proc/cpuinfo, since we
know these aren't exposed via sysfs.
Heiko Carstens [Wed, 22 Jun 2016 07:25:57 +0000 (09:25 +0200)]
lscpu: show static and dynamic MHz (s390)
s390 machines provide static and dynamic cpu mhz information via
/proc/cpuinfo. The static cpu mhz is the normal cpu frequency a cpu is
supposed to run with.
The dynamic cpu mhz is the actual frequency a cpu is running
with. This is usually the same as the static cpu mhz. Note that this
values are different to the min/max mhz values available on other
architecutes. The min/max values are unknown.
This patch adds two new fields to the summary output which display
these two values.
Karel Zak [Tue, 14 Jun 2016 11:15:44 +0000 (13:15 +0200)]
chfn: chsh: use selinux_check_passwd_access()
* selinux/av_permissions.h and magic constants are deprecated, the
recommended solution is to use string_to_security_class() and
string_to_av_perm() to get access vector
* it also seems that selinux_check_passwd_access() does exactly the
same as our checkAccess(), let's use it.
Karel Zak [Thu, 9 Jun 2016 10:39:44 +0000 (12:39 +0200)]
build-sys: remove global dependence between widechar and ncursesw
It seems that globally defined dependence between ncursesw and
wide-char support is overkill, because in some cases (e.g. cal(1)) we
can use ncurses independently on wide-char support.
It would be better to care about relation between wide-char and
ncurses individually (per util).
Daniel Shahaf [Fri, 3 Jun 2016 21:27:49 +0000 (21:27 +0000)]
ionice: clarify description of --classdata
Before this patch, it wasn't clear whether '0' or '7' should be used to
specify "highest priority". (The answer could have been inferred from
the 'Examples' section of the man page.)
Signed-off-by: Daniel Shahaf <danielsh@apache.org>
uClibc-ng tries to be compatible with GNU libc and defines
__GLIBC__ and pretend to be version 2.2.
We once changed it to 2.10, but then some hard to fix problems
in different software packages (gcc) occured.
It would be better if we disable the special GNU libc checks
for uClibc-ng here. uClibc-ng implements the required scanf
functionality.
Karel Zak [Fri, 3 Jun 2016 12:51:01 +0000 (14:51 +0200)]
more: don't include ncurses.h, fix for non-widechar
It seems our crazy widechar.h is in conflict with ncurses, but it
seems that nothing in more.c requires anything from ncurses. All we
need is probably <term.h>.