Commit Graph

396 Commits

Author SHA1 Message Date
Sami Kerola 929f939e6a dmesg: move get_boot_time() to lib/timeutils
In future the last(1) will use get_boot_time() as well.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-05-04 11:42:03 +01:00
Sami Kerola 1786a9ac2b lib/procutils: notice setuid() process ownership changes
Earlier the owner of a process was determined by owner of the
/proc/<pid>/stat file.  When changes user ID privileges with setuid() the
stat file ownership is not updated, that resulted kill(1) to consider
such processes where running using same uid as the present process.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-04-26 19:04:57 +01:00
Sami Kerola 5889fbe592 lib/procutils: reset errno before strtol() call
When going through /proc the last entry made readdir() to alter errno,
which made the strtol() to think something went wrong, resulting kill(1)
tests to fail when running in --parallel mode.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-04-26 19:04:57 +01:00
Karel Zak 0c33fcbf23 lib/mbalign: report also size in bytes
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-15 15:25:18 +02:00
Karel Zak c426f70fd4 lib/mbsalign: split mbs_safe_encode()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-15 13:58:34 +02:00
Karel Zak d9554c97e8 libsmartcols: rewrite test code to tree(1)-like util
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-08 12:13:02 +02:00
Ondrej Oprala 10a628c8b3 lib/tt.c: Goodbye!
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2014-04-03 12:29:19 +02:00
Sami Kerola 0720d60cc1 mcookie: use lib/randutils
The mcookie should reuse existing code, and there is definitely no need
to prefer /dev/random for this utility.  See reference for explanation
about later statement.

References: http://www.2uo.de/myths-about-urandom/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-26 10:36:18 +01:00
Karel Zak c1a5428667 lib/colors: care about colors only on tty()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-12 09:27:10 +01:00
Karel Zak 5296523d6b lib/strutils: fix parse_size() return code
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 12:59:42 +01:00
Karel Zak 2d49d0b65f lib/colors: fix colors test
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:51:38 +01:00
Karel Zak e11040bdfc lib/tt: keep track about output order
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:14 +01:00
Karel Zak 9a66e1e76f lib/tt: add tt_line_get_userdata()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:14 +01:00
Karel Zak 6c6750db34 lib/strutils: support dec.points in parse_size()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 3643958f48 lib/strutils: use proper return codes in parse_size()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 1b1f66e477 lib/mbalign: add mbs_safe_width() from tt.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak ed494c8d50 include/tt: add function to convert table to string
Note that open_memstream() is POSIX-1.2008, so it's possible than not
all libc have already implemented this function.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 7358229637 lib/tt: add reduce term width functionality
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak b839bd4fa1 lib/tt: add TT_FL_MAX to fill screen
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 575a1de03a lib/tt: add tb_get_nlines()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 0cd73f41e8 lib/tt: don't hardcode stdout as output
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 329b0ee753 lib/colors: support <name>.enable too
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 10:38:15 +01:00
Karel Zak 60ec67ff4e lib/colors: add info to man pages, add terminal-colors.d.5
Co-Author: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 10:05:32 +01:00
Ondrej Oprala d0c9ddc3cc lib/colors: check for /etc/terminal-colors.d/[util].disable
[kzak@redhat.com: - move paths to pathnames.h,
                  - use static path buffer]

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 09:38:09 +01:00
Karel Zak ea7f012b7c lib/sysfs: make dirent d_type usage more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-04 11:30:03 +01:00
Karel Zak 68f7b572ba lib/color: add colorscheme parser 2014-02-10 14:50:12 +01:00
Karel Zak 663bf04061 losetup: wait for udev
On system with /dev/lop-control the udevd creates /dev/loopN nodes.
It seems better to wait a moment after unsuccessful open(/dev/loopN)
and try it to open again.

