Commit Graph

937 Commits

Author SHA1 Message Date
Karel Zak 9fc0f69c25 include/strutils: consolidate string to number conversion
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-24 16:36:58 +02:00
Karel Zak 84825b161b include/strutils: cleanup strto..() functions
* add ul_strtos64() and ul_strtou64()
* add simple test

Addresses: https://github.com/karelzak/util-linux/issues/1358
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-22 14:42:15 +02:00
Karel Zak 17fc8693cd include/c: add drop_permissions(), consolidate UID/GID reset
Fixes: https://github.com/karelzak/util-linux/issues/1354
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-21 12:25:31 +02:00
Karel Zak 5a8261020b lib/path: (test) fix ul_new_path() use 2021-06-18 17:02:38 +02:00
Karel Zak 9dbae34c3d lib/path: improve ul_path_readlink() to be more robust
According to POSIX, readlink() makes no effort to null-terminate buffer
with the result. It seems better to hide this disadvantage in the
ul_path_...() API rather than assume buf[sz] = '\0' everywhere.

Reported-by: Reported-by: Jan Pazdziora <jpazdziora@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-17 13:28:32 +02:00
Karel Zak f3e5d34cac lib/strutils: make test_strutils_normalize() more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-15 10:25:06 +02:00
Karel Zak c862d0e177 lib/strutils: improve normalize_whitespace()
Let's make it possible to use the function to normalize the string
between two buffers (from source to destination).

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-14 16:24:59 +02:00
Karel Zak 1e881378d6 lib/path: fix possible leak when use ul_path_read_string() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-11 15:43:36 +02:00
Thomas Weißschuh f48554d48b libsmartcols: add support for optional boolean values
These default to `null` instead of `false`.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2021-05-30 23:17:23 +02:00
Karel Zak 670b10ae36 lib/c_strtod; add locale independent strtod()
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-25 11:31:08 +02:00
Naohiro Aota 6be38dccae libblkid: add magic and probing for zoned btrfs
This commit adds zone-aware magics and probing functions for zoned btrfs.

The superblock (and its copies) are the only data structure in btrfs with a
fixed location on a device. Since we cannot do overwrites in a sequential
write required zone, we cannot place the superblock in the zone.

Thus, zoned btrfs uses superblock log writing to update superblocks on
sequential write required zones. It uses two zones as a circular buffer to
write updated superblocks. Once the first zone is filled up, start writing
into the second buffer. When both zones are filled up, and before starting
to write to the first zone again, it reset the first zone.

We can determine the position of the latest superblock by reading the write
pointer information from a device. One corner case is when both zones are
full. For this situation, we read out the last superblock of each zone and
compare them to determine which zone is older.

The magics can detect a superblock magic ("_BHRfs_M") at the beginning of
zone #0 or zone #1 to see if it is zoned btrfs. When both zones are filled
up, zoned btrfs resets the first zone to write a new superblock. If btrfs
crashes at the moment, we do not see a superblock at zone #0. Thus, we need
to check not only zone #0 but also zone #1.

It also supports the temporary magic ("!BHRfS_M") in zone #0. Mkfs.btrfs
first writes the temporary superblock to the zone during the mkfs process.
It will survive there until the zones are filled up and reset. So, we also
need to detect this temporary magic.

Finally, this commit extends probe_btrfs() to load the latest superblock
determined by the write pointers.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
2021-05-24 13:39:53 +02:00
Karel Zak 64a89adaa1 lib/jsonwrt: don't use ctype.h for ASCII chars
tolower() does not work "as expected" for tr_TR.UTF-8 (Turkish).
Fortunately, we need to convert only objects and variables names in
JSON output, and this is always old good ASCII.

Anyway, for more details:

	$ cat a.c
	#include <ctype.h>
	#include <stdio.h>
	#include <locale.h>

	int main(void)
	{
		int in, out;

		setlocale(LC_ALL, "");

		in ='I';
		out = tolower(in);

		printf("%1$c [%1$d] --> %2$c [%2$d]\n", in, out);
		return 0;
	}

	$ make a
	cc     a.c   -o a

	$ LANG=en_US.utf8 ./a
	I [73] --> i [105]

	$ LANG=tr_TR.UTF-8 ./a
	I [73] --> I [73]

