Commit Graph

54 Commits (277e777fe8839b2434ddd394810a5fef86a61fab)

Author SHA1 Message Date
John Groves 277e777fe8 lib: Add simple crc32c() function
Source: freebsd/sys/libkern/crc32.c
This code is an unmodified fragment from the source.  Will fixup
comments / naming in next commit

Signed-off-by: Karel Zak <>
2017-11-16 11:44:39 +01:00
Niklas Hambüchen 6855f6e80b kill: Extract signal names into signames.h/signames.c 2017-10-14 04:46:13 +02:00
Karel Zak 4f5f35fc83 login: add xgetpwnam()
Signed-off-by: Karel Zak <>
2017-09-18 11:48:56 +02:00
Philip Prindeville 0047626887 libuuid: add support for hash-based UUIDs
Adding V3 and V5 UUIDs per RFC-4122.

[ - fix symbols file]

Signed-off-by: Philip Prindeville <>
Signed-off-by: Karel Zak <>
2017-09-05 11:26:39 +02:00
Ruediger Meier c0d7b11a3f 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

Signed-off-by: Ruediger Meier <>
2017-06-01 03:16:48 +02:00
Karel Zak c9ae73c03f lib/colors: fix test compilation
Signed-off-by: Karel Zak <>
2017-05-31 01:29:25 +02:00
Karel Zak 23d4726784 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)

Signed-off-by: Karel Zak <>
2017-05-30 17:14:12 +02:00
Karel Zak 30d7f61f4f build-sys: add parse-date.y
* add lib/parse-date.y to build system
* add necessary autotools stuff to generate .c on the fly
  (autotools are smart enough to add generated file to tarball)
* check for bison version by ./
* add non-wanted junk to .gitignore

With some modification by J William Piggott with regard to
moving the parse-date API into timeutils.h

Signed-off-by: J William Piggott <>
2017-03-04 11:01:56 -05:00
Karel Zak 299ef2c457 lib/mbsedit: add simple buffer editor
Signed-off-by: Karel Zak <>
2017-02-16 13:47:44 +01:00
Karel Zak 63dc575be3 build-sys: test_linux_version is Linux only
Signed-off-by: Karel Zak <>
2017-01-04 15:44:51 +01:00
Karel Zak e8f7acb0d3 lib: use unique ifdefs for tests
Let's use unique TEST_PROGRAM_<NAME> ifdefs to make build system more

Signed-off-by: Karel Zak <>
2017-01-04 11:44:37 +01:00
Karel Zak 5b9403a68f lib/linux_version: add test for manual testing
Signed-off-by: Karel Zak <>
2017-01-02 11:36:53 +01:00
Karel Zak 1eb16fd780 build-sys: add --disable-plymouth-support
The plymouth support depends on Linux specific SOCK_* flags and all
the feature is probably unnecessary in some cases (non-plymouth
distros, etc.)

Signed-off-by: Karel Zak <>
2016-05-26 15:08:53 +02:00
Werner Fink fe3f7e17aa sulogin: agetty: use the plymouth local protocol instead the plymouth binary
for stopping plymouthd.  That do not depend on the existence of
the plymouth binary if it e.g. becomes uninstalled or an other
service is providing plymouthd facilities.

[ - fix compiler warnings [-Wpointer-sign]
                  - use sizeof() for write_all()
                  - cast to char* for read_all]

Signed-off-by: Werner Fink <>
Signed-off-by: Karel Zak <>
2016-05-20 11:21:10 +02:00
Karel Zak 3c201431ee lib/timeutils: add strxxx_iso() functions
Signed-off-by: Karel Zak <>
2016-05-11 15:31:02 +02:00
Kent Overstreet 7ce27dc517 libblkid: Update for newer bcache superblocks
Later version of bcache add different checksum types, and allow for superblocks
greater than 4k - skipping the checksum check (as in most other probes) is the
easiest solution.

Signed-off-by: Kent Overstreet <>
2016-03-23 10:52:38 +01:00
Ruediger Meier dc0495166f build-sys: add and use openat build conditionals
Signed-off-by: Ruediger Meier <>
2016-03-07 15:37:25 +01:00
Ruediger Meier 1a048dc5e2 lib: move fopen_at() to fileutils.h, remove at.h
Signed-off-by: Ruediger Meier <>
2016-03-07 15:36:00 +01:00
Ruediger Meier 2208b3ccb2 lib: remove openat fallback functions (include/at.h)
I have validated that we are still compatible at least back to
  - openSUSE 11.4
  - SLE 11
  - RHEL/CentOS 6
  - OSX 10.10.x, (Xcode 6.3)
  - FreeBSD 10.2

