Commit Graph

10616 Commits

Author SHA1 Message Date
Sami Kerola 92a4d098ce
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.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sami Kerola 01e6b621e4
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.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sami Kerola 341154da28
switch_root: simplify code and reduce indentation [oclint]
The if statement in line 162 already ensures value of cfd to be 0 or
greater, so the later if is not needed.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sami Kerola 74ce680a3e
misc: simplify if clauses [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Karel Zak 10e8d7a324 agetty: call uname() only when necessary
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-20 13:20:14 +02:00
Karel Zak 1132e5aad1 agetty: fix \S usage
If \S without argument used then uninitialized 'varname' compared with
ANSI_COLOR.

Addresses: https://github.com/karelzak/util-linux/issues/329
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-20 13:16:13 +02:00
Karel Zak 78e7f78896 Revert "sfdisk: exit with error if rereading partition table fails"
This reverts commit 14f644f386.

It seems we have mess in reread-after-write:

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>
2016-07-20 11:24:36 +02:00
Sami Kerola f1f5f21ee6 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>
2016-07-19 11:02:48 +02:00
Tobias Stoeckmann 3f0e7f371a tailf: Fix previously adjusted segfault patch
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.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-07-19 11:01:18 +02:00
Karel Zak b8fd5c0558 tests: fix ttyutils test
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-15 10:11:35 +02:00
Karel Zak aefd6a9d6a write: don't use strftime()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-14 13:20:58 +02:00
Karel Zak 85a37ca8d1 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
2016-07-14 13:07:25 +02:00
Sami Kerola b236e43ef0 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.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-14 12:28:53 +02:00
James Clarke 0d474d29c5 tests: Fix fdisk/id and fdisk/mbr-nondos-mode on Sparc
On Sparc, fdisk defaults to using SUN disk labels, which causes the
output from these tests to differ from non-Sparc.

Signed-off-by: James Clarke <jrtc27@jrtc27.com>
2016-07-14 12:20:55 +02:00
Allon Mureinik 6bc4cc18e6 blkdiscard: Improve man page
Improve the grammar and phrasing of the --verbose option and how it
interacts with the --step option.

Signed-off-by: Allon Mureinik <amureini@redhat.com>
2016-07-14 12:20:07 +02:00
Tobias Stoeckmann e368476050 tailf: Fix segmentation fault in tailf on 32 bit
tailf crashes with a segmentation fault when used with a file that is
exactly 4GB in size due to an integer overflow between off_t and size_t:

$ dd if=/dev/zero of=tailf.crash bs=1 count=1 seek=4294967295
$ tailf tailf.crash
Segmentation fault
$ _

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-14 12:09:51 +02:00
Thierry Vignaud 04c163ed16 fdisk: make -l <dev ...> behaves like fdisk -l
aka having the same spacing between disks

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-14 12:04:04 +02:00
Karel Zak 50d1594c2e libblkid: avoid non-empty recursion in EBR
This is extension to the patch 7164a1c34d.

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>
2016-07-12 13:34:54 +02:00
Karel Zak 6f27e449a9 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>
2016-07-11 15:33:46 +02:00
Karel Zak 2cad2b32ff tests: mark chrt as TS_KNOWN_FAIL
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-11 12:36:51 +02:00
Karel Zak b267ec301b tests: make chrt test more debug-able
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-11 11:54:31 +02:00
Karel Zak 77604e87f3 tests: mark chrt tests as root-only
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-11 11:12:47 +02:00
Karel Zak 94fa9b4637 tests: implement ts_skip_subtest
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-11 11:01:14 +02:00
Karel Zak 078720a76f tests: add chrt test
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-11 10:25:13 +02:00
Karel Zak 6e51ab0c5c cfisk: add /dev/vda as another default disk
And use array for all default alternative disks.

Reported-by: Thierry Vignaud <thierry.vignaud@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-07 15:02:20 +02:00
Karel Zak 7164a1c34d libblkid: ignore extended partition at zero offset
If the extended partition starts at zero LBA then MBR is interpreted
as EBR and all is recursively parsed... result is out-of-memory.

 MBR --extended-partition--> EBR --> MBR --> ENB --> MBR ...

Note that such PT is not possible to create by standard partitioning
tools.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1349536
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-07 14:22:41 +02:00
Sami Kerola 285c1f3a3e
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.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-03 23:35:10 +01:00
Sami Kerola a58b90255c
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.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-03 23:35:10 +01:00
Sami Kerola 50e417c8ad
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>
2016-07-03 23:35:09 +01:00
Sami Kerola 5592bf0d9a
write: improve coding style
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-03 23:35:09 +01:00
Sami Kerola a8031743ea
write: remove PUTC macro
Function like macros make following the execution flow unnecessarily
difficult, and deserves to be removed.

Requested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-03 23:34:55 +01:00
Sami Kerola a079439266
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.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 22:07:02 +01:00
Sami Kerola c1d0a95eea
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>
2016-07-01 21:17:25 +01:00
Sami Kerola d732758e65
write: improve function and variable names
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 21:13:13 +01:00
Sami Kerola b5a6937961
write: add control structure to clarify what is going on
This is done purely an improve readability of the source code.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 21:08:53 +01:00
Sami Kerola 97ebab4ea8
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.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 21:01:26 +01:00
Sami Kerola e4aaa0e593
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.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 20:59:23 +01:00
Sami Kerola 489a0fd2f5
write: set atime value in term_chk() only when needed
The search_utmp() is needs atime but main() does not, so remove the later.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 20:54:02 +01:00
Sami Kerola 59f3d6ae12
write: remove pointless fileno(3) calls
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 20:51:47 +01:00
Sami Kerola b985f37240
write: get rid of function prototypes
Marking functions static and writing them in order where functions are
introduced before use is enough.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 20:51:47 +01:00
Sami Kerola 1baec22b08
write: remove unused variable
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-01 20:51:47 +01:00
Karel Zak 99ae5a4956 lsns: check for OOM
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-01 15:42:50 +02:00
Karel Zak f29bc6e1cc lslocks: add --noinaccessible
* add --noinaccessible to not print incomplete information

* make incomplete paths more visible (append "...")

* don't print 0B size if lock file inaccessible

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-01 14:45:04 +02:00
Karel Zak 29fdedc2bc 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
2016-07-01 13:51:59 +02:00
Alexey Obitotskiy 6c448f452e 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.

Signed-off-by: Alexey Obitotskiy <aleksey.obitotskiy@intel.com>
2016-07-01 13:40:11 +02:00
Karel Zak 3383b2f5ca agetty: don't modify argv[] when parse speeds
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-30 14:00:44 +02:00
Sami Kerola 3d47107de5
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.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-06-27 20:40:37 +01:00
Sami Kerola b5ef1507df
tests: utmpdump add subsecond accuracy test
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-06-27 19:57:29 +01:00
Sami Kerola 73f46aedc3
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.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-06-27 19:57:05 +01:00
Sami Kerola a17e7d7fab
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.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-06-26 21:58:18 +01:00