Fixes: https://github.com/karelzak/util-linux/issues/1302
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 16:35:50 +02:00
Karel Zak 3a07505a39 lib/jsonwrt: remove fputs_quoted_json_* functions from include/carefulputc.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 16:05:56 +02:00
Karel Zak d124a78034 lib/jsonwrt: remove 'islast' from API
The code should be able to keep track about previous content and print
JSON objects separator automatically.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 15:58:02 +02:00
Karel Zak 35c84bf76a lib/strutils: assume 64-bit time_t
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 11:06:45 +02:00
Karel Zak f02286fd89 lib/pty-session: fix time_t=long assumptions
Fixes: https://github.com/karelzak/util-linux/issues/1069
References: ce3355cc54
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 10:22:07 +02:00
Karel Zak d8d54e4bfc build-sys: keep adoc files in dist_noinst_DATA
* rename MANPAGES_EXTRA= to ADOCFILES_COMMON=

* keep track about individual adoc files by dist_noinst_DATA=
  This variable is not effected by automake conditions, so the files
  are always distributed.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-05 13:35:30 +02:00
Armin Begovic ce3355cc54 Fixed wrongful time_t=long assumptions in hwclock.c and timeutils.c 2021-04-29 11:56:37 +00:00
Karel Zak 0216836e8b build-sys: fix test_loopdev build
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-04-20 14:22:34 +02:00
Karel Zak d4423cce9b lib/loopdev: fix is_loopdev() to be usable with partitions
The current implementation of the function does not care if the device
is whole-disk device or partition, all is loopdev. This is regression
as the original is_loopdev() version was based on whole-disk devices
major numbers only.

Fixes: https://github.com/karelzak/util-linux/issues/1202
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-04-20 13:20:12 +02:00
Karel Zak 53b37016c3 meson: generate man pages from asciidoc
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-04-06 15:32:46 +02:00
Karel Zak 625e9c61e8 build-sys: make man pages location independent
We need to evaluate "include::" directive relatively to project
top-level source directory rather than to the current document
location.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-31 11:50:47 +02:00
Karel Zak 25ce8fb1ed Merge remote-tracking branch 'mariobl/topic/asciidoc'
* mariobl/topic/asciidoc: (71 commits)
  Asciidoc: Update .pot template
  Asciidoc: Reorder example command sequence
  Asciidoc: Update .pot template
  Asciidoc: Better gettext message splitting in nsenter.1.adoc
  Asciidoc: Update .pot template
  Asciidoc: Fix typo and remove invisible spaces which confuse po4a
  Asciidoc: Update .pot template
  Asciidoc: Fix typo
  Asciidoc: Fix artifact from initial import, sixth attempt
  Asciidoc: Update .pot template
  Asciidoc: Fix artifacts from initial import, fifth attempt
  Asciidoc: Fix artifacts from initial import, fourth attempt
  Asciidoc: Update .pot template
  Asciidoc: Fix artifacts from initial import, third attempt
  Asciidoc: Fix artifacts from initial import, second attempt
  Asciidoc: Fix artifacts from initial import
  Asciidoc: Add po4a config file and initial translation template for man pages
  Asciidoc: Small indentation fix in mount.8.adoc
  Asciidoc: Review sys-utils man pages, part 2
  build-sys: fix out-of-tree build
  ...

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-29 15:09:27 +02:00
Karel Zak 4f79d3032e build-sys: split man pages and man page links
The symlinks are generated by asciidoctor and current dist_man_MANS
depends on order (nan page before man link). This solutions is useless
when execute "make -j". The real solution is to keep man pages in
separate variable and use only this variable evaluate what we need to
generate.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-26 11:49:59 +01:00
Mario Blättermann ea81716d0c Asciidoc: Review terminal-colors.d.5.adoc 2021-03-24 17:37:34 +01:00
Mario Blättermann 295b3979d9 Asciidoc: Add Po4a hint to file headers 2021-03-20 16:42:47 +01:00
Mario Blättermann 4d29743519 Asciidoc: Some formatting cleanup in man pages 2021-03-19 18:25:50 +01:00
Karel Zak 308a097968 meson: update sources and dependencies
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-17 15:07:27 +01:00
Zbigniew Jędrzejewski-Szmek d4c880d5a4 meson: add second build system
To build: meson build && ninja -C build
To run tests: ninja -C build check
To install for packaging: DESTDIR=/var/tmp/inst ninja -C build install
To install for realz: sudo ninja -C build install