Confirmed incompatibility:
  - OSX 10.9.x, (Xcode 6.2)

Signed-off-by: Ruediger Meier <>
2016-03-07 15:33:56 +01:00
Ruediger Meier b0b54cc582 build-sys: always add AM_CFLAGS
We were missing our nice compliler warnings for many programs
and libs. See next commits how many trivial and non-trival
warnings have to be fixed.

Signed-off-by: Ruediger Meier <>
2016-02-23 01:17:29 +01:00
Ruediger Meier b201f1d86c build-sys: always use global LDADD
This was a major showstopper when building on a system where
LTLIBINTL libs are needed (e.g. OSX). Maybe there are a few test
programs which wouldn't need LDADD ... never mind.

Signed-off-by: Ruediger Meier <>
2016-02-23 01:16:58 +01:00
Karel Zak 04a5cb58b6 namei: move icache to lib/
Signed-off-by: Karel Zak <>
2015-11-27 13:56:01 +01:00
Karel Zak f9ffaac0d2 build-sys: fix test_colors build
Signed-off-by: Karel Zak <>
2015-07-24 14:33:25 +02:00
Karel Zak 0bef6f759b libsmartcols: don't link with tinfo
Let's move color names to sequence translation to separate file to
make it usable without all the stuff in lib/colors.c.

Signed-off-by: Karel Zak <>
2015-07-24 12:57:46 +02:00
Karel Zak a6bf40ee77 lslogins: merge read_utmp() code
The code is used only in lslogins, so it does not make sense to
maintain it in libcommon.

Signed-off-by: Karel Zak <>
2015-07-16 11:26:14 +02:00
Karel Zak 548b9714e8 lib/strv: add new functions (from systemd)
Signed-off-by: Karel Zak <>
2015-05-15 14:57:04 +02:00
Karel Zak 4310faf950 lib/colors: use libtinfo to check terminal capability
The current implementation assumes that all terminals supports colors
and users are forcet to use terminal-colors.d/ to disable colors for
some terminals.

This patch checks for maximal supported colors for the current
terminal and colors are automatically disabled for terminals like

The patch moves lib/colors.c from to to
avoid collisions with another utils.

Signed-off-by: Karel Zak <>
2015-02-27 13:57:34 +01:00
Karel Zak 9cf4f90911 lib/loopdev: remove test program
All is already covered by losetup and mount. The test program has
never been used in our regression tests.

Signed-off-by: Karel Zak <>
2014-11-04 15:36:05 +01:00
Sami Kerola 96c4bc4dd2 lib: remove xgetpass()
This function is not in use, and it has reference to obsoleted getpass().

Signed-off-by: Sami Kerola <>
2014-09-19 19:31:01 +01:00
Karel Zak d8ae3d977b tests: remove test_wholedisk
Signed-off-by: Karel Zak <>
2014-06-17 12:45:28 +02:00
Karel Zak 62acb047a6 build-sys: remove obsolete wholedisk.c
Signed-off-by: Karel Zak <>
2014-06-17 12:16:29 +02:00
Ondrej Oprala 29cc2a5568 lslogins: add functionality
Signed-off-by: Ondrej Oprala <>
2014-05-15 13:55:59 +02:00
Ondrej Oprala 10a628c8b3 lib/tt.c: Goodbye!
Signed-off-by: Ondrej Oprala <>
2014-04-03 12:29:19 +02:00
Karel Zak 60ec67ff4e lib/colors: add info to man pages, add terminal-colors.d.5
Co-Author: Ondrej Oprala <>
Signed-off-by: Karel Zak <>
2014-03-11 10:05:32 +01:00
Karel Zak db2a3dda74 lib: add crc64()
Based on bcache code from Rolf Fokkens.

Signed-off-by: Karel Zak <>
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 <>
2013-09-10 13:11:02 +02: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 <>
Signed-off-by: Sami Kerola <>
2013-08-29 18:14:08 +01:00
Karel Zak a10c043493 lib/colors: add support for auto, always and never modes
... to implement --color[=<when>]

Signed-off-by: Karel Zak <>
2013-05-06 19:07:23 +02:00
Jeff Mahoney 293714c0d1 loopdev: sync capacity after setting it
I recently tried to mount an hfsplus file system from an image file with
a partition table by using the loop offset and sizelimit options to specify
the location of the file system.

hfsplus stores some metadata at a set offset from the end of the partition,
so it's sensitive to the device size reported by the kernel.

It worked with this:

But failed with this:

/dev/loop0: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000
/dev/loop1: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000