The problem is pretty visible on systems where udevd also modifies
permission for loopN devices, then open() fails with EACCES when
losetup executed by non-root user (but user who is in "disk" group).

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1045432
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-24 13:58:40 +01:00
Karel Zak a6d85ee0a1 lib/sysfs: fix scanf format string [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-14 18:02:06 +01:00
Karel Zak dd3bc51a53 lib/path: add path_strdup()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-06 16:48:13 +01:00
Benno Schulenberg 47481cbd01 textual: standardize some "cannot read" and "seek failed" error messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-10-09 11:37:38 +02:00
Karel Zak a7d5202b5e losetup: don't require 512-byte aligned offsets
Kernel aligns the device size, but the offset where the device starts
is not required to be aligned.

 # losetup --offset 32 -f file.img

is just fine, the final size of the look device will be (in sectors)

  (backing_file_size - offset) >> 9

so we have to do the same in userspace when we check for successful
set capacity ioctl.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-01 15:52:11 +02:00
Karel Zak 80a1712f54 fdisk: add -L to colorize output
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:47:09 +02:00
Karel Zak f234cc3b51 lib/tt: add TT_FL_FREEDATA
... to call free() for line data.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:46:53 +02:00
Karel Zak db2a3dda74 lib: add crc64()
Based on bcache code from Rolf Fokkens.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-11 16:40:06 +02:00
Karel Zak 60f25deae7 lib: rename time-util.c to timeutils.c, fix headers
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-10 13:11:02 +02:00
Karel Zak 646e159aa9 lib/strutils: optimalize {starts,ends}with()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-10 12:18:20 +02:00
Sami Kerola 75ab9bf1eb lib/time-util: move YYYYMMDDHHMMSS to common parser
Even while the YYYYMMDDHHMMSS time format it not magnificent it is best
to make it to be part of the one, and only, time format parser.

Proposed-by: Karel Zak <kzak@redhat.com>
References: http://markmail.org/message/6baqt4ttkopu7ra6
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Sami Kerola 199e939d88 lib/strutils: move *swith() functions to private library
Avoid code dublication in libmount and time-util.

Proposed-by: Karel Zak <kzak@redhat.com>
Reference: http://markmail.org/message/h7zexvqsieqngtmx
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Sami Kerola 2659a49ef0 lib/time-util: copy time parsing functions from systemd
The functions are copied nearly as-is.  Coding style has been modified to
match with util-linux project, while the functionality remains untouched.

CC: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Karel Zak 3cb2413b02 losetup: use loop-control to explicitly ask for device
Now we use LOOP_CTL_GET_FREE ioctl to ask for free device, for example

  losetup -f foo.img

Unfortunately, losetup(8) allows to ask for specified device

  losetup /dev/loop100 foo.img

and in this case we assume that the device already exists in the
system. This is incorrect, we should be able to use loop-control
LOOP_CTL_ADD ioctl to ask for the specified device.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-06 11:04:35 +02:00
Karel Zak 01307ecf1b losetup: set errno for misaligned offsets
References: https://bugs.archlinux.org/task/36189
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-19 17:15:44 +02:00
Sami Kerola f7ff041409 lib/mbsalign: initializations values are never read [clang-analyzer]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-07-09 14:25:02 +02:00
Sami Kerola f55d9a4f81 lib/loopdev: assigned value is never read [clang-analyzer]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-07-09 14:25:00 +02:00
Karel Zak 8a52ef658c lib/canonical: use realpath() from libc
.. after many many years it seems that we can follow libc code rather
than duplicate realpath(3) implementation.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-01 16:13:46 +02:00
Mike Frysinger a84aa9df6f exec_shell: add a license and touch up func def
When this file was created, the standard license header was missed.
Add it using the same one from unshare.c.

The noreturn attribute is not needed since we include the header
which has it on the prototype.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2013-07-01 11:46:13 +02:00
Karel Zak 7ba207e781 libmount: be robust for empty target/source strings
* lib/canonicalize.c: don't interpret empty strings as relative paths
 * libmount: more robust libmnt_table find function and debug messages

References: https://bugzilla.novell.com/show_bug.cgi?id=825150
Signed-off-by: Karel Zak <kzak@redhat.com>

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-06-17 13:02:15 +02:00
Sami Kerola d722ce211a lib: remove unused code
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-06-07 12:24:40 +02:00
Karel Zak b1d4444988 lib/tty: fix get_terminal_name() usage, cleanup code
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-28 12:10:29 +02:00
Karel Zak 507341f832 lib/tty: don't hardcode terminal fd in get_terminal_name()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-13 15:40:57 +02:00
Karel Zak e3b6cb87e0 lib/loopdev: fix loopcxt_check_size() to work with blkdevs
The loopcxt_check_size() is workaround for kernels < v3.9, kernel has
been fixed by commit 541c742a7559eb65f0e36d3e2338c2ca532a3e61.

The function sets loopdev size according to backing file size. The
problem is that the backing file could be a block device where
stat.st_size is zero, so we have to use blkdev_get_size() for block
devices.

Addresses: https://bugs.archlinux.org/task/35193
Reported-by: Dave Reisner <d@falconindy.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-13 10:54:41 +02:00