v2:
- Optional items are now based on the 'feature' feature in meson.
  Built libraries which are disabled turn into disabler() objects
  and also poison any executables which link to them.

What is there:
- building of the binaries and libs and the python module
- installation of binaries, libs, python module, localization files,
  man pages, pkgconfig files
- running of tests
- most options to configure build equivalently to the
  ./configure settings

Partially implemented:
- disabling of stuff when things missing. In the C code, the defines
  are all used, so that should be fine. In the build system, some
  files should be skipped, but that is probably not always done properly.
  Getting this right might require some testing of various build option
  combinations to get the details right.

Not implemented:
- static builds of fdisk and other binaries
- things marked with XXX or FIXME
- ???

Differences:
- .la files are not created. They are useless and everybody hates them.
- Requires.private in pkgconfig files are not present in the
  autogenerated .pc file. Not sure if they should be there or not. If
  necessary, they can be added by hand.
- man pages and systemd units are installed by the install target. Not
  sure why 'make install' doesn't do that.
- the split between / and /usr is probably wrong. But it's all pointless
  anyway, so maybe we could simplify things but not implementing it at
  all under meson?
2021-03-17 15:07:27 +01:00
Mario Blättermann b366e6fc6b Asciidoc: Remove already imported *roff man pages 2021-03-16 19:35:37 +01:00
Luca Boccassi c65953d72b Automake: use EXTRA_LTLIBRARIES instead of noinst_LTLIBRARIES
noinst_LTLIBRARIES causes the libraries to be always built
unconditionally. EXTRA_LTLIBRARIES causes them to be built
only if other build target needs them.
In other words, avoid building libcommon.a and libtcolors.a
unless they are needed by another library/executable and
save some build time.

https://www.gnu.org/software/automake/manual/html_node/Libtool-Convenience-Libraries.html
2021-03-15 12:17:31 +00:00
Mario Blättermann e2db4d9410 Add asciidoc man pages and some include files 2021-03-11 18:38:46 +01:00
Karel Zak 17d5b26436 su: (pty) change owner and mode for pty
The current situation:

 # su --pty - kzak
 $ ll $(tty)
 crw--w---- 1 root tty 136, 9 Feb 23 11:53 /dev/pts/9
 $ mesg
 mesg: cannot open /dev/pts/9: Permission denied

the pseudo-terminal is still owned by the original user.

New version:

 # su --pty - kzak
 # ll $(tty)
 crw--w---- 1 kzak tty 136, 9 Feb 23 11:56 /dev/pts/9
 # mesg
 is y

The patch follows login(1) to change the pty owner and group. It
follows "TTYPERM" and "TTYGROUP" from login.defs (or econf lib).

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-23 11:52:45 +01:00
Karel Zak 27e6b3a92e lib/strutils: add ul_stralnumcmp()
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-23 09:19:48 +01:00
Karel Zak 71ba2792ab lib: use procutils.c on Linux only
Fixes: https://github.com/karelzak/util-linux/issues/1251
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-17 12:24:13 +01:00
Karel Zak 867df2617c lib: use ul_prefix for close_all_fds() and mkdir_p()
The names are too generic and it makes problems in static libraries.

Addresses: https://gitlab.com/cryptsetup/cryptsetup/-/issues/623
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-28 10:27:21 +01:00
Karel Zak 0735d0efe1 lib/selinux-utils: tiny cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 15:04:02 +01:00
Karel Zak b105446e69 mkswap: remove deprecated SELinux matchpathcon()
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 14:58:43 +01:00
Karel Zak e1de70b3c3 chfs-chfn: remove deprecated selinux_check_passwd_access()
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 14:27:15 +01:00
Karel Zak b5debf7105 lib/selinux-utils: cleanup function names
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 13:33:41 +01:00
Karel Zak 68f4aa2a2f build-sys: move selinux_utils.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 13:30:31 +01:00
Karel Zak fbc2fe824d lib/loopdev: make is_loopdev() more robust
It seems the current kernel can create a loop devices with a different
major number. For example

  # losetup /dev/loop12345678 file.img
  # lsblk /dev/loop12345678
  NAME          MAJ:MIN    RM SIZE RO TYPE MOUNTPOINT
  loop12345678   15:811342  0   5M  0 loop