/proc/partitions shows the correct number of blocks to match the sizelimit.

But if I set a breakpoint in mount before the mount syscall, I could see:

The kernel loop driver will set the gendisk capacity of the device at
LOOP_SET_STATUS64 but won't sync it to the block device until one of two
conditions are met: All open file descriptors referring to the device are
closed (and it will sync when re-opened) or if the LOOP_SET_CAPACITY ioctl
is called to sync it. Since mount opens the device and passes it directly
to the mount syscall after LOOP_SET_STATUS64 without closing and reopening
it, the sizelimit argument is effectively ignroed. The capacity needs to
be synced immediately for it to work as expected.

This patch adds the LOOP_SET_CAPACITY call to loopctx_setup_device since
the device isn't yet released to the user, so it's safe to sync the capacity

[ - port to the current git HEAD,
                  - use uint64_t]

Signed-off-by: Jeff Mahoney <>
Signed-off-by: Karel Zak <>
2013-04-09 14:32:50 +02:00
Karel Zak 13377dd64a lib/procutils: add simple API to scan /proc/PID/*
Signed-off-by: Karel Zak <>
2013-03-12 17:24:14 +01:00
Zbigniew Jędrzejewski-Szmek 5758069426 unshare,nsenter: spawn shell by default
The behaviour mimics chroot.

Possibly it would have been nicer to to query the password database in
the new namepace and run the shell of the user there, but it's hard to
do correctly. getpwuid() might need to load nss plugins, and the arch
in the new namespace might be different (in case of NEWNS mounts), or
the hostname might be different, etc. So in general it's not possible
to do it reliably.

Signed-off-by: Zbigniew Jędrzejewski-Szmek <>
2013-02-14 14:42:35 +01:00
Karel Zak a73f59fa03 sulogin: remove consoles.c from libcommon
- move struct chardata to include/ttyutils.h
- move console.{h,c} to login-utils/sulogin-* (it's sulogin specific)
- fix sulogin and agetty includes

Signed-off-by: Karel Zak <>
2012-12-23 22:14:21 +01:00
Karel Zak ca4f6229b0 lib/ismounted: basic support for loop devices
# losetup -a /dev/loop0
 /dev/loop0: [2053]:1048578 (/home/fs-images/filesystems/ext2.img)

 # findmnt /dev/loop0
 /mnt/test /dev/loop0 ext3   rw,relatime,data=ordered

old version:

 ./test_ismounted /home/fs-images/filesystems/ext2.img
 not mounted

new version:

 ./test_ismounted /home/fs-images/filesystems/ext2.img
 mounted on /mnt/test

Reported-by: Sami Kerola <>
Signed-off-by: Karel Zak <>
2012-12-19 12:40:32 +01:00
Karel Zak 5f247c8bcd lib/ttyutils: add test program
Signed-off-by: Karel Zak <>
2012-11-22 14:32:21 +01:00
Karel Zak 4e76adb0e1 lib/ttyutils: create .c file
Well, now all tty stuff are incline functions in include/ttyutils.h.
It's seems more elegant to create regular lib/ttyutils.c for libcommon
and write test program.

Signed-off-by: Karel Zak <>
2012-11-22 14:26:41 +01:00
Karel Zak 82d11fbd0f lib/consoles: add test program
Signed-off-by: Karel Zak <>
2012-11-09 10:12:35 +01:00
Werner Fink 3a08f74f1d lib/consoles: add code to detect all system consoles
Signed-off-by: Werner Fink <>
2012-11-08 15:55:48 +01:00
Karel Zak e21e6d265d build-sys: cleanup cpu_set_t usage
- make taskset depend on cpu_set_t
 - make cpuset.c optional for libcommon and lib/path.c

Signed-off-by: Karel Zak <>
2012-11-02 12:07:36 +01:00
Ondrej Oprala dfa68ad183 lib/color: add module for work with terminal colors
[ - split from dmesg patch
                  - add more colors]

Signed-off-by: Ondrej Oprala <>
Signed-off-by: Karel Zak <>
2012-10-16 16:39:00 +02:00
Samuel Thibault 4797b1e592 Fix non-Linux build
loopdev.c, test_pager, and get_max_number_of_cpus() are linux-specific.
get_linux_version will only work on Linux, let's introduce
system_supports_ext4_ext2() which assumes that mounting ext2 with ext4
is not supported on non-Linux systems.

[ - use #ifdef SYS_sched_getaffinity rather than __linux__]

Signed-off-by: Samuel Thibault <>
Signed-off-by: Karel Zak <>
2012-08-13 15:14:13 +02:00