We need a way how to verify the device is loopdev also when the device is
not associated with any backing file -- in this case there is no "loop"
directory in /sys/dev/block/<maj:min>/, but we can cannonicalize this sysfs
symlink as it points to /sys/devices/virtual/block/loop<n> (see "loop" in
the path).

Note that without this change losetup is not able to list and delete
the loop device.

Addresses: https://github.com/karelzak/util-linux/issues/1202
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-12 11:43:31 +01:00
Karel Zak 3c7355dd63 libsmartcols: support arrays for JSON output
This patch add support to format multi-line cells (columns with
SCOLS_FL_WRAP) to arrays in JSON output.

For example mountpoints[] in lsblk output:

Normal output:
	 $ lsblk -oNAME,FSTYPE,TYPE,MOUNTPOINTS /dev/sdc1
	 NAME FSTYPE TYPE MOUNTPOINTS
	 sdc1 btrfs  part /mnt/A
			  /mnt/test
			  /mnt/B

JSON output:
	$ lsblk -J -oNAME,FSTYPE,TYPE,MOUNTPOINTS /dev/sdc1
	{
	   "blockdevices": [
	      {
		 "name": "sdc1",
		 "fstype": "btrfs",
		 "type": "part",
		 "mountpoints": [
		     "/mnt/A",
		     "/mnt/test",
		     "/mnt/B"
		 ]
	      }
	   ]
	}

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-08 13:12:57 +01:00
Karel Zak 7ed579523b lib: fix compiler warnings [-Wmaybe-uninitialized]
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-17 11:07:38 +01:00
Karel Zak 2a2b7da131 tests: (fileutils) remove unused code
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-08 13:09:10 +01:00
Sami Kerola a75700d86e
lib/fileutils: make close_all_fds() to be similar with close_range()
The util-linux close_all_fds() serves the same purpose as close_range()
that will over time obsolete local implementation completely.  For
upcoming few years it is best to have a fallback that uses same input
arguments as the new system call.  That allows surrounding code and
variables not to be affected by version of mass file descriptor closing
function.

Proposed-by: Karel Zak <kzak@redhat.com>
Reference: https://github.com/karelzak/util-linux/pull/1205#discussion_r534080128
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:09:14 +00:00
Karel Zak 57b74b0dcb Merge branch 'w45'
* w45:
  fdformat: remove command from default build
  more: improve error messaging when input file is directory
  ul: make set_column() zero check more obvious
  colrm: fix argument parsing
  rfkill: stop execution when rfkill device cannot be opened
  cifuzz: reindent yaml file
  man: make tilde and caret characters to render correctly
2020-11-20 12:01:22 +01:00
Karel Zak 966420219c lib/caputils: split to multiple functions, add test
Let's split the code to make it possible to test separately bsearch as
well as procfs based cap_last_cap().

 $ ./test_caputils --last-by-bsearch
 last cap: 39
 $ ./test_caputils --last-by-procfs
 last cap: 39
 $ ./test_caputils --last
 last cap: 39

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-20 11:21:41 +01:00
Karel Zak 1b54a74e86 lib/procutils: improve proc_is_procfs(), add test
* add delay between attempts
* zeroize errno and check for EAGAIN (like in other code)
* add small test program
   ./test_procutils --is-procfs [<dir>]

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-20 10:40:31 +01:00
Karel Zak 61dc5ae39a Merge branch 'caps' of https://github.com/ericonr/util-linux
* 'caps' of https://github.com/ericonr/util-linux:
  lib/caputils: add fall back for last cap using prctl.
  lib/procutils: add proc_is_procfs helper.
2020-11-20 10:21:19 +01:00