Compare commits

..

326 commits

Author SHA1 Message Date
Karel Zak
689c03b416 Merge branch 'enosys/locale' of https://github.com/t-8ch/util-linux
Some checks failed
CIFuzz / Fuzzing (i386, address) (push) Has been cancelled
CIFuzz / Fuzzing (x86_64, address) (push) Has been cancelled
CIFuzz / Fuzzing (x86_64, memory) (push) Has been cancelled
CIFuzz / Fuzzing (x86_64, undefined) (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
2023-07-03 12:52:38 +02:00
Karel Zak
6462dbe2ef Merge branch 'clock' of https://github.com/t-8ch/util-linux
* 'clock' of https://github.com/t-8ch/util-linux:
  lsclocks: new util to interact with system clocks
  lib/timeutils: implement timespec formatting
  lib/timeutils: implement nanosecond formatting
  lib/timeutils: constify some arguments
  utmpdump: validate subsecond granularity
2023-07-03 12:47:08 +02:00
Karel Zak
96de80b659 Merge branch 'lsfd--xmode' of https://github.com/masatake/util-linux
* 'lsfd--xmode' of https://github.com/masatake/util-linux:
  lsfd: add 'D' flag for representing deleted files to XMODE column
  lsfd: introduce XMODE column, extensible variant of MODE
  test: (lsfd) add a subcase for testing NAME column for a deleted file
  test: (lsfd) add a case for testing DELETED column
  test: (mkfds) add "make-regular-file" factory
2023-07-03 12:41:04 +02:00
Karel Zak
3e2e4c32e8 Merge branch 'lsfd--misc-tun' of https://github.com/masatake/util-linux
* 'lsfd--misc-tun' of https://github.com/masatake/util-linux:
  tests: (lsfd) add a case testing TUN.IFACE column
  tests: (mkfds) add a factor for opening tun device
  lsfd: add TUN.IFFACE, a column for interfaces behind tun devices
  lsfd: (refactor) move miscdev specific code to cdev_misc_ops
  lsfd: (refactor) make the way to handle character devices extensible
  lsfd: (refactor) introduce a content data type for char devices
2023-07-03 12:38:48 +02:00
Karel Zak
c8e36ed4db Merge branch 'patch-1' of https://github.com/diizzyy/util-linux
* 'patch-1' of https://github.com/diizzyy/util-linux:
  include/bitops.h: Remove bswap* compatibility hack for FreeBSD
2023-07-03 12:36:07 +02:00
Karel Zak
452801e4f6 Merge branch 'wip/rishi/libmount-src-hook-mount-move_setattr-typo' of https://github.com/debarshiray/util-linux
* 'wip/rishi/libmount-src-hook-mount-move_setattr-typo' of https://github.com/debarshiray/util-linux:
  libmount: fix typo
2023-07-03 12:32:42 +02:00
Karel Zak
5098291b2c Merge branch 'wip/rishi/libmount-src-libmount.h-MNT_ERR_APPLYFLAGS-docs' of https://github.com/debarshiray/util-linux
* 'wip/rishi/libmount-src-libmount.h-MNT_ERR_APPLYFLAGS-docs' of https://github.com/debarshiray/util-linux:
  libmount: update documentation for MNT_ERR_APPLYFLAGS
2023-07-03 12:30:43 +02:00
Karel Zak
85c9a0af07 Merge branch 'unshare/negative-time-offset' of https://github.com/t-8ch/util-linux
* 'unshare/negative-time-offset' of https://github.com/t-8ch/util-linux:
  unshare: allow negative time offsets
2023-07-03 12:28:54 +02:00
Thomas Weißschuh
95e853892f unshare: allow negative time offsets
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-30 22:36:06 +02:00
Thomas Weißschuh
e9ddea7912 lsclocks: new util to interact with system clocks
Usecases:
* Compare current monotonic time to timestamps reported by systemd
* Validate time namespace operations
* Inspect clock resolutions

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-30 14:12:48 +02:00
Jakub Wilk
a753fb6520 prlimit: reject trailing junk in limits without ":"
Before:

    $ prlimit --verbose --core=1x
    New CORE limit for pid 42: <1:1>

After:

    $ prlimit --verbose --core=1x
    prlimit: failed to parse CORE limit

Signed-off-by: Jakub Wilk <jwilk@jwilk.net>
2023-06-29 20:13:01 +02:00
Debarshi Ray
5a17b1b626 libmount: update documentation for MNT_ERR_APPLYFLAGS
The implementation using the new FD based mount kernel API (ie.,
fsconfig/fsopen) uses MNT_ERR_APPLYFLAGS for failed mount_setattr(2)
calls, which involves more mount attributes (eg., MOUNT_ATTR_RDONLY,
MOUNT_ATTR_NOSUID, etc.) in addition to the MS_PROPAGATION flags (eg.,
MS_SHARED, MS_UNBINDABLE, etc.).

Note that mount_setattr(2) is part of the new FD based mount kernel API,
and is not used by the classic mount(2) based version.

Fallout from 987d844cdb

Signed-off-by: Debarshi Ray <rishi@fedoraproject.org>
2023-06-29 13:29:01 +02:00
Debarshi Ray
46fe78989d libmount: fix typo
Similar to e80f8e4612 and fallout from
6753e6f691

Signed-off-by: Debarshi Ray <rishi@fedoraproject.org>
2023-06-29 12:26:29 +02:00
Thomas Weißschuh
b9abaae312 lib/timeutils: implement timespec formatting
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-28 14:58:32 +02:00
Thomas Weißschuh
136f4874f4 lib/timeutils: implement nanosecond formatting
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-28 14:58:06 +02:00
Thomas Weißschuh
971244fdc7 lib/timeutils: constify some arguments
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-28 14:57:33 +02:00
Thomas Weißschuh
a8d0195462 utmpdump: validate subsecond granularity
tv_usec is only valid in the range [0, 999999].
If the file contains garbage data replace interpret it as "0" instead.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-28 14:50:49 +02:00
Karel Zak
2b48beb44e include/crc64: add missing license header
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-28 12:41:08 +02:00
Karel Zak
32c7870520 nsenter: avoid NULL pointer dereference [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-28 10:19:34 +02:00
Thomas Weißschuh
d191a7bef8 enosys: enable locale handling
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-27 12:45:37 +02:00
Karel Zak
65c4be5fc2 Merge branch 'cal' of https://github.com/jwilk-forks/util-linux
* 'cal' of https://github.com/jwilk-forks/util-linux:
  cal: fix long option name for -c
  cal: fix error message for bad -c argument
2023-06-27 10:29:59 +02:00
Masatake YAMATO
0cac072b64 tests: (lsfd) add a case testing TUN.IFACE column
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-27 08:28:06 +09:00
Jakub Wilk
618dd71be4 cal: fix long option name for -c 2023-06-26 21:02:13 +02:00
Jakub Wilk
0fb52dabba cal: fix error message for bad -c argument 2023-06-26 21:00:26 +02:00
Jakub Wilk
b1fc5d61f0 lib/strutils: fix typo 2023-06-26 20:00:43 +02:00
Daniel Engberg
214e668c84
include/bitops.h: Remove bswap* compatibility hack for FreeBSD
This is no longer needed on supported versions of FreeBSD and causes build failures
2023-06-26 19:22:16 +02:00
Masatake YAMATO
369007a5b7 tests: (mkfds) add a factor for opening tun device
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-27 01:21:42 +09:00
Masatake YAMATO
7cbec02a47 lsfd: add TUN.IFFACE, a column for interfaces behind tun devices
An example output:

  # ./lsfd -Q '(SOURCE == "misc:tun")'  -o+TUN.IFACE
  COMMAND             PID       USER ASSOC MODE TYPE   SOURCE MNTID INODE NAME          TUN.IFACE
  qemu-system-x86 2846033       qemu    48  rw-  CHR misc:tun    23   306 iface=vnet89     vnet89
  qemu-system-x86 2865022       qemu    56  rw-  CHR misc:tun    23   306 iface=vnet103   vnet103
  openvpn         3113730 nm-openvpn     7  rw-  CHR misc:tun   588   306 iface=tun0         tun0
  qemu-system-x86 3608136       qemu    36  rw-  CHR misc:tun    23   306 iface=vnet104   vnet104
  qemu-system-x86 3608136       qemu    39  rw-  CHR misc:tun    23   306 iface=vnet105   vnet105
  qemu-system-x86 3608238       qemu    40  rw-  CHR misc:tun    23   306 iface=vnet106   vnet106
  qemu-system-x86 3608238       qemu    43  rw-  CHR misc:tun    23   306 iface=vnet107   vnet107
  qemu-system-x86 3608338       qemu    54  rw-  CHR misc:tun    23   306 iface=vnet108   vnet108
  qemu-system-x86 3608338       qemu    60  rw-  CHR misc:tun    23   306 iface=vnet109   vnet109

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-27 01:21:42 +09:00
Masatake YAMATO
fb978312aa lsfd: (refactor) move miscdev specific code to cdev_misc_ops
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-27 01:21:42 +09:00
Masatake YAMATO
8aa5b7c9d0 lsfd: (refactor) make the way to handle character devices extensible
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-27 01:21:42 +09:00
Masatake YAMATO
1225e6d0fb lsfd: (refactor) introduce a content data type for char devices
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-27 01:21:42 +09:00
Karel Zak
fb062800be Merge branch 'nsenter-add-parent-ns-option' of https://github.com/igo95862/util-linux
* 'nsenter-add-parent-ns-option' of https://github.com/igo95862/util-linux:
  Add `--user-parent` option to nsenter
2023-06-26 14:04:52 +02:00
Karel Zak
b0d4d09379 cfdisk: fix menu behavior after writing changes
Florian wrote:
  after a successful write, cfdisk remains on the "Write" cursor and
  furthermore when navigating to "Quit" will continue to  show
  "...without writing changes", despite there were writes. This patch
  addresses that.

Based on patch from Florian Zimmermann <florian.zimmermann@gmail.com>

Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-26 13:27:11 +02:00
Edward Chron
fa6ac102dc dmesg: -r LOG_MAKEPRI needs fac << 3
Submission to Project: util-linux
Open Incident: #2325 at github.com/util-linux/util-linux/issues/2325
Component: util-linux/sys-utils
File: dmesg.c
Code level patch applied against: 2.39 - latest code pulled from
           git.github.com:util-linux/util-linux.git

BUG: The facility field passed to macro from /usr/include/sys/syslog.h
     LOG_MAKEPRI(fac, pri) by dmesg -r needs to have fac argument
     shifted 3 bit to the left to return a valid raw valid. The lower
     3 bits for a raw value are used by the loglevel priority (pri)
     field, so the facility bits can only occupy the bits above the
     bits used to hold the pri field value.

The dmesg -r command produces the incorrect output for the raw value
for the or'ed combination of the facility | loglevel priority that gets
produced by the LOG_MAKEPRI macro. That macro is defined as:

    #define LOG_MAKEPRI(fac, pri) ((fac) | (pri))

which is defined in the current glibc code in /usr/include/sys/syslog.h
and is used only in the dmesg -r (raw output option) command to form the
raw value for facility or'ed with loglevel priority and displayed as:

    <#>[#######.######] ...

where the # in <#> contains the output from the LOG_MAKEPRI macro.

The lower 3 bits are reserved for the loglevel priority 0-7
and the bits above that are for the facility value, so the facility
index should be shifted to the left three bits and or'ed with the
loglevel priority.

In the glibc file: /usr/include/sys/syslog.h the macro LOG_MAKEPRI is
defined as:

        #define LOG_MAKEPRI(fac, pri) ((fac) | (pri)

and returns the wrong facility and loglevel priority values, ideally it
should be defined as:

        #define LOG_MAKEPRI(fac, pri) ((fac << 3) | (pri))

to return the correct raw value.

We checked with glibc developement and the LOG_MAKEPRI macro is correct
as is and can't be changed as it used by *BSD as is so the solution for
dmesg -r is to shift the facility index left by 3 bits as input to the
LOG_MAKEPRI macro. That is what glibc development recommended.
(For reference, see glibc bugzilla Bug 30563)

We can front end the LOG_MAKEPRI macro with a macro that shifts the
facility by the needed 3 bits which we've added to dmesg.c:

    #define LOG_RAW_FAC_PRI(fac, pri) LOG_MAKEPRI((fac << 3), (pri))

This has been tested and works correctly to produce the correct raw
mode value for Facility or'ed together with Loglevel priority.

You can verify that this fix works correctly.

We can test by adding several records to /dev/kmsg like this:

    echo "<14> Test Message Facility 8 Loglevel 6" >> /dev/kmsg
    echo "<15> Test Message Facility 8 Loglevel 7" >> /dev/kmsg
    echo "<30> Test Message Facility 24 Loglevel 6" >> /dev/kmsg
    echo "<31> Test Message Facility 24 Loglevel 7" >> /dev/kmsg

these commands add 4 records to the dmesg buffer. Then when we print the
records by cat'ing /dev/kmsg or using the dmesg command several ways:

    -bash-4.2# cat /dev/kmsg | grep "Test Message Facility"
    14,1114,495317239,-; Test Message Facility 8 Loglevel 6
    15,1115,503340779,-; Test Message Facility 8 Loglevel 7
    30,1116,643374764,-; Test Message Facility 24 Loglevel 6
    31,1117,657165117,-; Test Message Facility 24 Loglevel 7

    -bash-4.2# dmesg -x | grep "Test Message Facility"
    user  :info  : [  495.317239]  Test Message Facility 8 Loglevel 6
    user  :debug : [  503.340779]  Test Message Facility 8 Loglevel 7
    daemon:info  : [  643.374764]  Test Message Facility 24 Loglevel 6
    daemon:debug : [  657.165117]  Test Message Facility 24 Loglevel 7

    -bash-4.2# dmesg -S -x | grep "Test Message Facility"
    user  :info  : [  495.317239]  Test Message Facility 8 Loglevel 6
    user  :debug : [  503.340779]  Test Message Facility 8 Loglevel 7
    daemon:info  : [  643.374764]  Test Message Facility 24 Loglevel 6
    daemon:debug : [  657.165117]  Test Message Facility 24 Loglevel 7

   -bash-4.2# dmesg -S -r | grep "Test Message Facility"
   <14>[  495.317239]  Test Message Facility 8 Loglevel 6
   <15>[  503.340779]  Test Message Facility 8 Loglevel 7
   <30>[  643.374764]  Test Message Facility 24 Loglevel 6
   <31>[  657.165117]  Test Message Facility 24 Loglevel 7

All the above methods agree in their output as expected.
However, running dmesg -r does not agree.

dmesg -r erronously produces:
----------------------------

    -bash-4.2# dmesg -r | grep "Test Message Facility"
    <7>[  495.317239]  Test Message Facility 8 Loglevel 6
    <7>[  503.340779]  Test Message Facility 8 Loglevel 7
    <7>[  643.374764]  Test Message Facility 24 Loglevel 6
    <7>[  657.165117]  Test Message Facility 24 Loglevel 7

However, if we run the dmesg -r command using the new front end macro
LOG_RAW_FAC_PRI(fac, pri) we do get the correct output:

Here is the corrected dmesg -r output:
-------------------------------------

    -bash-4.2# dmesg -r | grep "Test Message Facility"
    <14>[  495.317239]  Test Message Facility 8 Loglevel 6
    <15>[  503.340779]  Test Message Facility 8 Loglevel 7
    <30>[  643.374764]  Test Message Facility 24 Loglevel 6
    <31>[  657.165117]  Test Message Facility 24 Loglevel 7

shifting the facility index value by 3 bits in the LOG_RAW_FAC_PRI macro
provides the correct ouput as shown. All the other commands produce the
same output so now they are all in agreement.

Signed-off-by: Ivan Delalande <colona@arista.com>
Signed-off-by: Edward Chron <echron@arista.com>
2023-06-26 13:27:02 +02:00
Karel Zak
08b35072b9 build-sys: don't call pkg-config --static if unnecessary
Addresses: https://github.com/util-linux/util-linux/issues/2327
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-26 12:48:30 +02:00
Karel Zak
3a4d70419c logger: initialize socket credentials contol union
Addresses: https://github.com/util-linux/util-linux/issues/2336
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-26 11:56:23 +02:00
Karel Zak
0904cff4a5 Merge branch 'unshare/time-msg' of https://github.com/t-8ch/util-linux
* 'unshare/time-msg' of https://github.com/t-8ch/util-linux:
  unshare: fix error message for unexpected time offsets
2023-06-26 11:50:02 +02:00
Karel Zak
ceb13fa9e8 Merge branch 'test/builddir-pwd' of https://github.com/t-8ch/util-linux
* 'test/builddir-pwd' of https://github.com/t-8ch/util-linux:
  tests: (run.sh) detect builddir from working directory
2023-06-26 11:49:43 +02:00
Karel Zak
55b0cc7106 Merge branch 'losetup-errormsg' of https://github.com/t-8ch/util-linux
* 'losetup-errormsg' of https://github.com/t-8ch/util-linux:
  losetup: deduplicate find_unused() logic
  lib/loopdev: consistently return error values from loopcxt_find_unused()
  lib/loopdev: document function return values
2023-06-26 11:49:20 +02:00
Karel Zak
69e7e599c0 Merge branch 'hardlink' of https://github.com/jwilk-forks/util-linux
* 'hardlink' of https://github.com/jwilk-forks/util-linux:
  hardlink: (man) add missing comma
2023-06-26 11:48:43 +02:00
Karel Zak
c0ac6d590a Merge branch 'lsfd--fix-separators-for-json-output-cleanup' of https://github.com/masatake/util-linux
* 'lsfd--fix-separators-for-json-output-cleanup' of https://github.com/masatake/util-linux:
  lsfd: fix specifying wrong JSON typs when building the help message
  tests: (lsfd) add a case for verifying ENDPOINTS column output in JSON mode
2023-06-26 11:48:24 +02:00
Karel Zak
c985e0742e Merge branch 'PR/libmount-optstr-sync' of github.com:karelzak/util-linux-work
* 'PR/libmount-optstr-sync' of github.com:karelzak/util-linux-work:
  libmount: add sample to test fs and context relation
  libmount: fix sync options between context and fs structs
2023-06-26 11:45:50 +02:00
Thomas Weißschuh
2da0200327 unshare: fix error message for unexpected time offsets
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-25 13:28:19 +02:00
Thomas Weißschuh
af9fc22d03 losetup: deduplicate find_unused() logic
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-25 10:06:21 +02:00
Thomas Weißschuh
3c5402640d lib/loopdev: consistently return error values from loopcxt_find_unused()
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-25 10:06:21 +02:00
Thomas Weißschuh
af5efcd810 lib/loopdev: document function return values
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-25 10:04:39 +02:00
Thomas Weißschuh
dc1d0f8dd1 tests: (run.sh) detect builddir from working directory
This makes it easier to run test.sh from the build directory as
everything will work without any parameters irrespective of the build
directories name.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-25 09:06:47 +02:00
Jakub Wilk
4bcc2ed30d hardlink: (man) add missing comma 2023-06-24 09:24:29 +02:00
igo95862
01a6d803b5
Add --user-parent option to nsenter
When this option is used nsenter will fetch the parent user
namespace from any namespace file descriptors available.

It can be combined with existing `--user` option in which case
the parent user namespace will be fetched from the user namespace
and replace it.

The usecase of this option is when a user namespace that owns
the other type namespaces we want to switch to is not actually
bound to any process. Without using ioctl it is impossible to
acquire namespace file descriptor. For example, bubblewrap
`bwrap` command creates unbinded user namespace when `--dev`
option is used.
2023-06-23 00:26:13 +06:00
Masatake YAMATO
253c991da1 lsfd: fix specifying wrong JSON typs when building the help message
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-23 01:10:04 +09:00
Masatake YAMATO
ee72ea94c5 tests: (lsfd) add a case for verifying ENDPOINTS column output in JSON mode
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-23 01:07:04 +09:00
Karel Zak
ae62db7250 Merge branch 'lsfd--fix-separators-for-json-output' of https://github.com/masatake/util-linux
* 'lsfd--fix-separators-for-json-output' of https://github.com/masatake/util-linux:
  lsfd.1.adoc: fix a typo
  lsfd: use ARRAY_STRING and ARRAY_NUMBER json types in some columns
  lsfd: use \n as the separator in INOTIFY.INODES and INOTIFY.INODES.RAW columns
  lsfd: use \n as the separator in EVENTPOLL.TFDS column
  lsfd: (filter) weakly support ARRAY_STRING and ARRAY_NUMBER json types
2023-06-22 14:26:09 +02:00
Karel Zak
6a28c2f90a Merge branch 'coverage-tweaks' of https://github.com/mrc0mmand/util-linux
* 'coverage-tweaks' of https://github.com/mrc0mmand/util-linux:
  ci: collect coverage on _exit() as well
  ci: hide coverage-related stuff begind --enable-coverage
  ci: tweak build dir's ACL when collecting coverage
  ci: fix indentation
2023-06-22 14:19:07 +02:00
Karel Zak
7111160934 Merge branch 'cancel-jobs-on-push' of https://github.com/mrc0mmand/util-linux
* 'cancel-jobs-on-push' of https://github.com/mrc0mmand/util-linux:
  ci: cancel running jobs on push
2023-06-22 14:15:46 +02:00
Karel Zak
cd8f11b7cb libmount: add sample to test fs and context relation
Reerences: https://github.com/util-linux/util-linux/issues/2326
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-22 14:00:46 +02:00
Karel Zak
7b37d5b566 libmount: fix sync options between context and fs structs
Since v2.39 libmount prefers "struct libmnt_optlist" to keep mount options
rather than the original "struct libmnt_fs". This is problem if the
"fs" struct is defined and maintained outside the context.

The library has already a way how to sync "fs" and "optlist", but this
needs to be improved and used more widely. Changes:

* force "fs" from context to always read options from "optlist"

* copy options from "fs" to "optlist" in mnt_context_set_fs()

* internally redirect mnt_fs_* API for options to "optlist" if optlist
  defined

* add simple test to make sure options from different sources are
  always merged together

Addresses: https://github.com/util-linux/util-linux/issues/2326
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-22 13:11:57 +02:00
Frantisek Sumsal
2235cf919a ci: cancel running jobs on push
Let's cancel already running GH Actions jobs when a PR is (force) pushed
to conserve resources and make the CI runs faster thanks to the freed up
queue.
2023-06-22 12:38:53 +02:00
Frantisek Sumsal
b0d003023c ci: collect coverage on _exit() as well
_exit() skips the gcov hooks, so we lose all coverage collected up to
that point. Let's work around this by intercepting _exit() with our
wrapper that calls __gcov_dump() just before _exit().
2023-06-22 12:03:04 +02:00
Frantisek Sumsal
b4b8f8c293 ci: hide coverage-related stuff begind --enable-coverage 2023-06-22 12:03:04 +02:00
Frantisek Sumsal
f5b49efe42 ci: tweak build dir's ACL when collecting coverage
So gcov can create necessary directories/.gcda files even with dropped
privileges.
2023-06-22 12:03:04 +02:00
Rasmus Villemoes
ab7fe95ad7 hwclock: add --vl-read, --vl-clear documentation and bash-completion
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2023-06-22 10:27:36 +02:00
Rasmus Villemoes
76cf1753f4 hwclock: add support for RTC_VL_READ/RTC_VL_CLR ioctls
Implement a way for userspace to query the status of the backup
battery, if supported by the hardware and driver.

The RTC_VL_* bits are a somewhat recent addition (3431ca4837bf, but
really only from b0efe0281234) to the uapi header,
so provide our own definition if the build host's header doesn't.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2023-06-22 10:27:36 +02:00
Masatake YAMATO
14fee76fc1 lsfd.1.adoc: fix a typo
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-22 15:07:49 +09:00
Masatake YAMATO
42497e7d92 lsfd: use ARRAY_STRING and ARRAY_NUMBER json types in some columns
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-22 14:53:41 +09:00
Masatake YAMATO
c34f86326d lsfd: use \n as the separator in INOTIFY.INODES and INOTIFY.INODES.RAW columns
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-22 14:29:08 +09:00
Masatake YAMATO
92e0e017d8 lsfd: use \n as the separator in EVENTPOLL.TFDS column
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-22 14:29:08 +09:00
Masatake YAMATO
de7e11495b lsfd: (filter) weakly support ARRAY_STRING and ARRAY_NUMBER json types
We will have operators for array types in the future.  Till having
them, we treat the types as STRING. So we can use string operators for
the column having types.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-22 14:29:08 +09:00
Masatake YAMATO
30ac13fa20 lsfd: add 'D' flag for representing deleted files to XMODE column
Now NAME column doesn't print "(deleted)" markers at the end of
file name.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-22 09:01:13 +09:00
Masatake YAMATO
92c00d7215 lsfd: introduce XMODE column, extensible variant of MODE
The original MODE column comes from three letters (rwx) may not be
enough for representing various aspects of file descriptors and memory
mappings. We want to add more items in the future.

However, the description of MODE in lsfd(1) doesn't wrote about its
extensibility. Adding more letters to the column can break
compatibility in someone's use case.

This change introduces XMODE column. Unlike MODE, XMODE is declared as
an extensible column in lsfd(1). Currently, it shows the same items as
the MODE column does.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-22 09:01:13 +09:00
Masatake YAMATO
cb233a3e03 test: (lsfd) add a subcase for testing NAME column for a deleted file
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-22 09:01:13 +09:00
Masatake YAMATO
9ac2c69dbd test: (lsfd) add a case for testing DELETED column
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-22 09:01:13 +09:00
Masatake YAMATO
251319838d test: (mkfds) add "make-regular-file" factory
With "delete" boolean parameter, you can delete the file just
after making it.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-22 09:01:13 +09:00
Karel Zak
60c81b3272 sfdisk: add hint about duplicate UUIDs when use dump
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-21 10:57:37 +02:00
Frantisek Sumsal
4d34493450 ci: fix indentation 2023-06-20 16:19:42 +02:00
Karel Zak
33e347832e lib: remove pager.c from libcommon
The libcommon is a binary archive to keep compilation and maintenance
simple. The library is not linked as shared or so. The unused symbols
are removed from binaries (for example, by "make install-strip").

But it isn't evident for license analyzers (and some humans) that the
library uses GPL and non-GPL stuff simultaneously. Let's avoid doubts
and keep pager.c (with GPL license) out of the archive

Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-20 13:15:45 +02:00
Karel Zak
79feaa6022 lib/ include/: cleanup licence headers
This patch does not change any license of the affected files. Changes:

* add missing SPDX-License-Identifier lines for LGPL

* copy missing license lines from code (lib/) to header files (include/)

* use the same comment formatting

Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-20 12:52:35 +02:00
Karel Zak
278f76ae88 lib/color-names: fix licence header
The header file and code uses a different license. Let's use (public
domain) license from code also for the header file.

Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-20 12:51:05 +02:00
Todd Zullinger
7293d66314 sys-utils: fix SELinux context example in mount.8
In the description of the context option, the example which shows how to
properly quote is displayed incorrectly on terminals > 80 columns.  This
leaves a seemingly needless '\' in the command, e.g.:

    mount -t tmpfs none /mnt -o \ 'context="system_u:...'

The intent is to display the command properly on terminals <= 80
columns.  Use a literal block to ensure the code is displayed
consistently, regardless of the terminal width.

Connect the blockquote to the previous indented items in the context
option description to ensure it is properly indented.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
2023-06-20 11:27:07 +02:00
Karel Zak
d7f1fc1839 tests: add omitted files
Sorry, forgot in the previous commit ...

Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-19 14:59:15 +02:00
Karel Zak
b11005d90f tests: add user and user=name mount test
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-19 13:45:06 +02:00
Karel Zak
a96b486d17 libmount: always ignore user=<name>
The library (on mount) cares about "user", but has to ignore
"user=name". It works as expected, but only for non-root users. We
need to ignore it also root to be compatible with /sbin/mount.cifs
where some people still use "user=" (rather than "username=").

References: fe0b1e793c
Addresses: https://github.com/util-linux/util-linux/issues/2315
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-19 13:29:42 +02:00
Karel Zak
640e93f480
Merge pull request #2317 from eworm-de/meson-langinfo
meson: check for _NL_TIME_WEEK_1STDAY in langinfo.h
2023-06-17 11:56:48 +02:00
Karel Zak
cd256c9f22
Merge pull request #2318 from mariobl/patch-11
[man] Fix typo in irqtop.1.adoc
2023-06-17 11:52:11 +02:00
Mario Blättermann
123ba32ae7
[man] Fix typo in irqtop.1.adoc 2023-06-16 16:31:47 +02:00
Christian Hesse
17bc58e018 meson: check for _NL_TIME_WEEK_1STDAY in langinfo.h
... which is required for `cal`.

Fixes GH-2316
2023-06-16 11:53:20 +02:00
Karel Zak
44806f659f Merge branch 'ci/gcc-13' of https://github.com/t-8ch/util-linux
* 'ci/gcc-13' of https://github.com/t-8ch/util-linux:
  ci: use clang 16
  ci: build with GCC 13/11
2023-06-14 09:54:25 +02:00
Karel Zak
b9040ac267 Merge branch 'lsfd--inotify' of https://github.com/masatake/util-linux
* 'lsfd--inotify' of https://github.com/masatake/util-linux:
  lsfd: use xstrdup instead of xasprintf(...\"%s\"
  tests: (lsfd) add a case for testing INOTIFY.INODES.RAW column
  tests: (mkfds) add / and /etc/fstab as the monitoring targets to inotify
  lsfd: fill NAME column of inotify files with the information about their monitoring targets
  lsdf: make the code for filling SOURCE, PARTITION, and MAJMIN reusable
2023-06-14 09:53:04 +02:00
Karel Zak
07e7d1c781 Merge branch 'meson-more-conditions' of https://github.com/keszybz/util-linux
* 'meson-more-conditions' of https://github.com/keszybz/util-linux:
  meson: conditionalize waitpid
  meson: add conditionalization for test progs
  meson: implement HAVE_PTY
2023-06-14 09:51:12 +02:00
Zbigniew Jędrzejewski-Szmek
334939a19d meson: conditionalize waitpid
I *think* this mirros what configure.ac does, except that the configuration
option is not implemented.
2023-06-13 21:12:00 +02:00
Zbigniew Jędrzejewski-Szmek
d6418774ab meson: add conditionalization for test progs
This just mirrors what the autotools setup is doing.
2023-06-13 21:12:00 +02:00
Zbigniew Jędrzejewski-Szmek
444753601c meson: implement HAVE_PTY
This conditional was never implemented in the meson config. Under
autotools, it is guarded by availability of headers and an option. I
didn't implement the option here.

Fixes #2310.

'!= false' is used because 'x == 1' is rejected by meson if 'x' is
false. OTOH, 'x != false' seems to work if 'x' is 1.
2023-06-13 21:10:57 +02:00
Masatake YAMATO
157a469671 lsfd: use xstrdup instead of xasprintf(...\"%s\"
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-13 19:21:33 +09:00
Masatake YAMATO
6b58fb5f45 tests: (lsfd) add a case for testing INOTIFY.INODES.RAW column
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-13 19:18:54 +09:00
Masatake YAMATO
5e0e9730ca tests: (mkfds) add / and /etc/fstab as the monitoring targets to inotify
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-13 19:18:54 +09:00
Masatake YAMATO
c1a26ac8f1 lsfd: fill NAME column of inotify files with the information about their monitoring targets
# ./lsfd  -p 1  -Q '(TYPE == "inotify") and (FD > 7)'
    COMMAND PID USER ASSOC MODE    TYPE       SOURCE MNTID INODE NAME
    systemd   1 root    11  r-- inotify anon_inodefs    15  1060 inodes=116@dm-0
    systemd   1 root    13  r-- inotify anon_inodefs    15  1060 inodes=299@tmpfs
    systemd   1 root    19  r-- inotify anon_inodefs    15  1060 inodes=41@tmpfs,2@tmpfs,1@tmpfs,96@dm-0
    systemd   1 root    21  r-- inotify anon_inodefs    15  1060 inodes=41@tmpfs,2@tmpfs,1@tmpfs,96@dm-0

In addition, INOTIFY.INODES and INOTIFY.INODES.RAW column are added.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-13 19:18:35 +09:00
Masatake YAMATO
c032850e8f lsdf: make the code for filling SOURCE, PARTITION, and MAJMIN reusable
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-13 19:18:26 +09:00
Thomas Weißschuh
88ad4e7462 libmount: (tests) add helper for option list splitting
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-13 08:27:48 +02:00
Thomas Weißschuh
565eebbc45 meson: build test_mount_optlist
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-13 08:20:15 +02:00
Enze Li
b5fc1d120e build-sys: add enosys and syscalls.h to gitignore
After compiling enosys, the syscalls.h file and the executable enosys are
generated, let's add these two files to the .gitignore file.

Signed-off-by: Enze Li <lienze@kylinos.cn>
2023-06-12 12:47:44 +02:00
Enze Li
c9fbfd99ad build-sys: rearrange gitignore in alphabetical order
Signed-off-by: Enze Li <lienze@kylinos.cn>
2023-06-12 12:47:44 +02:00
Karel Zak
793e8d2ab8 cfdisk: add hint about labels for bootable flag
Addresses: https://github.com/util-linux/util-linux/discussions/2220
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-12 12:34:16 +02:00
Karel Zak
1c8a51701d Merge branch 'libmount/loop-rw' of https://github.com/t-8ch/util-linux
* 'libmount/loop-rw' of https://github.com/t-8ch/util-linux:
  libmount: (optlist) correctly detect ro status
2023-06-12 12:22:02 +02:00
Karel Zak
48554a4165 Merge branch 'lsfd--refactor' of https://github.com/masatake/util-linux
* 'lsfd--refactor' of https://github.com/masatake/util-linux:
  timeutils: add an inline funciton, is_timespecset()
  lsfd: use scols_table_get_column_by_name
2023-06-12 12:18:50 +02:00
Karel Zak
6182debc20 Merge branch 'setuid' of https://github.com/eworm-de/util-linux
* 'setuid' of https://github.com/eworm-de/util-linux:
  meson: install write setgid
  meson: install wall setgid
  meson: install umount setuid
  meson: install mount setuid
  meson: install newgrp setuid
  meson: install su setuid
  meson: install chsh setuid
  meson: install chfn setuid
2023-06-12 12:16:27 +02:00
Karel Zak
ed41386a03 Merge branch 'lsfd--signalfd' of https://github.com/masatake/util-linux
* 'lsfd--signalfd' of https://github.com/masatake/util-linux:
  tests: (lsfd) add a case for testing signalfd related columns
  tests: (mkfds) add a factory to make a signalfd
  lsfd.1.adoc: update for signalfds
  lsfd: print the masks specified in signalfds
2023-06-12 12:15:41 +02:00
Thomas Weißschuh
69e98d12a9 libmount: (optlist) correctly detect ro status
Fixes #2305

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-11 11:52:08 +02:00
Masatake YAMATO
765b4a147b timeutils: add an inline funciton, is_timespecset()
Close #2300.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-11 05:11:08 +09:00
Masatake YAMATO
0cc8e82a49 lsfd: use scols_table_get_column_by_name
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-11 00:19:12 +09:00
Christian Hesse
cee78467be meson: install write setgid
... as this requires elevated privileges.
2023-06-09 15:04:40 +02:00
Christian Hesse
07641fd93c meson: install wall setgid
... as this requires elevated privileges.
2023-06-09 15:04:40 +02:00
Christian Hesse
1cb3c90ca5 meson: install umount setuid
... as this requires elevated privileges.
2023-06-09 15:04:40 +02:00
Christian Hesse
8f49b3693d meson: install mount setuid
... as this requires elevated privileges.
2023-06-09 15:04:40 +02:00
Christian Hesse
cb3dee5a14 meson: install newgrp setuid
... as this requires elevated privileges.
2023-06-09 15:04:40 +02:00
Christian Hesse
fb8c224eae meson: install su setuid
... as this requires elevated privileges.
2023-06-09 15:04:40 +02:00
Christian Hesse
a13574b1de meson: install chsh setuid
... as this requires elevated privileges.
2023-06-09 15:04:40 +02:00
Christian Hesse
60d457f529 meson: install chfn setuid
... as this requires elevated privileges.
2023-06-09 15:04:40 +02:00
Karel Zak
39032646fe Merge branch 'PR/libmount-force-mount2' of github.com:karelzak/util-linux-work
* 'PR/libmount-force-mount2' of github.com:karelzak/util-linux-work:
  libmount: introduce LIBMOUNT_FORCE_MOUNT2={always,never,auto}
2023-06-09 11:50:23 +02:00
Masatake YAMATO
6591ddf6b0 tests: (lsfd) add a case for testing signalfd related columns
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-09 07:51:00 +09:00
Masatake YAMATO
4012622ab4 tests: (mkfds) add a factory to make a signalfd
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-08 21:33:06 +09:00
Masatake YAMATO
82e8be5a3d lsfd.1.adoc: update for signalfds
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-08 07:37:01 +09:00
Masatake YAMATO
b22d1e541a lsfd: print the masks specified in signalfds
An example output:

    # ./lsfd -p "$(pidof systemd-journald)" -Q '(TYPE == "signalfd")'

    COMMAND             PID USER ASSOC MODE     TYPE       SOURCE MNTID INODE NAME
    systemd-journal 2382709 root   238  rw- signalfd anon_inodefs    15  1060 mask=USR1,USR2
    systemd-journal 2382709 root   239  rw- signalfd anon_inodefs    15  1060 mask=INT,TERM
    systemd-journal 2382709 root   240  rw- signalfd anon_inodefs    15  1060 mask=35

Using signum_to_signame is suggested by Karel Zak <kzak@redhat.com>.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-08 07:35:20 +09:00
Karel Zak
fd6b4d94ff libmount: introduce LIBMOUNT_FORCE_MOUNT2={always,never,auto}
Let's introduce a stable workaround for use cases where new kernel API
is not ready to use.

The patch does not use "goto enosys" to exit as nothing in the hookset
is initialized yet.

Addresses: https://github.com/util-linux/util-linux/issues/1992
Addresses: https://github.com/util-linux/util-linux/issues/2283
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-07 10:12:29 +02:00
Karel Zak
97d60d6699 Merge branch 'pr/libmount-5.12.0' of github.com:karelzak/util-linux-work
* 'pr/libmount-5.12.0' of github.com:karelzak/util-linux-work:
  libmount: use mount(2) for remount on Linux < 5.14
2023-06-06 10:47:35 +02:00
Karel Zak
0dbf5504dc Merge branch 'lsfd--misc-fix' of https://github.com/masatake/util-linux
* 'lsfd--misc-fix' of https://github.com/masatake/util-linux:
  lsfd: assign a class to the file in new_file()
  lsfd: don't check the value returned from new_file()
2023-06-06 10:46:19 +02:00
Karel Zak
00f254a8f0 Merge branch 'lsfd--timerfd' of https://github.com/masatake/util-linux
* 'lsfd--timerfd' of https://github.com/masatake/util-linux:
  tests: (lsfd/filter) add a case for comparing floating point numbers
  tests: (lsfd) add a case for testing timerfd related columns
  tests: add ts_skip_capability
  tests: (mkfds) add a factory to make a timerfd
  lsfd.1.adoc: write about timerfd
  lsfd: print the detail of the timer associated with a timerfd
  lsfd: (filter) accept floating point numbers in expressions
  lsfd: (filter) support floating point number used in columns
  lsfd: (filter) reduce duplicated code in macro definitions
  lsfd: (filter) improve error message
  lsfd.1.adoc: revise type names for columns
  lsfd.1.adoc: fix typos
  lsfd: adjust coding style
  lsfd: fix a sentence in comment
2023-06-06 10:45:17 +02:00
Karel Zak
71b01d2a37 libmount: use mount(2) for remount on Linux < 5.14
It seems mount_setattr() is supported on Linux < 5.14, but it's without
MOUNT_ATTR_NOSYMFOLLOW. That's problem for remount where we reset all
VFS flags.

The most simple (but not elegant) is to check for kernel version and
fallback to mount(2) on remount.

Addresses: https://github.com/util-linux/util-linux/issues/2283
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-06-05 12:59:41 +02:00
Karel Zak
7db2e6373b Merge branch 'fix-jfs' of https://github.com/mbroz/util-linux
* 'fix-jfs' of https://github.com/mbroz/util-linux:
  libblkid: jfs - avoid undefined shift
2023-06-05 11:46:11 +02:00
Karel Zak
b7dd45f6c8 Merge branch 'libblkid/bcache-csum' of https://github.com/t-8ch/util-linux
* 'libblkid/bcache-csum' of https://github.com/t-8ch/util-linux:
  libblkid: (bcache) report block size
  libblkid: (bcache) report version
  libblkid: (bcache) report label
  libblkid: (bcache) also calculate checksum over journal buckets
  libblkid: (bcache) extend superblock definition
2023-06-05 11:45:37 +02:00
Karel Zak
57cd868ed1 Merge branch 'fixes' of https://github.com/t-8ch/util-linux
* 'fixes' of https://github.com/t-8ch/util-linux:
  libmount (python) : simplify struct initialization
  lsfd-filter: constify filter logic
  misc: constify some fields
2023-06-05 11:44:30 +02:00
Masatake YAMATO
2beb17a641 lsfd: assign a class to the file in new_file()
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-05 06:41:08 +09:00
Masatake YAMATO
783807a511 lsfd: don't check the value returned from new_file()
The funciton newver returns NULL.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-05 06:41:08 +09:00
Milan Broz
16d8b1e2a6 libblkid: jfs - avoid undefined shift
Fix previous commit 04a0717b0b
to avoid undefined shift if value is exactly 32.

  libblkid/src/superblocks/jfs.c:46:39: runtime error:
  shift exponent 32 is too large for 32-bit type 'unsigned int'

Reproducer found with OSS-Fuzz (issue 59284) running over
cryptsetup project (blkid is used in header init).

Signed-off-by: Milan Broz <gmazyland@gmail.com>
2023-06-04 19:18:57 +02:00
Masatake YAMATO
7816bcb9da tests: (lsfd/filter) add a case for comparing floating point numbers
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 17:19:34 +09:00
Masatake YAMATO
ed59afeefb tests: (lsfd) add a case for testing timerfd related columns
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 17:19:34 +09:00
Masatake YAMATO
63feafbae8 tests: add ts_skip_capability
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 17:19:34 +09:00
Masatake YAMATO
baadd080d3 tests: (mkfds) add a factory to make a timerfd
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 17:19:34 +09:00
Masatake YAMATO
50f73920c5 lsfd.1.adoc: write about timerfd
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 17:19:34 +09:00
Masatake YAMATO
188b7d64bb lsfd: print the detail of the timer associated with a timerfd
An example output:

    # ./lsfd -p 1  -Q '(TYPE == "timerfd")' -oCOMMAND,PID,ASSOC,TYPE,INODE,NAME
    COMMAND PID ASSOC    TYPE INODE NAME
    systemd   1    22 timerfd  1060 clockid=monotonic remaining=4625.661834645
    systemd   1    25 timerfd  1060 clockid=realtime remaining=398.164618943
    systemd   1   112 timerfd  1060 clockid=realtime remaining=7537606384.202715161

Added three new columns, TIMERFD.{CLOCKID,TIMERFD.REMAINING,INTERVAL}.
The filter engine works well with them.

An example listing timerfd files expiring within 1.2 seconds.

    # ./lsfd -Q '(TIMERFD.REMAINING > 0.0) && (TIMERFD.REMAINING < 1.2)'
    COMMAND          PID        USER ASSOC MODE    TYPE       SOURCE MNTID INODE NAME
    Xorg           17069         jet    26  rw- timerfd anon_inodefs    15  1060 clockid=monotonic remaining=0.061075544
    systemd-oomd 2382701 systemd-oom     8  rw- timerfd anon_inodefs    15  1060 clockid=monotonic remaining=0.178126915

Using SCOLS_JSON_NUMBER as the data type for TIMERFD.REMAINING and
TIMERFD.INTERVAL columns is suggested by Thomas Weißschuh
<thomas@t-8ch.de>.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 17:18:38 +09:00
Masatake YAMATO
1fa1856471 lsfd: (filter) accept floating point numbers in expressions
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 07:57:02 +09:00
Masatake YAMATO
564d954a86 lsfd: (filter) support floating point number used in columns
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 07:40:42 +09:00
Masatake YAMATO
520f03a241 lsfd: (filter) reduce duplicated code in macro definitions
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 07:40:42 +09:00
Masatake YAMATO
70b1623ca6 lsfd: (filter) improve error message
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 07:40:42 +09:00
Masatake YAMATO
0dc26444be lsfd.1.adoc: revise type names for columns
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 07:40:42 +09:00
Masatake YAMATO
0a0c726e77 lsfd.1.adoc: fix typos
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 06:32:18 +09:00
Masatake YAMATO
dd458e6585 lsfd: adjust coding style
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 06:32:18 +09:00
Masatake YAMATO
326e4be479 lsfd: fix a sentence in comment
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-06-04 06:32:18 +09:00
Thomas Weißschuh
9bd8074862 libblkid: (bcache) report block size
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-03 13:51:36 +02:00
Thomas Weißschuh
1b2efad216 libblkid: (bcache) report version
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-03 13:51:22 +02:00
Thomas Weißschuh
11d0724f78 libblkid: (bcache) report label
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-03 13:51:09 +02:00
Thomas Weißschuh
7140635881 libblkid: (bcache) also calculate checksum over journal buckets
Fixes #2291

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-03 13:50:51 +02:00
Thomas Weißschuh
d2f4b5c83b libblkid: (bcache) extend superblock definition
We will need it for the correct checksum calculation.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-03 13:28:18 +02:00
Thomas Weißschuh
6f052eaa1e libmount (python) : simplify struct initialization
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-03 10:25:03 +02:00
Thomas Weißschuh
9b6ad16fd9 lsfd-filter: constify filter logic
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-03 10:25:03 +02:00
Thomas Weißschuh
37b2b3fa46 misc: constify some fields
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-03 10:13:59 +02:00
Thomas Weißschuh
ed3fd21fe2 ci: use clang 16
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-03 09:22:00 +02:00
Thomas Weißschuh
3a14fb35be tests: fix subtests containing spaces in their name
Previously these tests would silently fail to compare
$TS_OUTPUT / $TS_ERRLOG.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-03 09:19:44 +02:00
Thomas Weißschuh
45552ef260 ci: build with GCC 13/11
Newer releases of GCC 13 have reigned in the false positives, so use it
for CI now.
The sanitizer builds are sticking to GCC 11 for now.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-06-01 15:01:14 +02:00
Thomas Weißschuh
90b12595bb ci: build on old distro
This should help to catch build breaks

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-31 18:14:28 +02:00
Thomas Weißschuh
edc4e52533 ci: mark source directory as safe
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-31 18:14:28 +02:00
Thomas Weißschuh
b660e0c4df ci: prevent prompts during installation
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-31 18:14:28 +02:00
Thomas Weißschuh
d53284bb1e tests: skip broken tests on docker
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-31 18:14:28 +02:00
Thomas Weißschuh
023e77d26a tests: add ts_skip_docker
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-31 18:14:28 +02:00
Thomas Weißschuh
a5b093698a tools: (asciidoctor) explicitly require extensions module
This is needed for older versions of asciidoctor.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-31 18:14:28 +02:00
Thomas Weißschuh
25a70dcb2e build-sys: only pass --failure-level if supported
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-31 17:31:42 +02:00
Thomas Weißschuh
58c16c8442 build-sys: fix typo in waitpid check
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-31 17:31:42 +02:00
Thomas Weißschuh
d975467d8f lsfd: (tests) fix typo
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-31 17:31:42 +02:00
Thomas Weißschuh
ae20b7fb4c blockdev: properly check for BLKGETZONESZ ioctl
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-31 16:11:46 +02:00
Thomas Weißschuh
754c030f29 blkzone: don't take address of struct blk_zone
Older versions of GCC do not know the warning so they warn about the
unknown ignored warning.

As struct blk_zone is only 64 bytes anyway just copy it.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-31 16:11:46 +02:00
Karel Zak
99e7f7101a Merge branch 'pr/termtype' 2023-05-31 11:03:07 +02:00
Karel Zak
edbd9ee562 Merge branch 'patch-1' of https://github.com/theHenMan/util-linux
* 'patch-1' of https://github.com/theHenMan/util-linux:
  Update fsck.8.adoc
2023-05-31 09:35:05 +02:00
Karel Zak
142738e861 Merge branch 'enosys/compat' of https://github.com/t-8ch/util-linux
* 'enosys/compat' of https://github.com/t-8ch/util-linux:
  test_enosys: fix build on old kernels
2023-05-31 09:30:31 +02:00
Karel Zak
423bf01e7e Merge branch 'patch-1' of https://github.com/nt8r/util-linux
* 'patch-1' of https://github.com/nt8r/util-linux:
  dmesg: make kmsg read() buffer big enough for kernel
2023-05-31 09:28:33 +02:00
Karel Zak
ddf41df9e9 Merge branch 'patch-2' of https://github.com/ThomasKaiser/util-linux
* 'patch-2' of https://github.com/ThomasKaiser/util-linux:
  Fix Blizzard-M2-Max
  Add recent Apple ARM cores
2023-05-31 09:21:11 +02:00
Karel Zak
84a8f5edb2 ttyutils: improve get_terminal_default_type() code
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-31 09:18:06 +02:00
Hennie Botha
565eae0cf4
Update fsck.8.adoc
Typo
2023-05-31 08:45:25 +02:00
Thomas Weißschuh
9ff6f9d9ab test_enosys: fix build on old kernels
Fixes #2277

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-30 20:10:02 +02:00
anteater
efb18899d2
dmesg: make kmsg read() buffer big enough for kernel
otherwise, if the kernel log has an item longer than 1024B, our read() gives EINVAL and we stop reading kmsg
2023-05-29 20:59:11 +00:00
Karel Zak
0c7df652e2 sulogin: use get_terminal_default_type()
Let's reuse the way how agetty initializes $TERM.

Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-29 15:11:48 +02:00
Karel Zak
4869b259d6 agetty: use get_terminal_default_type()
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-29 15:11:13 +02:00
Karel Zak
cba97be9fb lib/ttyutils: add get_terminal_default_type()
Based on code from agetty.

Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-29 15:10:24 +02:00
Karel Zak
96c8ff27a4 Merge branch 'next' 2023-05-29 14:56:52 +02:00
ThomasKaiser
9bd0ed6fba
Fix Blizzard-M2-Max 2023-05-29 14:47:50 +02:00
ThomasKaiser
e97637ec6f
Add recent Apple ARM cores 2023-05-29 14:42:18 +02:00
Karel Zak
ac2fc8b442 Merge branch 'mount/ntfs-segfault' of https://github.com/t-8ch/util-linux
* 'mount/ntfs-segfault' of https://github.com/t-8ch/util-linux:
  mount: (tests) test mount helper with multiple filesystems
  libmount: (tests) split helper tests
2023-05-29 11:29:19 +02:00
Masatake YAMATO
f271f09bd6 tests: (lsfd) add a case for testing EVENTPOLL.TFDS column
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-28 18:01:27 +09:00
Masatake YAMATO
bf416aeca3 tests: (mkfds) add a factory to make an eventpoll fd
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-28 18:01:27 +09:00
Masatake YAMATO
c2e2dd6008 lsfd: print file descriptors targeted by eventpoll files
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-28 18:01:27 +09:00
Masatake YAMATO
3062a58f0b add the "x" wrapper for reallocarray(3)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-28 12:34:21 +09:00
Thomas Weißschuh
36d4e61c65 mount: (tests) test mount helper with multiple filesystems
See #2267

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-25 12:44:19 +02:00
Thomas Weißschuh
63d4806055 libmount: (tests) split helper tests
This splits the test introduced in
commit 06e05eb0f7 ("libmount: don't pass option "defaults" to helper")
into its own subtest.

We will have more subtests.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-25 12:44:19 +02:00
Karel Zak
f94a7760ed libmount: don't call hooks after mount.<type> helper
In case more filesystems are specified (or when libmount follows
/{etc,proc}/filesystems) then the library may try to use and
initialize the new API because for some filesystems, we need
exec(/sbin/mount.<type>) and for another fsopen().

The hooks that use the API have to smart and detect that the mount
operation was done in external /sbin/mount.<type> helper. And in this
case, the new API file descriptors must be ignored.

The exception is propagation flags, mount(8) can set the flags after
exec(/sbin/mount.<type>), for example, "mount -t ntfs --make-private".

Fixes: https://github.com/util-linux/util-linux/issues/2267
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-25 11:58:51 +02:00
Karel Zak
12c616b029 Merge branch 'enosys/arch-check' of https://github.com/t-8ch/util-linux
* 'enosys/arch-check' of https://github.com/t-8ch/util-linux:
  enosys: add support for loongarch
  enosys: only build if AUDIT_ARCH_NATIVE is defined
  meson: require 0.57
  enosys: split audit arch detection into dedicated header
  enosys: add support for sparc
2023-05-24 11:41:59 +02:00
Karel Zak
27675c5c62 Merge branch 'lsfd--sysvipc-shmem' of https://github.com/masatake/util-linux
* 'lsfd--sysvipc-shmem' of https://github.com/masatake/util-linux:
  tests: (lsfd) add a case for testing SOURCE column for SysV shmem mappings
  tests: (mkfds) add a factory to make SysV shmem
  lsfd: add tmpfs as source of sysvipc to the the nodev_table
  lsfd: initialize pagesize in an earlier stage
  lsfd: add "nsfs" to the nodev_table to fill SOURCE column for nsfs files
  lsfd: add a helper function for adding a nodev to the nodev_table
  lsfd: add a whitespace
  lsfd: write more about nsfs in comment
2023-05-24 11:41:42 +02:00
Masatake YAMATO
24a10f06e9 tests: (lsfd) add a case for testing SOURCE column for SysV shmem mappings
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-24 01:41:47 +09:00
Masatake YAMATO
c3f8cba1d4 tests: (mkfds) add a factory to make SysV shmem
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-24 01:41:47 +09:00
Masatake YAMATO
de9ec7ee36 lsfd: add tmpfs as source of sysvipc to the the nodev_table
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-24 01:41:47 +09:00
Masatake YAMATO
c1cb27357c lsfd: initialize pagesize in an earlier stage
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-24 01:02:08 +09:00
Masatake YAMATO
916b44a59a lsfd: add "nsfs" to the nodev_table to fill SOURCE column for nsfs files
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-24 01:02:02 +09:00
Masatake YAMATO
d5ca01c0f4 lsfd: add a helper function for adding a nodev to the nodev_table
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-24 00:49:47 +09:00
Masatake YAMATO
ccd4e14285 lsfd: add a whitespace
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-24 00:49:47 +09:00
Masatake YAMATO
d289149385 lsfd: write more about nsfs in comment
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-24 00:49:47 +09:00
Thomas Weißschuh
c345a4002b enosys: add support for loongarch
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-23 17:24:01 +02:00
Thomas Weißschuh
3e0bbb1222 enosys: only build if AUDIT_ARCH_NATIVE is defined
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-23 17:24:01 +02:00
Thomas Weißschuh
e2cd74462e meson: require 0.57
It is needed for fs.read()

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-23 17:24:01 +02:00
Thomas Weißschuh
29e3f73784 enosys: split audit arch detection into dedicated header
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-23 17:24:01 +02:00
Thomas Weißschuh
fc5018e801 enosys: add support for sparc
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-23 16:35:14 +02:00
Thomas Weißschuh
9d48efbbe7 lsfd: (tests) don't run mqueue test on byteorder mismatch
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-23 14:27:48 +02:00
Thomas Weißschuh
ffdd75ccee waitpid: only build when pidfd_open is available
Fixes #2256

[kzak@redhat.com: - fix UL_BUILD_INIT() use]

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-23 12:31:23 +02:00
Karel Zak
fb889bab8b Merge branch 'meson' of https://github.com/eworm-de/util-linux
* 'meson' of https://github.com/eworm-de/util-linux:
  meson: install symlink for vigr man page
  meson: include bash-completion for write
  meson: include bash-completion for newgrp
2023-05-23 12:18:00 +02:00
Karel Zak
c733db6114 Merge branch 'lsfd--mqueue' of https://github.com/masatake/util-linux
* 'lsfd--mqueue' of https://github.com/masatake/util-linux:
  tests: (lsfd) add cases for POSIX Mqueue
  tests: (mkfds) add mqueue factory
  lsfd: fill ENDPOINTS column of POSIX Mqueue
  lsfd: add a new type "mqueue", a type for POSIX Mqueue
2023-05-23 12:17:18 +02:00
Karel Zak
3429accb62 Merge branch 'agetty/fileutils' of https://github.com/t-8ch/util-linux
* 'agetty/fileutils' of https://github.com/t-8ch/util-linux:
  agetty: include fileutils.h
2023-05-23 12:16:31 +02:00
Christian Hesse
f6fb7fa713 meson: install symlink for vigr man page 2023-05-23 12:15:41 +02:00
Christian Hesse
e1cd4002c8 meson: include bash-completion for write 2023-05-23 12:15:41 +02:00
Christian Hesse
f265b43296 meson: include bash-completion for newgrp 2023-05-23 12:15:41 +02:00
Karel Zak
54e94f8669 libmount: cleanup enosys returns from mount hoop
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-23 12:13:02 +02:00
Karel Zak
99550bf5aa Merge branch 'libmount/mount_setattr' of https://github.com/t-8ch/util-linux
* 'libmount/mount_setattr' of https://github.com/t-8ch/util-linux:
  libmount: check for availability of mount_setattr
2023-05-23 12:06:36 +02:00
Karel Zak
9105d3cdd8 fstab: add hint about systemd reload
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-23 11:34:19 +02:00
Karel Zak
a5eba5046d mount: improve code readability
Static analyzers (e.g., Coverity) have a hard time understanding why
'optarg' is tested for NULL, and later in another place, code assumes
that it's non-NULL. For idmapping, the optarg is required.

Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-23 10:47:18 +02:00
Karel Zak
a5e0e06cc2 login: fix memory leak [coverity scan]
Let's use ul_path_read_buffer() to avoid memory allocation.

Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-23 10:43:59 +02:00
Karel Zak
fe0b1e793c libmount: don't call mount.<type> helper with usernames
This is v2.39 regression. The "user" mount option is internally
converted to "user=<name>", but this should not be exported to
the mount helpers.

The mount helper accepts the <name> only if specified in mount options
(cifs uses user=). The real username as generated by libmount is not
relevant in this case.

Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-22 17:26:55 +02:00
Thomas Weißschuh
51a97767db agetty: include fileutils.h
It is needed to access xreaddir()

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-22 17:11:17 +02:00
Masatake YAMATO
d6850a7611 tests: (lsfd) add cases for POSIX Mqueue
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-22 23:29:19 +09:00
Masatake YAMATO
330555c481 tests: (mkfds) add mqueue factory
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-22 23:29:19 +09:00
Masatake YAMATO
29bcb60ee6 lsfd: fill ENDPOINTS column of POSIX Mqueue
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-22 23:29:19 +09:00
Karel Zak
e2d6f5e30e tests: add optlist tests
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-22 15:40:38 +02:00
Masatake YAMATO
ad0569880f lsfd: add a new type "mqueue", a type for POSIX Mqueue
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-22 22:25:57 +09:00
Karel Zak
c0267687fd libmount: fix options prepend/insert and merging
* the order of the new options should not be changed
   (for example prepend "a,b,c" to list with "d" has to generate "a,b,c,d", not "c,b,a,d")

 * make sure that  options map is defined when merging options

Fixes: https://github.com/util-linux/util-linux/issues/2238
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-22 15:00:25 +02:00
Karel Zak
096800a0df Merge branch 'agetty-creds' of https://github.com/DaanDeMeyer/util-linux
* 'agetty-creds' of https://github.com/DaanDeMeyer/util-linux:
  Document new systemd credentials support for agetty and login
  login: Initialize noauth from login.noauth credential
  agetty: Load autologin user from agetty.autologin credential
2023-05-22 13:42:48 +02:00
Karel Zak
59dc323560 Merge branch 'map-users' of https://github.com/arachsys-prs/util-linux
* 'map-users' of https://github.com/arachsys-prs/util-linux:
  mount: add --map-users and --map-groups convenience options
2023-05-22 13:36:37 +02:00
Karel Zak
518026915b Merge branch 'ci/openwrt' of https://github.com/t-8ch/util-linux
* 'ci/openwrt' of https://github.com/t-8ch/util-linux:
  ci: add OpenWrt SDK based CI jobs
  enosys: provide a nicer build message for syscalls.h generation
  libsmartcols: (samples): fix format truncation warning
  test_uuidd: make pthread_t formatting more robust
  mkfs.minix: handle 64bit time on 32bit system
  enosys: add support for MIPS, PowerPC and ARC
  enosys: include sys/syscall.h
2023-05-22 13:32:53 +02:00
Karel Zak
f1cd43964d Merge branch 'enosys/speculation' of https://github.com/t-8ch/util-linux 2023-05-22 13:10:31 +02:00
Karel Zak
c8ecfe1e39 Merge branch 'enosys/mips' of https://github.com/t-8ch/util-linux
* 'enosys/mips' of https://github.com/t-8ch/util-linux:
  enosys: add support for MIPS, PowerPC and ARC
2023-05-22 13:09:28 +02:00
Karel Zak
0045193005 Merge branch 'fadvise/big-page' of https://github.com/t-8ch/util-linux
* 'fadvise/big-page' of https://github.com/t-8ch/util-linux:
  fadvise: (test) test with 64k blocks
  fadvise: (test) don't compare fincore page counts
  fadvise: (tests) factor out calls to "fincore"
  fadvise: (test) dynamically calculate expected test values
2023-05-22 13:06:44 +02:00
Karel Zak
3dae5ca16a Merge branch 'test--fix-process-leak' of https://github.com/masatake/util-linux
* 'test--fix-process-leak' of https://github.com/masatake/util-linux:
  lsfd: (tests) fix process leak
2023-05-22 13:04:08 +02:00
Karel Zak
e20944db44 Merge branch 'enosys/include' of https://github.com/t-8ch/util-linux
* 'enosys/include' of https://github.com/t-8ch/util-linux:
  enosys: include sys/syscall.h
2023-05-22 13:01:58 +02:00
Karel Zak
b39f5764b9 Merge branch 'libblkid/const' of https://github.com/t-8ch/util-linux
* 'libblkid/const' of https://github.com/t-8ch/util-linux:
  libblkid: constify cached disk data
2023-05-22 13:00:04 +02:00
Karel Zak
392d864b75 lib/shells: remove space after function name
Cats and ponies die when they see a space after a function name ...

Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-22 12:45:06 +02:00
Karel Zak
f644f33089 lib/shells: initialize free-able variables
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-22 12:43:53 +02:00
Karel Zak
8128908d32 Merge branch 'econf' of https://github.com/stoeckmann/util-linux
* 'econf' of https://github.com/stoeckmann/util-linux:
  lib/shells: Plug econf memory leak
2023-05-22 12:42:13 +02:00
Karel Zak
ccd06765ce Merge branch 'lsfd--eventfd' of https://github.com/masatake/util-linux
* 'lsfd--eventfd' of https://github.com/masatake/util-linux:
  test_mkfds: avoid "ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’"
  tests: (lsfd) add cases for eventfd
  tests: (mkfds) add eventfd factory
  tests: (mkfds) provide the way to declare the number of extra printing values
  tests: (mkfds) print a whitespace only when the running factory has "report" method
  lsfd: fill ENDPOINTS column for eventfd
  lsfd: add a helper macro, foreach_endpoint
  lsfd: add a helper function, init_endpoint
  lsfd: add a helper function, add_endpoint
  lsfd: add a helper function, new_ipc
  lsfd: add a back pointer as a member of anon_eventfd_data
  lsfd: move a local variable to a narrower scope
  lsfd: add EVENTFD.ID column
  lsfd: delete redundant parentheses surrounding return value
  ldfd: delete unnecessary ';'
  lsfd: choose anon_ops declarative way
2023-05-22 12:39:59 +02:00
Karel Zak
cc665f33f4 Merge branch 'hexdump-one-byte-hex' of https://github.com/tpwo/util-linux
* 'hexdump-one-byte-hex' of https://github.com/tpwo/util-linux:
  hexdump: add new format-strings test case
  hexdump: add '--one-byte-hex' format option
2023-05-22 12:36:45 +02:00
Karel Zak
8a53082787 Merge branch 'allow-disabling-waitpid' of https://github.com/mrc0mmand/util-linux
* 'allow-disabling-waitpid' of https://github.com/mrc0mmand/util-linux:
  build-sys: add --disable-waitpid
2023-05-22 12:32:07 +02:00
Thomas Weißschuh
ced82526a1 enosys: allow CPU speculation
enosys is not a security tool so we can allow the CPU to speculate.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-22 10:00:13 +02:00
Thomas Weißschuh
1bd85b6463 libmount: check for availability of mount_setattr
If mount_setattr is not available but needed fall back to the legacy
mount API.

Fixes #2247

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-22 09:38:07 +02:00
Masatake YAMATO
47035719fc lsfd: (tests) fix process leak
Unifying multiple invocations of kill command and wait command
into two is suggested by Thomas Weißschuh <thomas@t-8ch.de>.

Addresses: https://lore.kernel.org/util-linux/652d32c5-4b33-ce3a-3de7-9ebc064bbdcb@gmail.com/
Reported-by: Bruce Dubbs <bruce.dubbs@gmail.com>
Tested-by: Bruce Dubbs <bruce.dubbs@gmail.com>
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-22 06:45:22 +09:00
Thomas Weißschuh
c0f31b79f5 fadvise: (test) test with 64k blocks
This will allow the tests to also pass on systems with 64k pagesizes.

Closes #2249
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-21 21:49:41 +02:00
Thomas Weißschuh
33980996d0 fadvise: (test) don't compare fincore page counts
These depend on the machines pagesize and are therefore not a good
comparision.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-21 21:48:50 +02:00
Thomas Weißschuh
e5009e773f fadvise: (tests) factor out calls to "fincore"
This will make it easier to pass argument later.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-21 21:48:20 +02:00
Thomas Weißschuh
8b36444f44 fadvise: (test) dynamically calculate expected test values
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-21 21:48:12 +02:00
Thomas Weißschuh
06e05eb0f7 libmount: don't pass option "defaults" to helper
"defaults" is only a pseudo-option that expands to other options.
It should not be passed to helpers.

Reported-by: Quentin Rameau <quinq@fifth.space>
Closes: https://lore.kernel.org/util-linux/20230521181814.0b0f2d38.quinq@fifth.space/
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-21 20:02:21 +02:00
Thomas Weißschuh
5f7c4093e2 ci: add OpenWrt SDK based CI jobs
This allows testing some more exotic architectures and libcs.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-19 23:16:48 +02:00
Thomas Weißschuh
9b1cf2bc69 enosys: provide a nicer build message for syscalls.h generation
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-19 17:52:19 +02:00
Thomas Weißschuh
d36705f402 libsmartcols: (samples): fix format truncation warning
As this is only an example and the needed memory is not much just
hardcode a large enough number.
The previously computed value was wrong anyways.

libsmartcols/samples/continuous.c: In function 'main':
libsmartcols/samples/continuous.c:110:61: error: '%3d' directive output may be truncated writing between 3 and 11 bytes into a region of size between 0 and 7 [-Werror=format-truncation=]
  110 |                         snprintf(timecell, timecellsz, "%f [%3d%%]", diff,
      |                                                             ^~~
libsmartcols/samples/continuous.c:110:25: note: 'snprintf' output between 11 and 333 bytes into a destination of size 12
  110 |                         snprintf(timecell, timecellsz, "%f [%3d%%]", diff,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111 |                                 done ? 100 : (int)(diff / (TIME_PERIOD / 100.0)));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libsmartcols/samples/continuous.c:110:61: error: '%3d' directive output may be truncated writing 3 bytes into a region of size between 0 and 7 [-Werror=format-truncation=]
  110 |                         snprintf(timecell, timecellsz, "%f [%3d%%]", diff,
      |                                                             ^~~
libsmartcols/samples/continuous.c:110:25: note: 'snprintf' output between 11 and 325 bytes into a destination of size 12
  110 |                         snprintf(timecell, timecellsz, "%f [%3d%%]", diff,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111 |                                 done ? 100 : (int)(diff / (TIME_PERIOD / 100.0)));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-19 17:50:01 +02:00
Thomas Weißschuh
cf652a7278 test_uuidd: make pthread_t formatting more robust
On musl pthread_t is a pointer. To avoid compiler warnings on 32bit
systems add a cast through intptr_t.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-19 17:48:58 +02:00
Thomas Weißschuh
c249602368 mkfs.minix: handle 64bit time on 32bit system
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-19 17:48:16 +02:00
Thomas Weißschuh
9c9d03e064 enosys: add support for MIPS, PowerPC and ARC
Co-developed-by: Hauke Mertens <hauke@hauke-m.de>
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-19 17:47:52 +02:00
Thomas Weißschuh
43d4d1cc1d enosys: include sys/syscall.h
Otherwise there is no guarantee that all syscall numbers detected by
tools/all_syscalls are actually available to enosys.c.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-19 17:47:52 +02:00
Thomas Weißschuh
6c1bd545cb enosys: include sys/syscall.h
Otherwise there is no guarantee that all syscall numbers detected by
tools/all_syscalls are actually available to enosys.c.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-19 10:51:25 +02:00
Thomas Weißschuh
1808882ad3 enosys: add support for MIPS, PowerPC and ARC
Co-developed-by: Hauke Mertens <hauke@hauke-m.de>
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-19 00:14:24 +02:00
Thomas Weißschuh
7eba8f98bd libblkid: constify cached disk data
The data returned from blkid_probe_get_buffer() and friends may or may
not be cached between different calls.
If one copy is modified this may not be visible in other copies.

This issue can be avoided by making any modification illegal.

See also #2165

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-19 00:00:34 +02:00
Masatake YAMATO
babcf0896c test_mkfds: avoid "ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’"
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:27 +09:00
Masatake YAMATO
821efb4f6f tests: (lsfd) add cases for eventfd
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:27 +09:00
Masatake YAMATO
5ba67aeabd tests: (mkfds) add eventfd factory
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:27 +09:00
Masatake YAMATO
26406d1a72 tests: (mkfds) provide the way to declare the number of extra printing values
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:27 +09:00
Masatake YAMATO
90317e2a12 tests: (mkfds) print a whitespace only when the running factory has "report" method
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:27 +09:00
Masatake YAMATO
d4fea4d089 lsfd: fill ENDPOINTS column for eventfd
An example output:

  $ ./lsfd -Q '(TYPE == "eventfd") and (ENDPOINTS =~ ".+") ' -o+ENDPOINTS
  COMMAND          PID USER ASSOC MODE    TYPE       SOURCE MNTID INODE NAME   ENDPOINTS
  pipewire       17251  jet    40  rw- eventfd anon_inodefs    15  1060 id=818 17255,pipewire-pulse,26
  pipewire       17251  jet    52  rw- eventfd anon_inodefs    15  1060 id=695 17255,pipewire-pulse,30
									       17255,pipewire-pulse,37
									       17255,pipewire-pulse,49
  pipewire       17251  jet    54  rw- eventfd anon_inodefs    15  1060 id=845 17255,pipewire-pulse,31
  pipewire       17251  jet    61  rw- eventfd anon_inodefs    15  1060 id=212 17255,pipewire-pulse,45
  pipewire       17251  jet    62  rw- eventfd anon_inodefs    15  1060 id=224 17255,pipewire-pulse,46
  pipewire-pulse 17255  jet    26  rw- eventfd anon_inodefs    15  1060 id=818 17251,pipewire,40
  pipewire-pulse 17255  jet    30  rw- eventfd anon_inodefs    15  1060 id=695 17251,pipewire,52
									       17255,pipewire-pulse,37
									       17255,pipewire-pulse,49
  pipewire-pulse 17255  jet    31  rw- eventfd anon_inodefs    15  1060 id=845 17251,pipewire,54
  pipewire-pulse 17255  jet    37  rw- eventfd anon_inodefs    15  1060 id=695 17251,pipewire,52
									       17255,pipewire-pulse,30
									       17255,pipewire-pulse,49
  pipewire-pulse 17255  jet    45  rw- eventfd anon_inodefs    15  1060 id=212 17251,pipewire,61
  pipewire-pulse 17255  jet    46  rw- eventfd anon_inodefs    15  1060 id=224 17251,pipewire,62
  pipewire-pulse 17255  jet    49  rw- eventfd anon_inodefs    15  1060 id=695 17251,pipewire,52
									       17255,pipewire-pulse,30
									       17255,pipewire-pulse,37

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:27 +09:00
Masatake YAMATO
e62d587334 lsfd: add a helper macro, foreach_endpoint
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:27 +09:00
Masatake YAMATO
f9263edc9b lsfd: add a helper function, init_endpoint
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:27 +09:00
Masatake YAMATO
1c2ab17ecd lsfd: add a helper function, add_endpoint
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:27 +09:00
Masatake YAMATO
79ec864eaa lsfd: add a helper function, new_ipc
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:27 +09:00
Masatake YAMATO
e283500c05 lsfd: add a back pointer as a member of anon_eventfd_data
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:27 +09:00
Masatake YAMATO
55c857ae09 lsfd: move a local variable to a narrower scope
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:27 +09:00
Masatake YAMATO
8c2ca9c973 lsfd: add EVENTFD.ID column
The files under of /proc/$pid/fdinfo/* provide IDs for eventfd files.
With this change, lsfd extacts the IDs. All eventfd files share the
same inode. So the IDs are useful to distinguish two different
envetfds.

An example output:

  $ ./lsfd -Q '(TYPE == "eventfd")' -o+EVENTFD.ID | head
  COMMAND             PID USER ASSOC MODE    TYPE       SOURCE MNTID INODE NAME   EVENTFD.ID
  gnome-session-b   17113  jet     3  rw- eventfd anon_inodefs    15  1060 id=43          43
  gnome-session-b   17113  jet     4  rw- eventfd anon_inodefs    15  1060 id=44          44
  gnome-session-b   17113  jet     6  rw- eventfd anon_inodefs    15  1060 id=158        158
  gnome-session-b   17113  jet     8  rw- eventfd anon_inodefs    15  1060 id=167        167
  at-spi-bus-laun   17160  jet     3  rw- eventfd anon_inodefs    15  1060 id=341        341
  at-spi-bus-laun   17160  jet     4  rw- eventfd anon_inodefs    15  1060 id=342        342
  at-spi-bus-laun   17160  jet     5  rw- eventfd anon_inodefs    15  1060 id=343        343
  at-spi-bus-laun   17160  jet     9  rw- eventfd anon_inodefs    15  1060 id=344        344
  gvfsd             17169  jet     3  rw- eventfd anon_inodefs    15  1060 id=369        369

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:27:24 +09:00
Masatake YAMATO
4a3d70fed3 lsfd: delete redundant parentheses surrounding return value
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:26:57 +09:00
Masatake YAMATO
1e83b1fc6f ldfd: delete unnecessary ';'
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:26:57 +09:00
Masatake YAMATO
007e405b1e lsfd: choose anon_ops declarative way
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-05-19 03:26:55 +09:00
Frantisek Sumsal
c0d75916b6 build-sys: add --disable-waitpid
The new pidfd stuff waitpid uses is not compatible with older kernel
headers, but the rest of the util-linux is still perfectly fine, so
allow disabling just the waitpid utility to make the builds happy again.
2023-05-18 18:56:15 +02:00
Tobias Stoeckmann
b83e58a55c lib/shells: Plug econf memory leak
You can see the memory leak with address sanitizer if util-linux is
compiled with `--with-vendordir=/usr/etc`.

How to reproduce:

1. Prepare a custom shell file as root
```
mkdir -p /etc/shells.d
echo /bin/myshell > /etc/shells.d/custom
```

2. Run chsh as regular user
```
chsh
```

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2023-05-18 17:48:46 +02:00
Karel Zak
01a0a55601 lib/caputils: fix integer handling issues [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-05-18 10:26:02 +02:00
наб
03a8f430c5 mesg.1 cleanups/updates
First hunk:  grammar.
Second hunk: (a) mentioning BSD ptys and not UNIX98 ones is odd,
             (b) mentioning /only/ ptys is odder still.
Third hunk:  mesg is found in the UNIX Programmer's Manual;
             it takes its modern form in V7
             (it's unclear to me why V6 specifically is mentioned,
              since it's still default-invert + always-report-"was X").
2023-05-17 13:53:45 +02:00
Karel Zak
a82df27f5d Merge branch 'nsenter-keep-caps' of https://github.com/dgibson/util-linux
* 'nsenter-keep-caps' of https://github.com/dgibson/util-linux:
  Add --keep-caps option to nsenter, similar to the one in unshare
  unshare: Move implementation of --keep-caps option to library function
2023-05-17 13:43:40 +02:00
Karel Zak
d3edf0f8de Merge branch 'libmount/syscall' 2023-05-17 13:42:01 +02:00
Karel Zak
bd2ebbd4ea Merge branch 'enosys' of https://github.com/t-8ch/util-linux
* 'enosys' of https://github.com/t-8ch/util-linux:
  enosys: properly block execve syscall
  enosys: don't require end-of-options marker
  enosys: find syscalls at build time
  enosys: remove long jumps from BPF
  enosys: add --list
  enosys: validate syscall architecture
  enosys: add manpage
  enosys: add bash completion
  enosys: make messages useful for users
  enosys: translate messages
  enosys: add common arguments
  enosys: add test
  enosys: fix native arch for s390x
  enosys: syscall numbers are "long"
  enosys: mark variable static
  enosys: remove unneeded inline variable declaration
  enosys: improve checks for EXIT_NOTSUPP
  enosys: move from tests/helpers/test_enosys.c
  c.h: make err_nonsys available
2023-05-17 13:34:34 +02:00
Karel Zak
372e026e09 Merge branch 'mkswap/offset' of https://github.com/t-8ch/util-linux
* 'mkswap/offset' of https://github.com/t-8ch/util-linux:
  mkswap: implement --offset
  mkswap: (tests) don't overwrite logfiles
  mkswap: (tests) validate existence of truncate command
2023-05-17 13:27:55 +02:00
Karel Zak
976157c821 Merge branch 'blockdev/zonesz' of https://github.com/t-8ch/util-linux
* 'blockdev/zonesz' of https://github.com/t-8ch/util-linux:
  blockdev: add support for BLKGETZONESZ
2023-05-17 13:26:34 +02:00
Karel Zak
747fe9946a Merge branch 'mount/tests/fstab' of https://github.com/t-8ch/util-linux
* 'mount/tests/fstab' of https://github.com/t-8ch/util-linux:
  mount: (tests) reuse well-known per-test fstab location
  tests: (functions.sh) use per-test fstab file
  mount: (tests) explicitly use test fstab location
  tests: (functions.sh) create variable for test fstab location
2023-05-17 13:25:25 +02:00
Thomas Weißschuh
afb669afed enosys: properly block execve syscall
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-17 00:25:20 +02:00
Thomas Weißschuh
4b1538c754 enosys: don't require end-of-options marker
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:45:17 +02:00
Thomas Weißschuh
69e542bd2d enosys: find syscalls at build time
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:44:50 +02:00
Thomas Weißschuh
5e248716e6 enosys: remove long jumps from BPF
BPF encodes the jump distance in a uint8_t. To avoid overflows of this
value reorganize the generated bytecode to work without long jumps.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:44:50 +02:00
Thomas Weißschuh
7f104027e2 enosys: add --list 2023-05-16 22:44:50 +02:00
Thomas Weißschuh
9e8fb1f5ed enosys: validate syscall architecture
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:44:50 +02:00
Thomas Weißschuh
ae03abcf56 enosys: add manpage
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:44:50 +02:00
Thomas Weißschuh
ac5267423d enosys: add bash completion
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:44:50 +02:00
Thomas Weißschuh
a3fdbe0c4f enosys: make messages useful for users
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:44:50 +02:00
Thomas Weißschuh
13d1cbced2 enosys: translate messages
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:44:50 +02:00
Thomas Weißschuh
344ba205c1 enosys: add common arguments
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:44:50 +02:00
Thomas Weißschuh
4290056351 enosys: add test
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:44:41 +02:00
Thomas Weißschuh
113356e95d enosys: fix native arch for s390x
s390 also defines __s390__ so we first have to check for __s390x__.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:32:29 +02:00
Thomas Weißschuh
58fe26362c enosys: syscall numbers are "long"
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:32:29 +02:00
Thomas Weißschuh
165fbfd46e enosys: mark variable static
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:32:29 +02:00
Thomas Weißschuh
7626054ca8 enosys: remove unneeded inline variable declaration
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:32:29 +02:00
Thomas Weißschuh
f080b635a1 enosys: improve checks for EXIT_NOTSUPP
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:32:25 +02:00
Thomas Weißschuh
cba52cc194 enosys: move from tests/helpers/test_enosys.c 2023-05-16 22:31:57 +02:00
Thomas Weißschuh
bb2b071f54 c.h: make err_nonsys available
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-16 22:31:57 +02:00
Tomasz Wojdat
42de8aba28
hexdump: add new format-strings test case
Signed-off-by: Tomasz Wojdat <tpwojdat@gmail.com>
2023-05-16 21:46:57 +02:00
Tomasz Wojdat
bbf5bf8a88
hexdump: add '--one-byte-hex' format option
Signed-off-by: Tomasz Wojdat <tpwojdat@gmail.com>
2023-05-16 20:24:21 +02:00
Thomas Weißschuh
8b70b9e32a mount: (tests) reuse well-known per-test fstab location
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-14 21:51:23 +02:00
Thomas Weißschuh
6aa8d17b6b tests: (functions.sh) use per-test fstab file
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-14 21:51:23 +02:00
Thomas Weißschuh
b1580bd760 mount: (tests) explicitly use test fstab location
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-14 21:51:23 +02:00
Thomas Weißschuh
ed3d33faff tests: (functions.sh) create variable for test fstab location
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-14 21:51:23 +02:00
Thomas Weißschuh
84ec6f99f7 mkswap: implement --offset
Addresses #2166

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-11 12:09:56 +02:00
Thomas Weißschuh
b0826e8c98 mkswap: (tests) don't overwrite logfiles
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-11 12:09:56 +02:00
Thomas Weißschuh
d996ff1dc6 mkswap: (tests) validate existence of truncate command
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-11 12:09:55 +02:00
Thomas Weißschuh
4832fd9f36 blockdev: add support for BLKGETZONESZ
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-05 10:57:52 +02:00
Karel Zak
91ea38e91d libmount: report failed syscall name
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-04-25 12:48:18 +02:00
Chris Webb
a61bbb3709 mount: add --map-users and --map-groups convenience options
Allow an X-mount.idmap option to be specified either from an existing
userns with --map-users=/proc/PID/ns/user or incrementally with a series
of --map-users=INNER:OUTER:COUNT and --map-groups=INNER:OUTER:COUNT
options which compose into a single X-mount.idmap mount option.

Apart from distinguishing absolute namespace paths from literal mappings,
defer validation to libmount when it parses X-mount.idmap.

Signed-off-by: Chris Webb <chris@arachsys.com>
2023-04-24 15:37:45 +01:00
Daan De Meyer
1bf9c6915e Document new systemd credentials support for agetty and login 2023-04-16 15:05:15 +02:00
Karel Zak
2ed0190535 Merge branch 'flock/test/fd' of https://github.com/t-8ch/util-linux into next
* 'flock/test/fd' of https://github.com/t-8ch/util-linux:
  flock: (tests) add test for fd-based locking
2023-04-14 09:47:16 +02:00
Karel Zak
575d71fde1 nsenter: (man) add --keep-caps
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-04-13 12:29:55 +02:00
Karel Zak
d4b1d901c5 Merge branch 'nsenter-keep-caps' of https://github.com/dgibson/util-linux into next
* 'nsenter-keep-caps' of https://github.com/dgibson/util-linux:
  Add --keep-caps option to nsenter, similar to the one in unshare
  unshare: Move implementation of --keep-caps option to library function
2023-04-13 12:25:01 +02:00
Daan De Meyer
12252002ad login: Initialize noauth from login.noauth credential
Let's check if we've been passed credentials by systemd and if so,
try to determine whether we need to auth the user to login from
the login.noauth credential.
2023-04-13 11:47:18 +02:00
Daan De Meyer
bcebab29a7 agetty: Load autologin user from agetty.autologin credential
Let's check if we've been passed credentials by systemd and if so,
try to read the user to autologin from the agetty.autologin
credential.

Partially fixes #2012
2023-04-13 11:46:21 +02:00
Karel Zak
ad6d9fd50c cfdisk: ask y/n before wipe
Addresses: https://github.com/util-linux/util-linux/issues/2160
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-04-12 15:07:45 +02:00
David Gibson
5b175fa9f0 Add --keep-caps option to nsenter, similar to the one in unshare
When entering a user namespace at the kernel level, whether with clone(2),
unshare(2) or setns(2), a process always gains full capabilities in the
new userns.

unshare(1) allows using that from the shell with the --keep-caps option,
which transfers that full permitted capability set to the ambient set so
it's available to the spawned shell or other process.

nsenter(1) currently has no equivalent option, despite the fact that
setns(2) grants capabilities in just the same way.  This patch adds a
--keep-caps to nsenter(1) that works just like the one in unshare(1).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-29 13:51:10 +11:00
David Gibson
acb72212eb unshare: Move implementation of --keep-caps option to library function
unshare.c open codes some logic to copy the permitted capability set to the
ambient set in order to implement the --keep-caps option.  Move this logic
to lib/caputils.c so that we can reuse it in nsenter.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-29 13:36:15 +11:00
292 changed files with 20382 additions and 92886 deletions

View file

@ -29,6 +29,7 @@ PACKAGES=(
iproute2
dmsetup
python3-dev
gawk
)
PACKAGES_OPTIONAL=(
@ -59,7 +60,9 @@ bash -c "echo 'deb-src http://archive.ubuntu.com/ubuntu/ $RELEASE main restricte
# cov-build fails to compile util-linux when CC is set to gcc-*
# so let's just install and use the default compiler
if [[ "$COMPILER_VERSION" == "" ]]; then
PACKAGES+=("$COMPILER")
if [[ "$COMPILER" != "none" ]]; then
PACKAGES+=("$COMPILER")
fi
elif [[ "$COMPILER" == clang ]]; then
# Latest LLVM stack deb packages provided by https://apt.llvm.org/
# Following snippet was borrowed from https://apt.llvm.org/llvm.sh

View file

@ -1,5 +1,5 @@
#!/bin/bash
set -ex
PHASES=(${@:-CONFIGURE MAKE INSTALL CHECK DISTCHECK})
@ -87,9 +87,7 @@ for phase in "${PHASES[@]}"; do
)
if [[ "$COVERAGE" == "yes" ]]; then
CFLAGS+=(--coverage)
CXXFLAGS+=(--coverage)
LDFLAGS+=(--coverage)
opts+=(--enable-coverage)
fi
if [[ "$SANITIZE" == "yes" ]]; then
@ -104,6 +102,11 @@ for phase in "${PHASES[@]}"; do
CXXFLAGS+=(-shared-libasan)
fi
if [[ "$HOST_TRIPLET" != "" ]]; then
opts+=(--host "$HOST_TRIPLET")
fi
git config --global --add safe.directory "$PWD"
git clean -xdf
./autogen.sh
@ -123,9 +126,9 @@ for phase in "${PHASES[@]}"; do
ninja -C build
;;
CODECHECK)
make checklibdoc
make checkxalloc
;;
make checklibdoc
make checkxalloc
;;
CHECK)
if [[ "$SANITIZE" == "yes" ]]; then
# All the following black magic is to make test/eject/umount work, since
@ -157,6 +160,20 @@ for phase in "${PHASES[@]}"; do
fi
fi
if [[ "$COVERAGE" == "yes" ]]; then
# Make (almost) everything under current directory readable/writable
# for everyone to allow gcov to write the .gcda files even with
# dropped privileges
find . tests/helpers/ -maxdepth 1 -type d ! -name . ! -name tests \
-exec setfacl -R -m 'd:g::rwX,d:o::rwX' -m 'g::rwX,o::rwX' '{}' \;
# Make sure we can access $PWD as an unpriv user
path="$PWD"
while [[ "$path" != / ]]; do
chmod o+rx "$path"
path="$(dirname "$path")"
done
fi
./tests/run.sh --show-diff
if [[ "$COVERAGE" == "yes" ]]; then

View file

@ -20,14 +20,18 @@ permissions:
jobs:
build:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ toJSON(matrix.env) }}-${{ github.ref }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
env:
- { COMPILER: "gcc", COMPILER_VERSION: "10", SANITIZE: "yes" }
- { COMPILER: "gcc", COMPILER_VERSION: "10", SANITIZE: "no" }
- { COMPILER: "clang", COMPILER_VERSION: "15", SANITIZE: "yes" }
- { COMPILER: "clang", COMPILER_VERSION: "15", SANITIZE: "no" }
# gcc-13 has false-positives with ubsan
- { COMPILER: "gcc", COMPILER_VERSION: "11", SANITIZE: "yes" }
- { COMPILER: "gcc", COMPILER_VERSION: "13", SANITIZE: "no" }
- { COMPILER: "clang", COMPILER_VERSION: "16", SANITIZE: "yes" }
- { COMPILER: "clang", COMPILER_VERSION: "16", SANITIZE: "no" }
env: ${{ matrix.env }}
steps:
- name: Repository checkout
@ -44,13 +48,16 @@ jobs:
run: sudo -E .github/workflows/cibuild.sh CHECK
- name: Make install
run: .github/workflows/cibuild.sh INSTALL
coveralls:
permissions:
contents: read # to fetch code (actions/checkout)
checks: write # to create new checks (coverallsapp/github-action)
runs-on: ubuntu-latest
if: github.repository == 'util-linux/util-linux'
concurrency:
group: ${{ github.workflow }}-coveralls-${{ github.ref }}
cancel-in-progress: true
env:
COMPILER: gcc
COMPILER_VERSION: 10
@ -70,9 +77,13 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coverage.info
meson:
needs: build
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-meson-${{ github.ref }}
cancel-in-progress: true
env:
COMPILER: gcc
COMPILER_VERSION: 10
@ -86,9 +97,13 @@ jobs:
run: .github/workflows/cibuild.sh MESONCONF
- name: Meson build
run: .github/workflows/cibuild.sh MESONBUILD
distcheck:
needs: build
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-distcheck-${{ github.ref }}
cancel-in-progress: true
env:
COMPILER: gcc
COMPILER_VERSION: 10
@ -103,9 +118,42 @@ jobs:
run: .github/workflows/cibuild.sh CONFIGURE
- name: Make distcheck
run: .github/workflows/cibuild.sh DISTCHECK
build-compat:
strategy:
fail-fast: false
matrix:
include:
- image: ubuntu:18.04
name: build (compat, ${{ matrix.image }})
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-build-compat-${{ github.ref }}
cancel-in-progress: true
env:
COMPILER: none
container:
image: ${{ matrix.image }}
steps:
- name: Repository checkout
uses: actions/checkout@v1
- name: Ubuntu setup
run: .github/workflows/cibuild-setup-ubuntu.sh
- name: Configure
run: .github/workflows/cibuild.sh CONFIGURE
- name: Code checks
run: .github/workflows/cibuild.sh CODECHECK
- name: Configure & Make
run: .github/workflows/cibuild.sh MAKE
- name: Check
run: .github/workflows/cibuild.sh CHECK
build-arch:
name: build (qemu-user, ${{ matrix.arch }})
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ toJSON(matrix) }}-${{ github.ref }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
@ -133,3 +181,55 @@ jobs:
.github/workflows/cibuild.sh CONFIGURE MAKE
# Check
.github/workflows/cibuild.sh CHECK
build-openwrt:
name: build (openwrt, ${{ matrix.target }})
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ toJSON(matrix) }}-${{ github.ref }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
include:
- target: ipq40xx
subtarget: generic
abi: musl_eabi
- target: ath79
subtarget: generic
abi: musl
- target: bcm63xx
subtarget: generic
abi: musl
- target: mpc85xx
subtarget: p2020
abi: musl
- target: archs38
subtarget: generic
abi: glibc
env:
COMPILER: none
steps:
- name: Repository checkout
uses: actions/checkout@v1
- name: Ubuntu setup
run: sudo -E .github/workflows/cibuild-setup-ubuntu.sh
- name: OpenWrt environment
run: |
OPENWRT_RELEASE=22.03.5
OPENWRT_SDK=openwrt-sdk-$OPENWRT_RELEASE-${{ matrix.target }}-${{ matrix.subtarget }}_gcc-11.2.0_${{ matrix.abi }}.Linux-x86_64
echo "COMPILER=$COMPILER" >> $GITHUB_ENV
echo "OPENWRT_RELEASE=$OPENWRT_RELEASE" >> $GITHUB_ENV
echo "OPENWRT_SDK=$OPENWRT_SDK" >> $GITHUB_ENV
- name: Download toolchain
run: |
curl -o ~/${{ env.OPENWRT_SDK }}.tar.xz -C - https://downloads.cdn.openwrt.org/releases/${{ env.OPENWRT_RELEASE }}/targets/${{ matrix.target }}/${{ matrix.subtarget }}/${{ env.OPENWRT_SDK }}.tar.xz
tar xf ~/${{ env.OPENWRT_SDK }}.tar.xz -C ~
- name: Configure
run: |
source .github/workflows/openwrt-sdk-env.sh ~/${{ env.OPENWRT_SDK }}
.github/workflows/cibuild.sh CONFIGURE
- name: Make
run: |
source .github/workflows/openwrt-sdk-env.sh ~/${{ env.OPENWRT_SDK }}
.github/workflows/cibuild.sh MAKE

View file

@ -23,6 +23,9 @@ jobs:
runs-on: ubuntu-latest
if: github.repository == 'util-linux/util-linux'
concurrency:
group: ${{ github.workflow }}-${{ matrix.sanitizer }}-${{ matrix.architecture }}-${{ github.ref }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:

17
.github/workflows/openwrt-sdk-env.sh vendored Executable file
View file

@ -0,0 +1,17 @@
#!/bin/sh
sdk="$(realpath $1)"
STAGING_DIR="$(echo "$sdk"/staging_dir/toolchain-*)"
. "$STAGING_DIR/info.mk"
PATH="$sdk/staging_dir/host/bin:$PATH"
CC="$STAGING_DIR/bin/${TARGET_CROSS}gcc"
BISON_PKGDATADIR="$sdk/staging_dir/host/share/bison"
M4="$sdk/staging_dir/host/bin/m4"
HOST_TRIPLET="$("$CC" -dumpmachine)"
echo "Building for $HOST_TRIPLET from $sdk"
export STAGING_DIR PATH CC BISON_PKGDATADIR M4 HOST_TRIPLET

12
.gitignore vendored
View file

@ -46,6 +46,10 @@ config/test-driver
configure
cscope.out
depcomp
GPATH
GRTAGS
GTAGS
GSYMS
INSTALL
install-sh
libtool
@ -58,22 +62,20 @@ mkinstalldirs
stamp-h
stamp-h.in
stamp-h1
syscalls.h
tags
test-suite.log
tests/run.sh.log
tests/run.sh.trs
update.log
ylwrap
GPATH
GRTAGS
GTAGS
GSYMS
#
# binaries
#
/addpart
/agetty
/build*/
/blkdiscard
/blkid
/blkpr
@ -95,6 +97,7 @@ GSYMS
/delpart
/dmesg
/eject
/enosys
/fadvise
/fallocate
/fdformat
@ -197,4 +200,3 @@ GSYMS
/wipefs
/write
/zramctl
/build*/

View file

@ -397,7 +397,6 @@ CONTRIBUTORS:
Helmut Grohne <helmut@subdivi.de>
Hendrik Lönngren <wikibugs@googlemail.com>
Henne Vogelsang <hvogel@opensuse.org>
Hennie Botha <42469385+theHenMan@users.noreply.github.com>
Hideki EIRAKU <hdk@igel.co.jp>
Hill Ma <maahiuzeon@gmail.com>
Hiroaki Sengoku <sengoku@senri.gcd.org>
@ -751,7 +750,6 @@ CONTRIBUTORS:
ratijas <me@ratijas.tk>
Raul Gutierrez Segales <rgs@itevenworks.net>
Ray Wang <wanglei1123@gmail.com>
Remus-Gabriel Chelu <remusgabriel.chelu@disroot.org>
Rian Hunter <rian@alum.mit.edu>
Richard Allen <rsaxvc@rsaxvc.net>
Richard Fuchs <rfuchs@sipwise.com>

View file

@ -1,117 +0,0 @@
util-linux v2.39.1 Release Notes
================================
The main objective of this maintenance release is to address bugs in libmount and
resolve the regression that occurred due to the v2.39 rewrite for the new kernel
mount interface.
The meson build system has also been enhanced.
Changes between v2.39 and v2.39.1
---------------------------------
blkzone:
- don't take address of struct blk_zone [Thomas Weißschuh]
build-sys:
- add --disable-waitpid [Frantisek Sumsal]
- don't call pkg-config --static if unnecessary [Karel Zak]
- fix typo in waitpid check [Thomas Weißschuh]
- only pass --failure-level if supported [Thomas Weißschuh]
cal:
- fix error message for bad -c argument [Jakub Wilk]
- fix long option name for -c [Jakub Wilk]
ci:
- prevent prompts during installation [Thomas Weißschuh]
dmesg:
- make kmsg read() buffer big enough for kernel [anteater]
docs:
- update AUTHORS file [Karel Zak]
enosys:
- add support for MIPS, PowerPC and ARC [Thomas Weißschuh]
- add support for loongarch [Thomas Weißschuh]
- add support for sparc [Thomas Weißschuh]
- split audit arch detection into dedicated header [Thomas Weißschuh]
hardlink:
- (man) add missing comma [Jakub Wilk]
lib:
- remove pager.c from libcommon [Karel Zak]
lib/ include/:
- cleanup license headers [Karel Zak]
lib/color-names:
- fix license header [Karel Zak]
lib/loopdev:
- consistently return error values from loopcxt_find_unused() [Thomas Weißschuh]
- document function return values [Thomas Weißschuh]
lib/strutils:
- fix typo [Jakub Wilk]
libblkid:
- (bcache) also calculate checksum over journal buckets [Thomas Weißschuh]
- (bcache) extend superblock definition [Thomas Weißschuh]
- jfs - avoid undefined shift [Milan Broz]
libmount:
- (optlist) correctly detect ro status [Thomas Weißschuh]
- always ignore user=<name> [Karel Zak]
- check for availability of mount_setattr [Thomas Weißschuh]
- cleanup enosys returns from mount hoop [Karel Zak]
- don't call hooks after mount.<type> helper [Karel Zak]
- don't call mount.<type> helper with usernames [Karel Zak]
- don't pass option "defaults" to helper [Thomas Weißschuh]
- fix options prepend/insert and merging [Karel Zak]
- fix sync options between context and fs structs [Karel Zak]
- introduce LIBMOUNT_FORCE_MOUNT2={always,never,auto} [Karel Zak]
libsmartcols:
- (samples) fix format truncation warning [Thomas Weißschuh]
logger:
- initialize socket credentials contol union [Karel Zak]
losetup:
- deduplicate find_unused() logic [Thomas Weißschuh]
lsfd:
- (filter) weakly support ARRAY_STRING and ARRAY_NUMBER json types [Masatake YAMATO]
- (tests) fix typo [Thomas Weißschuh]
- use ARRAY_STRING for ENDPOINTS column in JSON output mode [Masatake YAMATO]
meson:
- add conditionalization for test progs [Zbigniew Jędrzejewski-Szmek]
- check for _NL_TIME_WEEK_1STDAY in langinfo.h [Christian Hesse]
- conditionalize waitpid [Zbigniew Jędrzejewski-Szmek]
- implement HAVE_PTY [Zbigniew Jędrzejewski-Szmek]
- include bash-completion for newgrp [Christian Hesse]
- include bash-completion for write [Christian Hesse]
- install chfn setuid [Christian Hesse]
- install chsh setuid [Christian Hesse]
- install mount setuid [Christian Hesse]
- install newgrp setuid [Christian Hesse]
- install su setuid [Christian Hesse]
- install symlink for vigr man page [Christian Hesse]
- install umount setuid [Christian Hesse]
- install wall setgid [Christian Hesse]
- install write setgid [Christian Hesse]
- require 0.57 [Thomas Weißschuh]
mkfs.minix:
- handle 64bit time on 32bit system [Thomas Weißschuh]
po:
- merge changes [Karel Zak]
- update hr.po (from translationproject.org) [Božidar Putanec]
po-man:
- add ko.po (from translationproject.org) [Seong-ho Cho]
- add ro.po (from translationproject.org) [Remus-Gabriel Chelu]
- merge changes [Karel Zak]
- update uk.po (from translationproject.org) [Yuri Chornoivan]
sfdisk:
- add hint about duplicate UUIDs when use dump [Karel Zak]
test_enosys:
- fix build on old kernels [Thomas Weißschuh]
test_uuidd:
- make pthread_t formatting more robust [Thomas Weißschuh]
tests:
- (lsfd) add a case for verifying ENDPOINTS column output in JSON mode [Masatake YAMATO]
- (run.sh) detect builddir from working directory [Thomas Weißschuh]
- backport mount_setattr test [Karel Zak]
- backport special mount script [Karel Zak]
- fix update special mount test output [Karel Zak]
tools:
- (asciidoctor) explicitly require extensions module [Thomas Weißschuh]
unshare:
- fix error message for unexpected time offsets [Thomas Weißschuh]
waitpid:
- only build when pidfd_open is available [Thomas Weißschuh]

View file

@ -17,9 +17,14 @@ AM_CPPFLAGS += \
endif
endif
if WITH_COVERAGE
AM_CPPFLAGS += \
-include $(top_srcdir)/include/coverage.h
endif
AM_CFLAGS = -fsigned-char $(WARN_CFLAGS)
AM_CXXFLAGS = $(AM_CFLAGS)
AM_LDFLAGS = $(ASAN_LDFLAGS) $(UBSAN_LDFLAGS) $(FUZZING_ENGINE_LDFLAGS)
AM_LDFLAGS = $(ASAN_LDFLAGS) $(UBSAN_LDFLAGS) $(FUZZING_ENGINE_LDFLAGS) $(COVERAGE_LDFLAGS)
# Add gettext stuff to the global LDADD for systems with separate libintl
# library. The LTLIBINTL is generated by AM_GNU_GETTEXT macro.

4
NEWS
View file

@ -1,7 +1,3 @@
util-linux 2.39.1: Jun 27 2023
* see Documentation/releases/v2.39.1-ReleaseNotes or the complete changelog at
https://www.kernel.org/pub/linux/utils/util-linux/v2.39/v2.39.1-ChangeLog
util-linux 2.39: May 17 2023
* see Documentation/releases/v2.39-ReleaseNotes or the complete changelog at
https://www.kernel.org/pub/linux/utils/util-linux/v2.39/v2.39-ChangeLog

View file

@ -344,5 +344,11 @@ endif
if BUILD_WAITPID
dist_bashcompletion_DATA += bash-completion/waitpid
endif
if BUILD_ENOSYS
dist_bashcompletion_DATA += bash-completion/enosys
endif
if BUILD_LSCLOCKS
dist_bashcompletion_DATA += bash-completion/lsclocks
endif
endif # BUILD_BASH_COMPLETION

View file

@ -13,6 +13,7 @@ _blockdev_module()
--getro
--getdiscardzeroes
--getdiskseq
--getzonesz
--getss
--getpbsz
--getiomin

37
bash-completion/enosys Normal file
View file

@ -0,0 +1,37 @@
_waitpid_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-s'|'--syscall')
return 0
;;
'-l'|'--list')
return 0
;;
'-h'|'--help'|'-V'|'--version')
return 0
;;
esac
case $cur in
-*)
OPTS="--syscall
--list
--help
--version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
*)
_pids
return 0
;;
esac
local IFS=$'\n'
compopt -o filenames
COMPREPLY=( $(compgen -u -- $cur) )
return 0
}
complete -F _enosys_module enosys

View file

@ -28,6 +28,7 @@ _hexdump_module()
case $cur in
-*)
OPTS=" --one-byte-octal
--one-byte-hex
--one-byte-char
--canonical
--two-bytes-decimal

View file

@ -54,6 +54,8 @@ _hwclock_module()
--epoch
--param-get
--param-set
--vl-read
--vl-clear
--update-drift
--noadjfile
--adjfile

48
bash-completion/lsclocks Normal file
View file

@ -0,0 +1,48 @@
_lsclocks_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-J'|'--json')
return 0
;;
'-n'|'--noheadings')
return 0
;;
'-o'|'--output')
return 0
;;
'-r'|'--raw')
return 0
;;
'-t'|'--time')
clocks="$(command "$1" --noheadings --raw --output NAME)"
COMPREPLY=( $(compgen -W "$clocks" -- "$cur") )
return 0
;;
'-h'|'--help'|'-V'|'--version')
return 0
;;
esac
case $cur in
-*)
OPTS="--json
--noheadings
--output
--raw
--time
--help
--version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
*)
return 0
;;
esac
return 0
}
complete -F _lsclocks_module lsclocks

View file

@ -21,13 +21,17 @@ _mkswap_module()
COMPREPLY=( $(compgen -W "$(uuidgen -r)" -- $cur) )
return 0
;;
'-o'|'--offset')
COMPREPLY=( $(compgen -W "bytes" -- $cur) )
return 0
;;
'-h'|'--help'|'-V'|'--version')
return 0
;;
esac
case $cur in
-*)
OPTS="--check --force --pagesize --lock --label --swapversion --uuid --verbose --version --help"
OPTS="--check --force --pagesize --lock --label --swapversion --uuid --offset --verbose --version --help"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;

View file

@ -42,9 +42,11 @@ _nsenter_module()
--pid=
--cgroup=
--user=
--user-parent
--time=
--setuid
--setgid
--keep-caps
--preserve-credentials
--root=
--wd=

View file

@ -29,7 +29,7 @@ PACKAGE_VERSION_RELEASE=$(echo $PACKAGE_VERSION | awk -F. '{
dnl libblkid version
LIBBLKID_VERSION="$PACKAGE_VERSION_MAJOR.$PACKAGE_VERSION_MINOR.$PACKAGE_VERSION_RELEASE"
LIBBLKID_DATE="27-Jun-2023"
LIBBLKID_DATE="17-May-2023"
LIBBLKID_LT_MAJOR=1
LIBBLKID_LT_MINOR=1
LIBBLKID_LT_MICRO=0
@ -215,6 +215,17 @@ AC_PROG_CXX
AM_CONDITIONAL([FUZZING_ENGINE], [test "x$enable_fuzzing_engine" = xyes])
AM_CONDITIONAL([OSS_FUZZ], [test "x$LIB_FUZZING_ENGINE" != x])
AC_ARG_ENABLE([coverage],
AS_HELP_STRING([--enable-coverage], [compile with gcov]),
[], [enable_coverage=no]
)
AS_IF([test "x$enable_coverage" = xyes], [
UL_WARN_ADD([--coverage])
COVERAGE_LDFLAGS="--coverage"
])
AC_SUBST([COVERAGE_LDFLAGS])
AM_CONDITIONAL([WITH_COVERAGE], [test "x$enable_coverage" = xyes])
dnl libtool-2
LT_INIT
@ -729,6 +740,9 @@ AS_IF([test x"$have_dirfd" = xno], [
AM_CONDITIONAL([HAVE_DIRFD], [test "x$have_dirfd" = xyes || test "x$have_ddfd" = xyes])
MQ_LIBS=
AC_CHECK_LIB([rt], [mq_open], [MQ_LIBS="-lrt"])
AC_SUBST([MQ_LIBS])
AC_MSG_CHECKING([whether program_invocation_short_name is defined])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
@ -1867,6 +1881,22 @@ UL_REQUIRES_LINUX([waitpid])
UL_REQUIRES_SYSCALL_CHECK([waitpid], [UL_CHECK_SYSCALL([pidfd_open])], [pidfd_open])
AM_CONDITIONAL([BUILD_WAITPID], [test "x$build_waitpid" = xyes])
UL_BUILD_INIT([enosys], [check])
UL_REQUIRES_LINUX([enosys])
AS_IF([test "x$build_enosys" = xyes], [
AC_MSG_CHECKING([for valid audit arch])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include "${srcdir}/include/audit-arch.h"]])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
build_enosys=no
])
])
AM_CONDITIONAL([BUILD_ENOSYS], [test "x$build_enosys" = xyes])
UL_BUILD_INIT([lsclocks], [yes])
AM_CONDITIONAL([BUILD_LSCLOCKS], [test "x$build_lsclocks" = xyes])
UL_BUILD_INIT([getopt], [yes])
AM_CONDITIONAL([BUILD_GETOPT], [test "x$build_getopt" = xyes])
@ -2875,7 +2905,8 @@ AC_MSG_RESULT([
ldflags: ${LDFLAGS}
suid ldflags: ${SUID_LDFLAGS}
ASAN enabled: ${enable_asan}
Fuzzing enabled: ${enable_fuzzing_engine}
Fuzzing enabled: ${enable_fuzzing_engine}
Coverage enabled ${enable_coverage}
cflags: ${CFLAGS}

View file

@ -60,6 +60,9 @@ Get discard zeroes support status.
*--getdiskseq*::
Get disk sequence number.
*--getzonesz*::
Get zone size in 512-byte sectors.
*--getfra*::
Get filesystem readahead in 512-byte sectors.

View file

@ -10,6 +10,9 @@
#include <unistd.h>
#include <sys/ioctl.h>
#include <errno.h>
#ifdef HAVE_LINUX_BLKZONED_H
#include <linux/blkzoned.h>
#endif
#include "c.h"
#include "nls.h"
@ -175,6 +178,14 @@ static const struct bdc bdcms[] =
.argval = -1,
.help = N_("get disk sequence number")
},{
#ifdef BLKGETZONESZ
IOCTL_ENTRY(BLKGETZONESZ),
.name = "--getzonesz",
.argtype = ARG_UINT,
.argval = -1,
.help = N_("get zone size")
},{
#endif
IOCTL_ENTRY(BLKFLSBUF),
.name = "--flushbufs",
.help = N_("flush buffers")

View file

@ -1,7 +1,7 @@
/*
* cfdisk.c - Display or manipulate a disk partition table.
*
* Copyright (C) 2014-2015 Karel Zak <kzak@redhat.com>
* Copyright (C) 2014-2023 Karel Zak <kzak@redhat.com>
* Copyright (C) 1994 Kevin E. Martin (martin@cs.unc.edu)
*
* The original cfdisk was inspired by the fdisk program
@ -21,6 +21,7 @@
#include <assert.h>
#include <libsmartcols.h>
#include <sys/ioctl.h>
#include <rpmatch.h>
#include <libfdisk.h>
#ifdef HAVE_LIBMOUNT
@ -2256,7 +2257,8 @@ static int ui_help(void)
" ",
N_("Command Meaning"),
N_("------- -------"),
N_(" b Toggle bootable flag of the current partition"),
N_(" b Toggle bootable flag of the current partition;"),
N_(" implemented for DOS (MBR) and SGI labels only"),
N_(" d Delete the current partition"),
N_(" h Print this screen"),
N_(" n Create new partition from free space"),
@ -2280,7 +2282,7 @@ static int ui_help(void)
N_("Use lsblk(8) or partx(8) to see more details about the device."),
" ",
" ",
"Copyright (C) 2014-2017 Karel Zak <kzak@redhat.com>"
"Copyright (C) 2014-2023 Karel Zak <kzak@redhat.com>"
};
erase();
@ -2523,11 +2525,15 @@ static int main_menu_action(struct cfdisk *cf, int key)
if (rc)
warn = _("Failed to write disklabel.");
else {
size_t q_idx = 0;
if (cf->device_is_used)
fdisk_reread_changes(cf->cxt, cf->original_layout);
else
fdisk_reread_partition_table(cf->cxt);
info = _("The partition table has been altered.");
if (menu_get_menuitem_by_key(cf, 'q', &q_idx))
ui_menu_goto(cf, q_idx);
}
cf->nwrites++;
break;
@ -2587,11 +2593,17 @@ static int ui_run(struct cfdisk *cf)
DBG(UI, ul_debug("start cols=%zu, lines=%zu", ui_cols, ui_lines));
if (fdisk_get_collision(cf->cxt)) {
ui_warnx(_("Device already contains a %s signature; it will be removed by a write command."),
fdisk_get_collision(cf->cxt));
fdisk_enable_wipe(cf->cxt, 1);
ui_hint(_("Press a key to continue."));
getch();
ui_warnx(_("Device already contains a %s signature."), fdisk_get_collision(cf->cxt));
if (fdisk_is_readonly(cf->cxt)) {
ui_hint(_("Press a key to continue."));
getch();
} else {
char buf[64] = { 0 };
rc = ui_get_string(_("Do you want to remove it? [Y]es/[N]o: "), NULL,
buf, sizeof(buf));
fdisk_enable_wipe(cf->cxt,
rc > 0 && rpmatch(buf) == RPMATCH_YES ? 1 : 0);
}
}
if (!fdisk_has_label(cf->cxt) || cf->zero_start) {

View file

@ -73,6 +73,9 @@ generate a new time-based UUID
*-e*, *--endianness* _ENDIANNESS_::
Specify the _ENDIANNESS_ to use, valid arguments are *native*, *little* or *big*. The default is *native*.
*-o*, *--offset* _offset_::
Specify the _offset_ to write the swap area to.
*-v*, *--swapversion 1*::
Specify the swap-space version. (This option is currently pointless, as the old *-v 0* option has become obsolete and now only *-v 1* is supported. The kernel has not supported v0 swap-space format since 2.5.22 (June 2002). The new version v1 is supported since 2.1.117 (August 1998).)

View file

@ -76,6 +76,7 @@ struct mkswap_control {
int user_pagesize; /* --pagesize */
int pagesize; /* final pagesize used for the header */
off_t offset; /* offset of the header in the target */
char *opt_label; /* LABEL as specified on command line */
unsigned char *uuid; /* UUID parsed by libbuuid */
@ -194,6 +195,7 @@ static void __attribute__((__noreturn__)) usage(void)
fprintf(out,
_(" -e, --endianness=<value> specify the endianness to use "
"(%s, %s or %s)\n"), "native", "little", "big");
fputs(_(" -o, --offset OFFSET specify the offset in the device\n"), out);
fputs(_(" --verbose verbose output\n"), out);
fprintf(out,
@ -347,6 +349,9 @@ static unsigned long long get_size(const struct mkswap_control *ctl)
err(EXIT_FAILURE, _("cannot open %s"), ctl->devname);
if (blkdev_get_size(fd, &size) < 0)
err(EXIT_FAILURE, _("cannot determine size of %s"), ctl->devname);
if ((unsigned long long) ctl->offset > size)
errx(EXIT_FAILURE, _("offset larger than file size"));
size -= ctl->offset;
size /= ctl->pagesize;
close(fd);
@ -465,11 +470,15 @@ static void wipe_device(struct mkswap_control *ctl)
static void write_header_to_device(struct mkswap_control *ctl)
{
off_t offset;
assert(ctl);
assert(ctl->fd > -1);
assert(ctl->signature_page);
if (lseek(ctl->fd, SIGNATURE_OFFSET, SEEK_SET) != SIGNATURE_OFFSET)
offset = SIGNATURE_OFFSET + ctl->offset;
if (lseek(ctl->fd, offset, SEEK_SET) != offset)
errx(EXIT_FAILURE, _("unable to rewind swap-device"));
if (write_all(ctl->fd, (char *) ctl->signature_page + SIGNATURE_OFFSET,
@ -503,6 +512,7 @@ int main(int argc, char **argv)
{ "swapversion", required_argument, NULL, 'v' },
{ "uuid", required_argument, NULL, 'U' },
{ "endianness", required_argument, NULL, 'e' },
{ "offset", required_argument, NULL, 'o' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{ "lock", optional_argument, NULL, OPT_LOCK },
@ -521,7 +531,7 @@ int main(int argc, char **argv)
textdomain(PACKAGE);
close_stdout_atexit();
while((c = getopt_long(argc, argv, "cfp:qL:v:U:e:Vh", longopts, NULL)) != -1) {
while((c = getopt_long(argc, argv, "cfp:qL:v:U:e:o:Vh", longopts, NULL)) != -1) {
err_exclusive_options(c, longopts, excl, excl_st);
@ -567,6 +577,10 @@ int main(int argc, char **argv)
_("invalid endianness %s is not supported"), optarg);
}
break;
case 'o':
ctl.offset = str2unum_or_err(optarg,
10, _("Invalid offset"), SINT_MAX(off_t));
break;
case 'V':
print_version(EXIT_SUCCESS);
break;

View file

@ -75,14 +75,14 @@ enum {
/* column names */
struct colinfo {
const char *name; /* header */
double whint; /* width hint (N < 1 is in percent of termwidth) */
int flags; /* SCOLS_FL_* */
const char *help;
const char * const name; /* header */
double whint; /* width hint (N < 1 is in percent of termwidth) */
int flags; /* SCOLS_FL_* */
const char *help;
};
/* columns descriptions */
static struct colinfo infos[] = {
static const struct colinfo infos[] = {
[COL_PARTNO] = { "NR", 0.25, SCOLS_FL_RIGHT, N_("partition number") },
[COL_START] = { "START", 0.30, SCOLS_FL_RIGHT, N_("start of the partition in sectors") },
[COL_END] = { "END", 0.30, SCOLS_FL_RIGHT, N_("end of the partition in sectors") },
@ -141,7 +141,7 @@ static inline int get_column_id(int num)
return columns[num];
}
static inline struct colinfo *get_column_info(int num)
static inline const struct colinfo *get_column_info(int num)
{
return &infos[ get_column_id(num) ];
}
@ -674,7 +674,7 @@ static int show_parts(blkid_partlist ls, int scols_flags, int lower, int upper)
scols_table_enable_noheadings(table, !!(scols_flags & PARTX_NOHEADINGS));
for (i = 0; (size_t)i < ncolumns; i++) {
struct colinfo *col = get_column_info(i);
const struct colinfo *col = get_column_info(i);
if (!scols_table_new_column(table, col->name, col->whint, col->flags)) {
warnx(_("failed to allocate output column"));

View file

@ -13,6 +13,7 @@ dist_noinst_HEADERS += \
include/closestream.h \
include/colors.h \
include/color-names.h \
include/coverage.h \
include/cpuset.h \
include/crc32.h \
include/crc32c.h \

View file

@ -31,7 +31,7 @@
# define be16toh(x) betoh16(x)
# define be32toh(x) betoh32(x)
# define be64toh(x) betoh64(x)
#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
#elif defined(__NetBSD__) || defined(__DragonFly__)
# define bswap_16(x) bswap16(x)
# define bswap_32(x) bswap32(x)
# define bswap_64(x) bswap64(x)

View file

@ -294,6 +294,9 @@ void __err_oom(const char *file, unsigned int line)
}
#define err_oom() __err_oom(__FILE__, __LINE__)
#define err_nosys(exitcode, ...) \
err(errno == ENOSYS ? EXIT_NOTSUPP : exitcode, __VA_ARGS__)
/* Don't use inline function to avoid '#include "nls.h"' in c.h
*/

View file

@ -31,4 +31,6 @@ extern int capget(cap_user_header_t header, const cap_user_data_t data);
extern int cap_last_cap(void);
extern void cap_permitted_to_ambient(void);
#endif /* CAPUTILS_H */

25
include/coverage.h Normal file
View file

@ -0,0 +1,25 @@
/*
* No copyright is claimed. This code is in the public domain; do with
* it what you wish.
*/
#ifndef UTIL_LINUX_COVERAGE_H
#define UTIL_LINUX_COVERAGE_H
/* When built with --coverage (gcov) we need to explicitly call __gcov_dump()
* in places where we use _exit(), since _exit() skips at-exit hooks resulting
* in lost coverage.
*
* To make sure we don't miss any _exit() calls, this header file is included
* explicitly on the compiler command line via the -include directive (only
* when built with --coverage/-Db_coverage=true)
*/
void __gcov_dump(void);
void _exit(int);
__attribute__((noreturn)) static inline void _coverage__exit(int status) {
__gcov_dump();
_exit(status);
}
#define _exit(x) _coverage__exit(x)
#endif

View file

@ -1,3 +1,7 @@
/* SPDX-License-Identifier: MIT
*
* This file is licensed under the MIT License.
*/
#ifndef UL_CRC64_H
#define UL_CRC64_H

View file

@ -19,7 +19,7 @@ struct dos_partition {
#define MBR_PT_OFFSET 0x1be
#define MBR_PT_BOOTBITS_SIZE 440
static inline struct dos_partition *mbr_get_partition(unsigned char *mbr, int i)
static inline struct dos_partition *mbr_get_partition(const unsigned char *mbr, int i)
{
return (struct dos_partition *)
(mbr + MBR_PT_OFFSET + (i * sizeof(struct dos_partition)));
@ -42,7 +42,7 @@ static inline void __dos_store_4le(unsigned char *p, unsigned int val)
p[3] = ((val >> 24) & 0xff);
}
static inline unsigned int dos_partition_get_start(struct dos_partition *p)
static inline unsigned int dos_partition_get_start(const struct dos_partition *p)
{
return __dos_assemble_4le(&(p->start_sect[0]));
}
@ -52,7 +52,7 @@ static inline void dos_partition_set_start(struct dos_partition *p, unsigned int
__dos_store_4le(p->start_sect, n);
}
static inline unsigned int dos_partition_get_size(struct dos_partition *p)
static inline unsigned int dos_partition_get_size(const struct dos_partition *p)
{
return __dos_assemble_4le(&(p->nr_sects[0]));
}

View file

@ -18,6 +18,7 @@
#include <stdio.h>
#include <inttypes.h>
#include <sys/time.h>
#include <stdbool.h>
typedef uint64_t usec_t;
typedef uint64_t nsec_t;
@ -56,8 +57,10 @@ enum {
ISO_TIMEZONE = (1 << 2),
ISO_DOTUSEC = (1 << 3),
ISO_COMMAUSEC = (1 << 4),
ISO_T = (1 << 5),
ISO_GMTIME = (1 << 6),
ISO_DOTNSEC = (1 << 5),
ISO_COMMANSEC = (1 << 6),
ISO_T = (1 << 7),
ISO_GMTIME = (1 << 8),
ISO_TIMESTAMP = ISO_DATE | ISO_TIME | ISO_TIMEZONE,
ISO_TIMESTAMP_T = ISO_TIMESTAMP | ISO_T,
ISO_TIMESTAMP_DOT = ISO_TIMESTAMP | ISO_DOTUSEC,
@ -71,9 +74,10 @@ enum {
#define CTIME_BUFSIZ 26
#define ISO_BUFSIZ 42
int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz);
int strtm_iso(struct tm *tm, int flags, char *buf, size_t bufsz);
int strtimeval_iso(const struct timeval *tv, int flags, char *buf, size_t bufsz);
int strtm_iso(const struct tm *tm, int flags, char *buf, size_t bufsz);
int strtime_iso(const time_t *t, int flags, char *buf, size_t bufsz);
int strtimespec_iso(const struct timespec *t, int flags, char *buf, size_t bufsz);
#define UL_SHORTTIME_THISYEAR_HHMM (1 << 1)
@ -102,4 +106,9 @@ static inline struct timeval usec_to_timeval(usec_t t)
return r;
}
static inline bool is_timespecset(const struct timespec *t)
{
return t->tv_sec || t->tv_nsec;
}
#endif /* UTIL_LINUX_TIME_UTIL_H */

View file

@ -88,6 +88,7 @@ struct chardata {
extern int get_terminal_dimension(int *cols, int *lines);
extern int get_terminal_width(int default_width);
extern int get_terminal_type(const char **type);
extern char *get_terminal_default_type(const char *ttyname, int is_serial);
extern int get_terminal_stdfd(void);
extern int get_terminal_name(const char **path, const char **name,
const char **number);

View file

@ -46,6 +46,18 @@ void *xrealloc(void *ptr, const size_t size)
return ret;
}
static inline
__ul_calloc_size(2, 3)
__ul_returns_nonnull
void *xreallocarray(void *ptr, const size_t nelems, const size_t size)
{
void *ret = reallocarray(ptr, nelems, size);
if (!ret && size && nelems)
err(XALLOC_EXIT_CODE, "cannot allocate %zu bytes", size);
return ret;
}
static inline
__ul_calloc_size(1, 2)
__ul_returns_nonnull

View file

@ -24,6 +24,7 @@
#include "caputils.h"
#include "pathnames.h"
#include "procfs.h"
#include "nls.h"
static int test_cap(unsigned int cap)
{
@ -87,6 +88,43 @@ int cap_last_cap(void)
return cap;
}
void cap_permitted_to_ambient(void)
{
/* We use capabilities system calls to propagate the permitted
* capabilities into the ambient set because we may have
* already forked so be in async-signal-safe context. */
struct __user_cap_header_struct header = {
.version = _LINUX_CAPABILITY_VERSION_3,
.pid = 0,
};
struct __user_cap_data_struct payload[_LINUX_CAPABILITY_U32S_3] = {{ 0 }};
uint64_t effective, cap;
if (capget(&header, payload) < 0)
err(EXIT_FAILURE, _("capget failed"));
/* In order the make capabilities ambient, we first need to ensure
* that they are all inheritable. */
payload[0].inheritable = payload[0].permitted;
payload[1].inheritable = payload[1].permitted;
if (capset(&header, payload) < 0)
err(EXIT_FAILURE, _("capset failed"));
effective = ((uint64_t)payload[1].effective << 32) | (uint64_t)payload[0].effective;
for (cap = 0; cap < (sizeof(effective) * 8); cap++) {
/* This is the same check as cap_valid(), but using
* the runtime value for the last valid cap. */
if (cap > (uint64_t) cap_last_cap())
continue;
if ((effective & (1ULL << cap))
&& prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, cap, 0, 0) < 0)
err(EXIT_FAILURE, _("prctl(PR_CAP_AMBIENT) failed"));
}
}
#ifdef TEST_PROGRAM_CAPUTILS
int main(int argc, char *argv[])
{

View file

@ -21,8 +21,8 @@ extern int is_known_shell(const char *shell_name)
#if defined (HAVE_LIBECONF) && defined (USE_VENDORDIR)
size_t size = 0;
econf_err error;
char **keys;
econf_file *key_file;
char **keys = NULL;
econf_file *key_file = NULL;
error = econf_readDirs(&key_file,
_PATH_VENDORDIR,
@ -43,17 +43,18 @@ extern int is_known_shell(const char *shell_name)
syslog(LOG_ALERT,
_("Cannot evaluate entries in shells files: %s"),
econf_errString(error));
econf_free (key_file);
econf_free(key_file);
exit(EXIT_FAILURE);
}
for (size_t i = 0; i < size; i++) {
if (strcmp (keys[i], shell_name) == 0) {
if (strcmp(keys[i], shell_name) == 0) {
ret = 1;
break;
}
}
econf_free (key_file);
econf_free(keys);
econf_free(key_file);
#else
char *s;

View file

@ -448,8 +448,9 @@ int get_gmtoff(const struct tm *tp)
#endif
}
static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf, size_t bufsz)
static int format_iso_time(const struct tm *tm, uint32_t nsec, int flags, char *buf, size_t bufsz)
{
uint32_t usec = nsec / NSEC_PER_USEC;
char *p = buf;
int len;
@ -479,15 +480,28 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
p += len;
}
if (flags & ISO_DOTUSEC) {
len = snprintf(p, bufsz, ".%06"PRId64, (int64_t) usec);
if (flags & ISO_DOTNSEC) {
len = snprintf(p, bufsz, ".%09"PRIu32, nsec);
if (len < 0 || (size_t) len > bufsz)
goto err;
bufsz -= len;
p += len;
} else if (flags & ISO_COMMANSEC) {
len = snprintf(p, bufsz, ",%09"PRIu32, nsec);
if (len < 0 || (size_t) len > bufsz)
goto err;
bufsz -= len;
p += len;
} else if (flags & ISO_DOTUSEC) {
len = snprintf(p, bufsz, ".%06"PRIu32, usec);
if (len < 0 || (size_t) len > bufsz)
goto err;
bufsz -= len;
p += len;
} else if (flags & ISO_COMMAUSEC) {
len = snprintf(p, bufsz, ",%06"PRId64, (int64_t) usec);
len = snprintf(p, bufsz, ",%06"PRIu32, usec);
if (len < 0 || (size_t) len > bufsz)
goto err;
bufsz -= len;
@ -508,26 +522,37 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
return -1;
}
/* timeval to ISO 8601 */
int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz)
/* timespec to ISO 8601 */
int strtimespec_iso(const struct timespec *ts, int flags, char *buf, size_t bufsz)
{
struct tm tm;
struct tm *rc;
if (flags & ISO_GMTIME)
rc = gmtime_r(&tv->tv_sec, &tm);
rc = gmtime_r(&ts->tv_sec, &tm);
else
rc = localtime_r(&tv->tv_sec, &tm);
rc = localtime_r(&ts->tv_sec, &tm);
if (rc)
return format_iso_time(&tm, tv->tv_usec, flags, buf, bufsz);
return format_iso_time(&tm, ts->tv_nsec, flags, buf, bufsz);
warnx(_("time %"PRId64" is out of range."), (int64_t)(tv->tv_sec));
warnx(_("time %"PRId64" is out of range."), (int64_t)(ts->tv_sec));
return -1;
}
/* timeval to ISO 8601 */
int strtimeval_iso(const struct timeval *tv, int flags, char *buf, size_t bufsz)
{
struct timespec ts = {
.tv_sec = tv->tv_sec,
.tv_nsec = tv->tv_usec * NSEC_PER_USEC,
};
return strtimespec_iso(&ts, flags, buf, bufsz);
}
/* struct tm to ISO 8601 */
int strtm_iso(struct tm *tm, int flags, char *buf, size_t bufsz)
int strtm_iso(const struct tm *tm, int flags, char *buf, size_t bufsz)
{
return format_iso_time(tm, 0, flags, buf, bufsz);
}

View file

@ -7,9 +7,40 @@
#include <ctype.h>
#include <unistd.h>
#ifdef HAVE_GETTTYNAM
# include <ttyent.h>
#endif
#include "c.h"
#include "ttyutils.h"
#ifdef __linux__
# ifndef DEFAULT_VCTERM
# define DEFAULT_VCTERM "linux"
# endif
# if defined (__s390__) || defined (__s390x__)
# define DEFAULT_TTYS0 "dumb"
# define DEFAULT_TTY32 "ibm327x"
# define DEFAULT_TTYS1 "vt220"
# endif
# ifndef DEFAULT_STERM
# define DEFAULT_STERM "vt102"
# endif
#elif defined(__GNU__)
# ifndef DEFAULT_VCTERM
# define DEFAULT_VCTERM "hurd"
# endif
# ifndef DEFAULT_STERM
# define DEFAULT_STERM "vt102"
# endif
#else
# ifndef DEFAULT_VCTERM
# define DEFAULT_VCTERM "vt100"
# endif
# ifndef DEFAULT_STERM
# define DEFAULT_STERM "vt100"
# endif
#endif
static int get_env_int(const char *name)
{
@ -130,6 +161,35 @@ int get_terminal_type(const char **type)
return 0;
}
char *get_terminal_default_type(const char *ttyname, int is_serial)
{
if (ttyname) {
#ifdef HAVE_GETTTYNAM
struct ttyent *ent = getttynam(ttyname);
if (ent && ent->ty_type)
return strdup(ent->ty_type);
#endif
#if defined (__s390__) || defined (__s390x__)
/*
* Special terminal on first serial line on a S/390(x) which
* is due legacy reasons a block terminal of type 3270 or
* higher. Whereas the second serial line on a S/390(x) is
* a real character terminal which is compatible with VT220.
*/
if (strcmp(ttyname, "ttyS0") == 0) /* linux/drivers/s390/char/con3215.c */
return strdup(DEFAULT_TTYS0);
else if (strncmp(ttyname, "3270/tty", 8) == 0) /* linux/drivers/s390/char/con3270.c */
return strdup(DEFAULT_TTY32);
else if (strcmp(ttyname, "ttyS1") == 0) /* linux/drivers/s390/char/sclp_vt220.c */
return strdup(DEFAULT_TTYS1);
#endif
}
return strdup(is_serial ? DEFAULT_STERM : DEFAULT_VCTERM);
}
#ifdef TEST_PROGRAM_TTYUTILS
# include <stdlib.h>
int main(void)
@ -138,13 +198,21 @@ int main(void)
int c, l;
if (get_terminal_name(&path, &name, &num) == 0) {
fprintf(stderr, "tty path: %s\n", path);
fprintf(stderr, "tty name: %s\n", name);
fprintf(stderr, "tty number: %s\n", num);
char *term;
fprintf(stderr, "tty path: %s\n", path);
fprintf(stderr, "tty name: %s\n", name);
fprintf(stderr, "tty number: %s\n", num);
fprintf(stderr, "tty term: %s\n", getenv("TERM"));
term = get_terminal_default_type(name, 0);
fprintf(stderr, "tty dflt term: %s\n", term);
free(term);
}
get_terminal_dimension(&c, &l);
fprintf(stderr, "tty cols: %d\n", c);
fprintf(stderr, "tty lines: %d\n", l);
fprintf(stderr, "tty cols: %d\n", c);
fprintf(stderr, "tty lines: %d\n", l);
return EXIT_SUCCESS;

View file

@ -412,12 +412,12 @@ extern int blkdid_probe_is_opal_locked(blkid_probe pr)
__attribute__((nonnull))
__attribute__((warn_unused_result));
extern unsigned char *blkid_probe_get_buffer(blkid_probe pr,
extern const unsigned char *blkid_probe_get_buffer(blkid_probe pr,
uint64_t off, uint64_t len)
__attribute__((nonnull))
__attribute__((warn_unused_result));
extern unsigned char *blkid_probe_get_sector(blkid_probe pr, unsigned int sector)
extern const unsigned char *blkid_probe_get_sector(blkid_probe pr, unsigned int sector)
__attribute__((nonnull))
__attribute__((warn_unused_result));
@ -434,7 +434,7 @@ extern int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id,
__attribute__((nonnull(1)));
/* returns superblock according to 'struct blkid_idmag' */
extern unsigned char *blkid_probe_get_sb_buffer(blkid_probe pr, const struct blkid_idmag *mag, size_t size);
extern const unsigned char *blkid_probe_get_sb_buffer(blkid_probe pr, const struct blkid_idmag *mag, size_t size);
#define blkid_probe_get_sb(_pr, _mag, type) \
((type *) blkid_probe_get_sb_buffer((_pr), _mag, sizeof(type)))

View file

@ -47,7 +47,7 @@ static int probe_bsd_pt(blkid_probe pr, const struct blkid_idmag *mag)
blkid_partition parent;
blkid_partlist ls;
int i, nparts = BSD_MAXPARTITIONS;
unsigned char *data;
const unsigned char *data;
int rc = BLKID_PROBE_NONE;
uint32_t abs_offset = 0;

View file

@ -34,7 +34,7 @@ static const struct dos_subtypes {
{ MBR_MINIX_PARTITION, &minix_pt_idinfo }
};
static inline int is_extended(struct dos_partition *p)
static inline int is_extended(const struct dos_partition *p)
{
return (p->sys_ind == MBR_DOS_EXTENDED_PARTITION ||
p->sys_ind == MBR_W95_EXTENDED_PARTITION ||
@ -46,7 +46,7 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab,
{
blkid_partlist ls = blkid_probe_get_partlist(pr);
uint32_t cur_start = ex_start, cur_size = ex_size;
unsigned char *data;
const unsigned char *data;
int ct_nodata = 0; /* count ext.partitions without data partitions */
int i;
@ -57,7 +57,7 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab,
}
while (1) {
struct dos_partition *p, *p0;
const struct dos_partition *p, *p0;
uint32_t start = 0, size;
if (++ct_nodata > 100)
@ -156,9 +156,9 @@ static inline int is_lvm(blkid_probe pr)
return (v && v->data && strcmp((char *) v->data, "LVM2_member") == 0);
}
static inline int is_empty_mbr(unsigned char *mbr)
static inline int is_empty_mbr(const unsigned char *mbr)
{
struct dos_partition *p = mbr_get_partition(mbr, 0);
const struct dos_partition *p = mbr_get_partition(mbr, 0);
int i, nparts = 0;
for (i = 0; i < 4; i++) {
@ -177,8 +177,8 @@ static int probe_dos_pt(blkid_probe pr,
int ssf;
blkid_parttable tab = NULL;
blkid_partlist ls;
struct dos_partition *p0, *p;
unsigned char *data;
const struct dos_partition *p0, *p;
const unsigned char *data;
uint32_t start, size, id;
char idstr[UUID_STR_LEN];

View file

@ -109,7 +109,7 @@ static inline uint32_t count_crc32(const unsigned char *buf, size_t len,
return (ul_crc32_exclude_offset(~0L, buf, len, exclude_off, exclude_len) ^ ~0L);
}
static inline unsigned char *get_lba_buffer(blkid_probe pr,
static inline const unsigned char *get_lba_buffer(blkid_probe pr,
uint64_t lba, size_t bytes)
{
return blkid_probe_get_buffer(pr,
@ -161,8 +161,8 @@ static int last_lba(blkid_probe pr, uint64_t *lba)
static int is_pmbr_valid(blkid_probe pr, int *has)
{
int flags = blkid_partitions_get_flags(pr);
unsigned char *data;
struct dos_partition *p;
const unsigned char *data;
const struct dos_partition *p;
int i;
if (has)

View file

@ -56,7 +56,7 @@ struct mac_driver_desc {
/* there is more stuff after this that we don't need */
} __attribute__((packed));
static inline unsigned char *get_mac_block(
static inline const unsigned char *get_mac_block(
blkid_probe pr,
uint16_t block_size,
uint32_t num)

View file

@ -17,11 +17,11 @@
static int probe_minix_pt(blkid_probe pr,
const struct blkid_idmag *mag __attribute__((__unused__)))
{
struct dos_partition *p;
const struct dos_partition *p;
blkid_parttable tab = NULL;
blkid_partition parent;
blkid_partlist ls;
unsigned char *data;
const unsigned char *data;
int i;
data = blkid_probe_get_sector(pr, 0);

View file

@ -37,8 +37,8 @@ struct ultrix_disklabel {
static int probe_ultrix_pt(blkid_probe pr,
const struct blkid_idmag *mag __attribute__((__unused__)))
{
unsigned char *data;
struct ultrix_disklabel *l;
const unsigned char *data;
const struct ultrix_disklabel *l;
blkid_parttable tab = NULL;
blkid_partlist ls;
int i;
@ -50,7 +50,7 @@ static int probe_ultrix_pt(blkid_probe pr,
goto nothing;
}
l = (struct ultrix_disklabel *) (data + ULTRIX_OFFSET);
l = (const struct ultrix_disklabel *) (data + ULTRIX_OFFSET);
if (l->pt_magic != ULTRIX_MAGIC || l->pt_valid != 1)
goto nothing;

View file

@ -669,7 +669,7 @@ static int hide_buffer(blkid_probe pr, uint64_t off, uint64_t len)
* Note that @off is offset within probing area, the probing area is defined by
* pr->off and pr->size.
*/
unsigned char *blkid_probe_get_buffer(blkid_probe pr, uint64_t off, uint64_t len)
const unsigned char *blkid_probe_get_buffer(blkid_probe pr, uint64_t off, uint64_t len)
{
struct blkid_bufinfo *bf = NULL;
uint64_t real_off = pr->off + off;
@ -1136,7 +1136,7 @@ int blkid_probe_set_dimension(blkid_probe pr, uint64_t off, uint64_t size)
return 0;
}
unsigned char *blkid_probe_get_sb_buffer(blkid_probe pr, const struct blkid_idmag *mag, size_t size)
const unsigned char *blkid_probe_get_sb_buffer(blkid_probe pr, const struct blkid_idmag *mag, size_t size)
{
uint64_t hint_offset;
@ -1164,7 +1164,7 @@ int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id,
/* try to detect by magic string */
while(mag && mag->magic) {
unsigned char *buf;
const unsigned char *buf;
uint64_t kboff;
uint64_t hint_offset;
@ -1690,7 +1690,7 @@ done:
}
/* same sa blkid_probe_get_buffer() but works with 512-sectors */
unsigned char *blkid_probe_get_sector(blkid_probe pr, unsigned int sector)
const unsigned char *blkid_probe_get_sector(blkid_probe pr, unsigned int sector)
{
return blkid_probe_get_buffer(pr, ((uint64_t) sector) << 9, 0x200);
}

View file

@ -10,6 +10,7 @@
#include <stddef.h>
#include <stdio.h>
#include <inttypes.h>
#include "superblocks.h"
#include "crc32c.h"
@ -184,9 +185,18 @@ static int probe_bcache (blkid_probe pr, const struct blkid_idmag *mag)
if (le64_to_cpu(bcs->offset) != BCACHE_SB_OFF / 512)
return BLKID_PROBE_NONE;
if (blkid_probe_sprintf_version(pr, "%"PRIu64, le64_to_cpu(bcs->version)) < 0)
return BLKID_PROBE_NONE;
if (blkid_probe_set_uuid(pr, bcs->uuid) < 0)
return BLKID_PROBE_NONE;
if (blkid_probe_set_label(pr, bcs->label, sizeof(bcs->label)) < 0)
return BLKID_PROBE_NONE;
if (blkid_probe_set_block_size(pr, le16_to_cpu(bcs->block_size) * 512))
return BLKID_PROBE_NONE;
blkid_probe_set_wiper(pr, 0, BCACHE_SB_OFF);
return BLKID_PROBE_OK;
@ -214,7 +224,7 @@ static void probe_bcachefs_sb_members(blkid_probe pr,
blkid_probe_set_fssize(pr, sectors * BCACHEFS_SECTOR_SIZE);
}
static int is_within_range(void *start, uint64_t size, void *end)
static int is_within_range(const void *start, uint64_t size, const void *end)
{
ptrdiff_t diff;
@ -226,9 +236,9 @@ static int is_within_range(void *start, uint64_t size, void *end)
}
static void probe_bcachefs_sb_fields(blkid_probe pr, const struct bcachefs_super_block *bcs,
unsigned char *sb_start, unsigned char *sb_end)
const unsigned char *sb_start, const unsigned char *sb_end)
{
unsigned char *field_addr = sb_start + BCACHEFS_SB_FIELDS_OFF;
const unsigned char *field_addr = sb_start + BCACHEFS_SB_FIELDS_OFF;
while (1) {
struct bcachefs_sb_field *field = (struct bcachefs_sb_field *) field_addr;
@ -258,10 +268,10 @@ static void probe_bcachefs_sb_fields(blkid_probe pr, const struct bcachefs_super
}
static int bcachefs_validate_checksum(blkid_probe pr, const struct bcachefs_super_block *bcs,
unsigned char *sb, unsigned char *sb_end)
const unsigned char *sb, const unsigned char *sb_end)
{
uint8_t checksum_type = be64_to_cpu(bcs->flags[0]) >> 58;
unsigned char *checksummed_data_start = sb + sizeof(bcs->csum);
const unsigned char *checksummed_data_start = sb + sizeof(bcs->csum);
size_t checksummed_data_size = sb_end - checksummed_data_start;
switch (checksum_type) {
@ -288,7 +298,7 @@ static int bcachefs_validate_checksum(blkid_probe pr, const struct bcachefs_supe
static int probe_bcachefs(blkid_probe pr, const struct blkid_idmag *mag)
{
struct bcachefs_super_block *bcs;
unsigned char *sb, *sb_end;
const unsigned char *sb, *sb_end;
uint64_t sb_size, blocksize;
bcs = blkid_probe_get_sb(pr, mag, struct bcachefs_super_block);

View file

@ -122,7 +122,7 @@ struct bplustree_node {
char name[0];
} __attribute__((packed));
static unsigned char *get_block_run(blkid_probe pr, const struct befs_super_block *bs,
static const unsigned char *get_block_run(blkid_probe pr, const struct befs_super_block *bs,
const struct block_run *br, int fs_le)
{
return blkid_probe_get_buffer(pr,
@ -135,7 +135,7 @@ static unsigned char *get_block_run(blkid_probe pr, const struct befs_super_bloc
<< FS32_TO_CPU(bs->block_shift, fs_le));
}
static unsigned char *get_custom_block_run(blkid_probe pr,
static const unsigned char *get_custom_block_run(blkid_probe pr,
const struct befs_super_block *bs,
const struct block_run *br,
int64_t offset, uint32_t length, int fs_le)
@ -154,7 +154,7 @@ static unsigned char *get_custom_block_run(blkid_probe pr,
length);
}
static unsigned char *get_tree_node(blkid_probe pr, const struct befs_super_block *bs,
static const unsigned char *get_tree_node(blkid_probe pr, const struct befs_super_block *bs,
const struct data_stream *ds,
int64_t start, uint32_t length, int fs_le)
{

View file

@ -55,7 +55,7 @@ static int cramfs_verify_csum(blkid_probe pr, const struct blkid_idmag *mag,
struct cramfs_super *cs, int le)
{
uint32_t crc, expected, csummed_size;
unsigned char *csummed;
const unsigned char *csummed;
expected = cfs32_to_cpu(le, cs->info.crc);
csummed_size = cfs32_to_cpu(le, cs->size);
@ -67,9 +67,10 @@ static int cramfs_verify_csum(blkid_probe pr, const struct blkid_idmag *mag,
csummed = blkid_probe_get_sb_buffer(pr, mag, csummed_size);
if (!csummed)
return 0;
memset(csummed + offsetof(struct cramfs_super, info.crc), 0, sizeof(uint32_t));
crc = ~ul_crc32(~0LL, csummed, csummed_size);
crc = ~ul_crc32_exclude_offset(~0LL, csummed, csummed_size,
offsetof(struct cramfs_super, info.crc),
sizeof_member(struct cramfs_super, info.crc));
return blkid_probe_verify_csum(pr, crc, expected);
}

View file

@ -106,7 +106,7 @@ static int probe_ddf(blkid_probe pr,
if (lba > 0) {
/* check primary header */
unsigned char *buf;
const unsigned char *buf;
buf = blkid_probe_get_buffer(pr,
lba << 9, sizeof(ddf->signature));

View file

@ -46,7 +46,7 @@ static int erofs_verify_checksum(blkid_probe pr, const struct blkid_idmag *mag,
{
uint32_t expected, csum;
size_t csummed_size;
unsigned char *csummed;
const unsigned char *csummed;
if (!(le32_to_cpu(sb->feature_compat) & EROFS_FEATURE_SB_CSUM))
return 1;

View file

@ -119,7 +119,7 @@ static struct exfat_entry_label *find_label(blkid_probe pr,
}
/* From https://docs.microsoft.com/en-us/windows/win32/fileio/exfat-specification#34-main-and-backup-boot-checksum-sub-regions */
static uint32_t exfat_boot_checksum(unsigned char *sectors,
static uint32_t exfat_boot_checksum(const unsigned char *sectors,
size_t sector_size)
{
uint32_t n_bytes = sector_size * 11;
@ -141,7 +141,7 @@ static int exfat_validate_checksum(blkid_probe pr,
{
size_t sector_size = BLOCK_SIZE(sb);
/* 11 sectors will be checksummed, the 12th contains the expected */
unsigned char *data = blkid_probe_get_buffer(pr, 0, sector_size * 12);
const unsigned char *data = blkid_probe_get_buffer(pr, 0, sector_size * 12);
if (!data)
return 0;

View file

@ -67,14 +67,14 @@ static int f2fs_validate_checksum(blkid_probe pr, size_t sb_off,
if (csum_off + sizeof(uint32_t) > 4096)
return 0;
unsigned char *csum_data = blkid_probe_get_buffer(pr,
const unsigned char *csum_data = blkid_probe_get_buffer(pr,
sb_off + csum_off, sizeof(uint32_t));
if (!csum_data)
return 0;
uint32_t expected = le32_to_cpu(*(uint32_t *) csum_data);
unsigned char *csummed = blkid_probe_get_buffer(pr, sb_off, csum_off);
const unsigned char *csummed = blkid_probe_get_buffer(pr, sb_off, csum_off);
if (!csummed)
return 0;

View file

@ -183,11 +183,11 @@ static int probe_hfs(blkid_probe pr, const struct blkid_idmag *mag)
static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag)
{
struct hfsplus_extent extents[HFSPLUS_EXTENT_COUNT];
struct hfsplus_bnode_descriptor *descr;
struct hfsplus_bheader_record *bnode;
struct hfsplus_catalog_key *key;
struct hfsplus_vol_header *hfsplus;
struct hfs_mdb *sbd;
const struct hfsplus_bnode_descriptor *descr;
const struct hfsplus_bheader_record *bnode;
const struct hfsplus_catalog_key *key;
const struct hfsplus_vol_header *hfsplus;
const struct hfs_mdb *sbd;
unsigned int alloc_block_size;
unsigned int alloc_first_block;
unsigned int embed_first_block;
@ -203,7 +203,7 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag)
unsigned int leaf_block;
int ext;
uint64_t leaf_off;
unsigned char *buf;
const unsigned char *buf;
sbd = blkid_probe_get_sb(pr, mag, struct hfs_mdb);
if (!sbd)
@ -225,7 +225,7 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag)
buf = blkid_probe_get_buffer(pr,
off + (mag->kboff * 1024),
sizeof(struct hfsplus_vol_header));
hfsplus = (struct hfsplus_vol_header *) buf;
hfsplus = (const struct hfsplus_vol_header *) buf;
} else
hfsplus = blkid_probe_get_sb(pr, mag,

View file

@ -232,7 +232,7 @@ static int probe_iso9660(blkid_probe pr, const struct blkid_idmag *mag)
return probe_iso9660_hsfs(pr, mag);
for (i = 0, off += ISO_SUPERBLOCK_OFFSET; i < ISO_VD_MAX && (!boot || !pvd || !joliet); i++, off += ISO_SECTOR_SIZE) {
unsigned char *desc =
const unsigned char *desc =
blkid_probe_get_buffer(pr,
off,
max(sizeof(struct boot_record),

View file

@ -187,15 +187,14 @@ static int raid1_verify_csum(blkid_probe pr, off_t off,
{
size_t csummed_size = sizeof(struct mdp1_super_block)
+ le32_to_cpu(mdp1->max_dev) * sizeof(mdp1->dev_roles[0]);
unsigned char *csummed = blkid_probe_get_buffer(pr, off, csummed_size);
const unsigned char *csummed = blkid_probe_get_buffer(pr, off, csummed_size);
if (!csummed)
return 1;
memset(csummed + offsetof(struct mdp1_super_block, sb_csum), 0,
sizeof(mdp1->sb_csum));
uint64_t csum = 0;
csum -= le32_to_cpu(*(uint32_t *) (csummed + offsetof(struct mdp1_super_block, sb_csum)));
while (csummed_size >= 4) {
csum += le32_to_cpu(*(uint32_t *) csummed);
csummed_size -= 4;

View file

@ -76,7 +76,7 @@ static int probe_lvm2(blkid_probe pr, const struct blkid_idmag *mag)
int sector = mag->kboff << 1;
struct lvm2_pv_label_header *label;
char uuid[LVM2_ID_LEN + 7];
unsigned char *buf;
const unsigned char *buf;
buf = blkid_probe_get_buffer(pr,
mag->kboff << 10,

View file

@ -74,7 +74,7 @@ static int get_minix_version(const unsigned char *data, int *other_endian)
static int probe_minix(blkid_probe pr,
const struct blkid_idmag *mag __attribute__((__unused__)))
{
unsigned char *ext;
const unsigned char *ext;
const unsigned char *data;
int version = 0, swabme = 0;
unsigned long zones, ninodes, imaps, zmaps;

View file

@ -80,13 +80,13 @@ struct file_attribute {
static int __probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag, int save_info)
{
struct ntfs_super_block *ns;
struct master_file_table_record *mft;
const struct ntfs_super_block *ns;
const struct master_file_table_record *mft;
uint32_t sectors_per_cluster, mft_record_size;
uint16_t sector_size;
uint64_t nr_clusters, off, attr_off;
unsigned char *buf_mft;
const unsigned char *buf_mft;
ns = blkid_probe_get_sb(pr, mag, struct ntfs_super_block);
if (!ns)

View file

@ -100,7 +100,7 @@ struct oracle_asm_disk_label {
static int probe_ocfs(blkid_probe pr, const struct blkid_idmag *mag)
{
unsigned char *buf;
const unsigned char *buf;
struct ocfs_volume_header ovh;
struct ocfs_volume_label ovl;
uint32_t maj, min;

View file

@ -29,7 +29,7 @@ static int romfs_verify_csum(blkid_probe pr, const struct blkid_idmag *mag,
{
uint32_t csummed_size = min((uint32_t) 512,
be32_to_cpu(ros->ros_full_size));
unsigned char *csummed;
const unsigned char *csummed;
uint32_t csum;
if (csummed_size % sizeof(uint32_t) != 0)

View file

@ -49,7 +49,7 @@ const char STRATIS_MAGIC[] = "!Stra0tis\x86\xff\x02^\x41rh";
#define MAGIC_OFFSET_COPY_1 (FIRST_COPY_OFFSET + _MAGIC_OFFSET)
#define MAGIC_OFFSET_COPY_2 (SECOND_COPY_OFFSET + _MAGIC_OFFSET)
static int stratis_valid_sb(uint8_t *p)
static int stratis_valid_sb(const uint8_t *p)
{
const struct stratis_sb *stratis = (const struct stratis_sb *)p;
uint32_t crc = 0;
@ -83,7 +83,7 @@ static int probe_stratis(blkid_probe pr,
const struct blkid_idmag *mag __attribute__((__unused__)))
{
const struct stratis_sb *stratis = NULL;
uint8_t *buf = blkid_probe_get_buffer(pr, 0, SB_AREA_SIZE);
const uint8_t *buf = blkid_probe_get_buffer(pr, 0, SB_AREA_SIZE);
unsigned char uuid[STRATIS_UUID_STR_LEN];
if (!buf)

View file

@ -91,7 +91,7 @@ static int swap_set_info(blkid_probe pr, const struct blkid_idmag *mag,
static int probe_swap(blkid_probe pr, const struct blkid_idmag *mag)
{
unsigned char *buf;
const unsigned char *buf;
if (!mag)
return 1;

View file

@ -351,7 +351,7 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
version = "FAT16";
} else if (vs->vs_fat32_length) {
unsigned char *buf;
const unsigned char *buf;
uint16_t fsinfo_sect;
int maxloop = 100;

View file

@ -49,7 +49,7 @@ static int probe_vmfs_fs(blkid_probe pr, const struct blkid_idmag *mag)
static int probe_vmfs_volume(blkid_probe pr, const struct blkid_idmag *mag)
{
struct vmfs_volume_info *header;
unsigned char *lvm_uuid;
const unsigned char *lvm_uuid;
header = blkid_probe_get_sb(pr, mag, struct vmfs_volume_info);
if (header == NULL)

View file

@ -206,7 +206,7 @@ static int xfs_verify_sb(struct xfs_super_block *ondisk, blkid_probe pr,
if ((sbp->sb_versionnum & 0x0f) == 5) {
uint32_t expected, crc;
unsigned char *csummed;
const unsigned char *csummed;
if (!(sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT))
return 0;
@ -331,7 +331,7 @@ static int probe_xfs_log(blkid_probe pr,
{
int i;
struct xlog_rec_header *rhead;
unsigned char *buf;
const unsigned char *buf;
buf = blkid_probe_get_buffer(pr, 0, 256*1024);
if (!buf)

View file

@ -71,13 +71,13 @@ struct nvlist {
struct nvpair nvl_nvpair;
};
static void zfs_process_value(blkid_probe pr, char *name, size_t namelen,
void *value, size_t max_value_size, unsigned directory_level)
static void zfs_process_value(blkid_probe pr, const char *name, size_t namelen,
const void *value, size_t max_value_size, unsigned directory_level)
{
if (strncmp(name, "name", namelen) == 0 &&
sizeof(struct nvstring) <= max_value_size &&
!directory_level) {
struct nvstring *nvs = value;
const struct nvstring *nvs = value;
uint32_t nvs_type = be32_to_cpu(nvs->nvs_type);
uint32_t nvs_strlen = be32_to_cpu(nvs->nvs_strlen);
@ -92,7 +92,7 @@ static void zfs_process_value(blkid_probe pr, char *name, size_t namelen,
} else if (strncmp(name, "guid", namelen) == 0 &&
sizeof(struct nvuint64) <= max_value_size &&
!directory_level) {
struct nvuint64 *nvu = value;
const struct nvuint64 *nvu = value;
uint32_t nvu_type = be32_to_cpu(nvu->nvu_type);
uint64_t nvu_value;
@ -110,7 +110,7 @@ static void zfs_process_value(blkid_probe pr, char *name, size_t namelen,
} else if (strncmp(name, "pool_guid", namelen) == 0 &&
sizeof(struct nvuint64) <= max_value_size &&
!directory_level) {
struct nvuint64 *nvu = value;
const struct nvuint64 *nvu = value;
uint32_t nvu_type = be32_to_cpu(nvu->nvu_type);
uint64_t nvu_value;
@ -128,7 +128,7 @@ static void zfs_process_value(blkid_probe pr, char *name, size_t namelen,
"%"PRIu64, nvu_value);
} else if (strncmp(name, "ashift", namelen) == 0 &&
sizeof(struct nvuint64) <= max_value_size) {
struct nvuint64 *nvu = value;
const struct nvuint64 *nvu = value;
uint32_t nvu_type = be32_to_cpu(nvu->nvu_type);
uint64_t nvu_value;
@ -147,9 +147,9 @@ static void zfs_process_value(blkid_probe pr, char *name, size_t namelen,
static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
{
unsigned char *p;
struct nvlist *nvl;
struct nvpair *nvp;
const unsigned char *p;
const struct nvlist *nvl;
const struct nvpair *nvp;
size_t left = 4096;
unsigned directory_level = 0;
@ -166,16 +166,16 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
DBG(LOWPROBE, ul_debug("zfs_extract: nvlist offset %jd",
(intmax_t)offset));
nvl = (struct nvlist *) p;
nvl = (const struct nvlist *) p;
nvp = &nvl->nvl_nvpair;
left -= (unsigned char *)nvp - p; /* Already used up 12 bytes */
left -= (const unsigned char *)nvp - p; /* Already used up 12 bytes */
while (left > sizeof(*nvp)) {
uint32_t nvp_size = be32_to_cpu(nvp->nvp_size);
uint32_t nvp_namelen = be32_to_cpu(nvp->nvp_namelen);
uint64_t namesize = ((uint64_t)nvp_namelen + 3) & ~3;
size_t max_value_size;
void *value;
const void *value;
if (!nvp->nvp_size) {
if (!directory_level)
@ -201,7 +201,7 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
value = nvp->nvp_name + namesize;
if (sizeof(struct nvdirectory) <= max_value_size) {
struct nvdirectory *nvu = value;
const struct nvdirectory *nvu = value;
if (be32_to_cpu(nvu->nvd_type) == DATA_TYPE_DIRECTORY) {
nvp_size = sizeof(*nvp) + namesize + sizeof(*nvu);
directory_level++;
@ -259,7 +259,7 @@ static int probe_zfs(blkid_probe pr,
struct zfs_uberblock *ub = NULL;
loff_t offset = 0, ub_offset = 0;
int label_no, found = 0, found_in_label;
void *label;
const void *label;
loff_t blk_align = (pr->size % (256 * 1024ULL));
DBG(PROBE, ul_debug("probe_zfs"));

View file

@ -26,7 +26,7 @@
static const struct topology_val {
/* /sys/dev/block/<maj>:<min>/<ATTR> */
const char *attr;
const char * const attr;
/* functions to set probing result */
int (*set_ulong)(blkid_probe, unsigned long);

View file

@ -30,7 +30,7 @@
*
*/
static const char *bsd_dktypenames[] = {
static const char * const bsd_dktypenames[] = {
"unknown",
"SMD",
"MSCP",

View file

@ -792,7 +792,7 @@ static void get_partition_table_geometry(struct fdisk_context *cxt,
unsigned char *bufp = cxt->firstsector;
struct { unsigned int c, h, o, v; } t[8];
unsigned int n1, n2, n3, n4, n5, n6;
struct dos_partition *p;
const struct dos_partition *p;
unsigned int c, h, s, l;
unsigned int hh, ss;
unsigned int sects;

View file

@ -75,6 +75,7 @@ int fdisk_set_wipe_area(struct fdisk_context *cxt,
free(wp);
return 1;
}
DBG(WIPE, ul_debug("not requested"));
return 0;
}

View file

@ -2,6 +2,7 @@ if BUILD_LIBMOUNT
include libmount/src/Makemodule.am
include libmount/python/Makemodule.am
include libmount/samples/Makemodule.am
if ENABLE_GTK_DOC
# Docs uses separate Makefiles

View file

@ -117,6 +117,7 @@ libmount_tests = [
'context',
'lock',
'optstr',
'optlist',
'tab',
'tab_diff',
'monitor',

View file

@ -1175,43 +1175,17 @@ static PyObject *Context_repr(ContextObjext *self)
PyTypeObject ContextType = {
PyVarObject_HEAD_INIT(NULL, 0)
"libmount.Context", /*tp_name*/
sizeof(ContextObjext), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)Context_dealloc, /*tp_dealloc*/
0, /*tp_print*/
NULL, /*tp_getattr*/
NULL, /*tp_setattr*/
NULL, /*tp_compare*/
(reprfunc) Context_repr,
NULL, /*tp_as_number*/
NULL, /*tp_as_sequence*/
NULL, /*tp_as_mapping*/
NULL, /*tp_hash */
NULL, /*tp_call*/
NULL, /*tp_str*/
NULL, /*tp_getattro*/
NULL, /*tp_setattro*/
NULL, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
Context_HELP, /* tp_doc */
NULL, /* tp_traverse */
NULL, /* tp_clear */
NULL, /* tp_richcompare */
0, /* tp_weaklistoffset */
NULL, /* tp_iter */
NULL, /* tp_iternext */
Context_methods, /* tp_methods */
Context_members, /* tp_members */
Context_getseters, /* tp_getset */
NULL, /* tp_base */
NULL, /* tp_dict */
NULL, /* tp_descr_get */
NULL, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)Context_init, /* tp_init */
NULL, /* tp_alloc */
Context_new, /* tp_new */
.tp_name = "libmount.Context",
.tp_basicsize = sizeof(ContextObjext),
.tp_dealloc = (destructor)Context_dealloc,
.tp_repr = (reprfunc) Context_repr,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = Context_HELP,
.tp_methods = Context_methods,
.tp_members = Context_members,
.tp_getset = Context_getseters,
.tp_init = (initproc)Context_init,
.tp_new = Context_new,
};
void Context_AddModuleObject(PyObject *mod)

View file

@ -832,43 +832,17 @@ static PyObject *Fs_copy_fs(FsObject *self, PyObject *args, PyObject *kwds)
PyTypeObject FsType = {
PyVarObject_HEAD_INIT(NULL, 0)
"libmount.Fs", /*tp_name*/
sizeof(FsObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)Fs_destructor, /*tp_dealloc*/
0, /*tp_print*/
NULL, /*tp_getattr*/
NULL, /*tp_setattr*/
NULL, /*tp_compare*/
(reprfunc)Fs_repr, /*tp_repr*/
NULL, /*tp_as_number*/
NULL, /*tp_as_sequence*/
NULL, /*tp_as_mapping*/
NULL, /*tp_hash */
NULL, /*tp_call*/
NULL, /*tp_str*/
NULL, /*tp_getattro*/
NULL, /*tp_setattro*/
NULL, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
Fs_HELP, /* tp_doc */
NULL, /* tp_traverse */
NULL, /* tp_clear */
NULL, /* tp_richcompare */
0, /* tp_weaklistoffset */
NULL, /* tp_iter */
NULL, /* tp_iternext */
Fs_methods, /* tp_methods */
Fs_members, /* tp_members */
Fs_getseters, /* tp_getset */
NULL, /* tp_base */
NULL, /* tp_dict */
NULL, /* tp_descr_get */
NULL, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)Fs_init, /* tp_init */
NULL, /* tp_alloc */
Fs_new, /* tp_new */
.tp_name = "libmount.Fs",
.tp_basicsize = sizeof(FsObject),
.tp_dealloc = (destructor)Fs_destructor,
.tp_repr = (reprfunc)Fs_repr,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = Fs_HELP,
.tp_methods = Fs_methods,
.tp_members = Fs_members,
.tp_getset = Fs_getseters,
.tp_init = (initproc)Fs_init,
.tp_new = Fs_new,
};
void FS_AddModuleObject(PyObject *mod)

View file

@ -731,43 +731,17 @@ static PyObject *Table_repr(TableObject *self)
PyTypeObject TableType = {
PyVarObject_HEAD_INIT(NULL, 0)
"libmount.Table", /*tp_name*/
sizeof(TableObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)Table_destructor, /*tp_dealloc*/
0, /*tp_print*/
NULL, /*tp_getattr*/
NULL, /*tp_setattr*/
NULL, /*tp_compare*/
(reprfunc) Table_repr, /*tp_repr*/
NULL, /*tp_as_number*/
NULL, /*tp_as_sequence*/
NULL, /*tp_as_mapping*/
NULL, /*tp_hash */
NULL, /*tp_call*/
NULL, /*tp_str*/
NULL, /*tp_getattro*/
NULL, /*tp_setattro*/
NULL, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
Table_HELP, /* tp_doc */
NULL, /* tp_traverse */
NULL, /* tp_clear */
NULL, /* tp_richcompare */
0, /* tp_weaklistoffset */
NULL, /* tp_iter */
NULL, /* tp_iternext */
Table_methods, /* tp_methods */
Table_members, /* tp_members */
Table_getseters, /* tp_getset */
NULL, /* tp_base */
NULL, /* tp_dict */
NULL, /* tp_descr_get */
NULL, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)Table_init, /* tp_init */
NULL, /* tp_alloc */
Table_new, /* tp_new */
.tp_name = "libmount.Table",
.tp_basicsize = sizeof(TableObject),
.tp_dealloc = (destructor)Table_destructor,
.tp_repr = (reprfunc) Table_repr,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = Table_HELP,
.tp_methods = Table_methods,
.tp_members = Table_members,
.tp_getset = Table_getseters,
.tp_init = (initproc)Table_init,
.tp_new = Table_new,
};
void Table_AddModuleObject(PyObject *mod)

View file

@ -0,0 +1,12 @@
check_PROGRAMS += \
sample-mount-overwrite
sample_mount_cflags = $(AM_CFLAGS) $(NO_UNUSED_WARN_CFLAGS) \
-I$(ul_libmount_incdir)
sample_mount_ldadd = libmount.la $(LDADD)
sample_mount_overwrite_SOURCES = libmount/samples/overwrite.c
sample_mount_overwrite_LDADD = $(sample_mount_ldadd)
sample_mount_overwrite_CFLAGS = $(sample_mount_cflags)

View file

@ -0,0 +1,58 @@
/*
* Copyright (C) 2023 Karel Zak <kzak@redhat.com>
*
* This file may be redistributed under the terms of the
* GNU Lesser General Public License.
*
*
* This sample reads the mountpoint entry from /etc/fstab and mounts it to the
* different (on the command line specified) mountpoint. The mount options
* settings are read from fstab.
*/
#include <stdlib.h>
#include "c.h"
#include "libmount.h"
int main(int argc, char *argv[])
{
char *target, *fstab_target;
struct libmnt_table *tab;
struct libmnt_fs *fs;
struct libmnt_context *cxt;
int rc;
if (argc != 3)
errx(EXIT_FAILURE, "usage: %s <mnt-from-fstab> <target>",
program_invocation_short_name);
fstab_target = argv[1];
target = argv[2];
printf("Mounting %s from fstab to %s\n", fstab_target, target);
tab = mnt_new_table_from_file("/etc/fstab");
if (!tab)
err(EXIT_FAILURE, "failed to parse fstab");
fs = mnt_table_find_target(tab, fstab_target, MNT_ITER_FORWARD);
if (!fs)
err(EXIT_FAILURE, "cannot found %s in fstab", argv[1]);
cxt = mnt_new_context();
if (!cxt)
err(EXIT_FAILURE, "cannot allocate context");
mnt_context_set_fs(cxt, fs);
mnt_context_set_target(cxt, target);
rc = mnt_context_mount(cxt);
printf("Done: rc=%d status=%d\n", rc, mnt_context_get_status(cxt));
mnt_free_context(cxt);
mnt_unref_table(tab);
return rc == 0 && mnt_context_get_status(cxt) == 1 ? EXIT_SUCCESS : EXIT_FAILURE;
}

View file

@ -1560,7 +1560,6 @@ int mnt_context_get_mount_excode(
*/
syserr = mnt_context_get_syscall_errno(cxt);
switch(syserr) {
case EPERM:
if (!buf)
@ -1603,10 +1602,8 @@ int mnt_context_get_mount_excode(
return MNT_EX_SUCCESS;
if (buf)
snprintf(buf, bufsz, _("special device %s does not exist"), src);
} else if (buf) {
errno = syserr;
snprintf(buf, bufsz, _("mount(2) system call failed: %m"));
}
} else
goto generic_error;
break;
case ENOTDIR:
@ -1619,10 +1616,8 @@ int mnt_context_get_mount_excode(
if (buf)
snprintf(buf, bufsz, _("special device %s does not exist "
"(a path prefix is not a directory)"), src);
} else if (buf) {
errno = syserr;
snprintf(buf, bufsz, _("mount(2) system call failed: %m"));
}
} else
goto generic_error;
break;
case EINVAL:
@ -1703,10 +1698,8 @@ int mnt_context_get_mount_excode(
snprintf(buf, bufsz, _("cannot remount %s read-write, is write-protected"), src);
else if (mflags & MS_BIND)
snprintf(buf, bufsz, _("bind %s failed"), src);
else {
errno = syserr;
snprintf(buf, bufsz, _("mount(2) system call failed: %m"));
}
else
goto generic_error;
break;
case ENOMEDIUM:
@ -1726,9 +1719,11 @@ int mnt_context_get_mount_excode(
/* fallthrough */
default:
generic_error:
if (buf) {
errno = syserr;
snprintf(buf, bufsz, _("mount(2) system call failed: %m"));
snprintf(buf, bufsz, _("%s system call failed: %m"),
cxt->syscall_name ? : "mount");
}
break;
}

View file

@ -46,6 +46,7 @@
#include "mountP.h"
#include "fileutils.h" /* statx() fallback */
#include "mount-api-utils.h"
#include "linux_version.h"
#include <inttypes.h>
@ -462,7 +463,7 @@ static int hook_set_propagation(struct libmnt_context *cxt,
(uint64_t) attr.propagation));
rc = mount_setattr(api->fd_tree, "", flgs, &attr, sizeof(attr));
set_syscall_status(cxt, "move_setattr", rc == 0);
set_syscall_status(cxt, "mount_setattr", rc == 0);
if (rc && errno == EINVAL)
return -MNT_ERR_APPLYFLAGS;
@ -719,6 +720,13 @@ static int hook_prepare(struct libmnt_context *cxt,
if (!rc
&& cxt->helper == NULL
&& (set != 0 || clr != 0 || (flags & MS_REMOUNT))) {
/*
* mount_setattr() supported, but not usable for remount
* https://github.com/torvalds/linux/commit/dd8b477f9a3d8edb136207acb3652e1a34a661b7
*/
if (get_linux_version() < KERNEL_VERSION(5, 14, 0))
goto enosys;
if (!mount_setattr_is_supported())
goto enosys;

View file

@ -188,7 +188,8 @@ enum {
/**
* MNT_ERR_APPLYFLAGS:
*
* failed to apply MS_PROPAGATION flags
* failed to apply MS_PROPAGATION flags, and MOUNT_ATTR_* attributes for
* mount_setattr(2)
*/
#define MNT_ERR_APPLYFLAGS 5005
/**

View file

@ -1386,6 +1386,35 @@ static int test_get_flg(struct libmnt_test *ts, int argc, char *argv[])
return rc;
}
static int test_split(struct libmnt_test *ts, int argc, char *argv[])
{
struct libmnt_optlist *ol;
int rc;
struct libmnt_iter itr;
struct libmnt_opt *opt;
const char *name, *value;
if (argc != 2)
return -EINVAL;
rc = mk_optlist(&ol, argv[1]);
if (rc)
goto done;
mnt_reset_iter(&itr, MNT_ITER_FORWARD);
while (mnt_optlist_next_opt(ol, &itr, &opt) == 0) {
name = mnt_opt_get_name(opt);
value = mnt_opt_get_value(opt);
printf("%s = %s\n", name, value ?: "(null)");
}
done:
mnt_unref_optlist(ol);
return rc;
}
int main(int argc, char *argv[])
{
struct libmnt_test tss[] = {
@ -1396,6 +1425,7 @@ int main(int argc, char *argv[])
{ "--set-flg", test_set_flg, "<list> <flg> linux|user set to the list" },
{ "--get-str", test_get_str, "<list> [linux|user] all options in string" },
{ "--get-flg", test_get_flg, "<list> linux|user all options by flags" },
{ "--split", test_split, "<list> split options into key-value pairs"},
{ NULL }
};

View file

@ -148,6 +148,14 @@ _/etc/pam.d/remote_,
_/etc/hushlogins_,
_$HOME/.hushlogin_
== CREDENTIALS
*login* supports configuration via systemd credentials (see https://systemd.io/CREDENTIALS/). *login* reads the following systemd credentials:
*login.noauth* (boolean)::
If set, configures *login* to skip login authentication, similarly to the *-f* option.
== BUGS
The undocumented BSD *-r* option is not supported. This may be required by some *rlogind*(8) programs.

View file

@ -46,6 +46,7 @@
#include <grp.h>
#include <pwd.h>
#include <utmpx.h>
#include <path.h>
#ifdef HAVE_LASTLOG_H
# include <lastlog.h>
@ -1287,6 +1288,38 @@ static void __attribute__((__noreturn__)) usage(void)
exit(EXIT_SUCCESS);
}
static void load_credentials(struct login_context *cxt) {
char *env;
DIR *dir;
struct dirent *d;
struct path_cxt *pc;
env = safe_getenv("CREDENTIALS_DIRECTORY");
if (!env)
return;
pc = ul_new_path("%s", env);
if (!pc) {
syslog(LOG_WARNING, _("failed to initialize path context"));
return;
}
dir = ul_path_opendir(pc, NULL);
if (!dir) {
syslog(LOG_WARNING, _("failed to open credentials directory"));
return;
}
while ((d = xreaddir(dir))) {
char str[32] = { 0 };
if (strcmp(d->d_name, "login.noauth") == 0
&& ul_path_read_buffer(pc, str, sizeof(str), d->d_name) > 0
&& *str && strcmp(str, "yes") == 0)
cxt->noauth = 1;
}
}
static void initialize(int argc, char **argv, struct login_context *cxt)
{
int c;
@ -1318,6 +1351,8 @@ static void initialize(int argc, char **argv, struct login_context *cxt)
setpriority(PRIO_PROCESS, 0, 0);
process_title_init(argc, argv);
load_credentials(cxt);
while ((c = getopt_long(argc, argv, "fHh:pV", longopts, NULL)) != -1)
switch (c) {
case 'f':

View file

@ -64,7 +64,7 @@
* column description
*/
struct lslogins_coldesc {
const char *name;
const char * const name;
const char *help;
const char *pretty_name;

View file

@ -270,23 +270,21 @@ static void tcfinal(struct console *con)
{
struct termios *tio = &con->tio;
const int fd = con->fd;
char *term, *ttyname = NULL;
if (con->flags & CON_EIO)
return;
if ((con->flags & CON_SERIAL) == 0) {
xsetenv("TERM", "linux", 0);
return;
}
if (con->flags & CON_NOTTY) {
xsetenv("TERM", "dumb", 0);
return;
if (con->tty)
ttyname = strncmp(con->tty, "/dev/", 5) == 0 ?
con->tty + 5 : con->tty;
term = get_terminal_default_type(ttyname, con->flags & CON_SERIAL);
if (term) {
xsetenv("TERM", term, 0);
free(term);
}
#if defined (__s390__) || defined (__s390x__)
xsetenv("TERM", "dumb", 0);
#else
xsetenv("TERM", "vt102", 0);
#endif
if (!(con->flags & CON_SERIAL) || (con->flags & CON_NOTTY))
return;
tio->c_iflag |= (IXON | IXOFF);
tio->c_lflag |= (ICANON | ISIG | ECHO|ECHOE|ECHOK|ECHOKE);
tio->c_oflag |= OPOST;

View file

@ -108,7 +108,7 @@ static void print_utline(struct utmpx *ut, FILE *out)
addr_string = inet_ntop(AF_INET, &(ut->ut_addr_v6), buffer, sizeof(buffer));
tv.tv_sec = ut->ut_tv.tv_sec;
tv.tv_usec = ut->ut_tv.tv_usec;
tv.tv_usec = ut->ut_tv.tv_usec < (int32_t) USEC_PER_SEC ? ut->ut_tv.tv_usec : 0;
if (strtimeval_iso(&tv, ISO_TIMESTAMP_COMMA_GT, time_string,
sizeof(time_string)) != 0)

View file

@ -3,6 +3,7 @@ project('util-linux', 'c',
meson_version: '>=0.57.0',
license : 'GPLv2+')
fs = import('fs')
pkgconfig = import('pkgconfig')
libblkid_version = '1.1.0'
@ -2886,6 +2887,40 @@ if LINUX and conf.get('HAVE_PIDFD_OPEN') != false
endif
endif
syscalls_h = custom_target('syscalls.h',
input : 'tools/all_syscalls',
output : 'syscalls.h',
command : ['bash', '@INPUT@', cc.cmd_array()],
)
if cc.compiles(fs.read('include/audit-arch.h'), name : 'has AUDIT_ARCH_NATIVE')
exe = executable(
'enosys',
'misc-utils/enosys.c', syscalls_h,
include_directories : includes,
link_with : [lib_common],
install_dir : usrbin_exec_dir,
install : true)
if not is_disabler(exe)
exes += exe
manadocs += ['misc-utils/enosys.1.adoc']
bashcompletions += ['enosys']
endif
endif
exe = executable(
'lsclocks',
lsclocks_sources,
include_directories : includes,
link_with : [lib_common, lib_smartcols],
install_dir : usrbin_exec_dir,
install : true)
if not is_disabler(exe)
exes += exe
manadocs += ['misc-utils/lsclocks.1.adoc']
bashcompletions += ['lsclocks']
endif
############################################################
opt = not get_option('build-schedutils').disabled()
@ -3270,11 +3305,15 @@ exe = executable(
include_directories : includes)
exes += exe
mq_libs = []
mq_libs += cc.find_library('rt', required : true)
if LINUX
exe = executable(
'test_mkfds',
'tests/helpers/test_mkfds.c',
include_directories : includes)
include_directories : includes,
dependencies : mq_libs)
exes += exe
endif

View file

@ -297,3 +297,30 @@ waitpid_SOURCES = misc-utils/waitpid.c
waitpid_LDADD = $(LDADD) libcommon.la
waitpid_CFLAGS = $(AM_CFLAGS)
endif
if BUILD_ENOSYS
misc-utils/enosys.c: syscalls.h
syscalls.h: $(top_srcdir)/tools/all_syscalls
@echo ' GEN $@'
@$(top_srcdir)/tools/all_syscalls $(CC) $(CFLAGS)
-include syscalls.h.deps
CLEANFILES += syscalls.h syscalls.h.deps
usrbin_exec_PROGRAMS += enosys
MANPAGES += misc-utils/enosys.1
dist_noinst_DATA += misc-utils/enosys.1.adoc
enosys_SOURCES = misc-utils/enosys.c
enosys_LDADD = $(LDADD) libcommon.la
enosys_CFLAGS = $(AM_CFLAGS)
endif
if BUILD_LSCLOCKS
usrbin_exec_PROGRAMS += lsclocks
MANPAGES += misc-utils/lsclocks.1
lsclocks_SOURCES = misc-utils/lsclocks.c
lsclocks_LDADD = $(LDADD) libcommon.la libsmartcols.la
lsclocks_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir)
endif

60
misc-utils/enosys.1.adoc Normal file
View file

@ -0,0 +1,60 @@
//po4a: entry man manual
= enosys(1)
:doctype: manpage
:man manual: User Commands
:man source: util-linux {release-version}
:page-layout: base
:command: enosys
== NAME
enosys - utility make syscalls fail with ENOSYS
== SYNOPSIS
*enosys* [*--syscall*|*-s* _syscall_] command
== DESCRIPTION
*enosys* is a simple command to execute a child process for which certain
syscalls fail with errno ENOSYS.
It can be used to test the behavior of applications in the face of missing
syscalls as would happen when running on old kernels.
== OPTIONS
*-s*, *--syscall*::
Syscall to block. Can be specified multiple times.
*-l*, *--list*::
List syscalls known to *enosys*.
include::man-common/help-version.adoc[]
== EXIT STATUS
*enosys* exits with the status code of the executed process.
The following values have special meanings:
*1*::
internal error
*2*::
system does not provide the necessary functionality
== AUTHORS
mailto:thomas@t-8ch.de[Thomas Weißschuh]
== SEE ALSO
*syscall*(2)
include::man-common/bugreports.adoc[]
include::man-common/footer.adoc[]
ifdef::translation[]
include::man-common/translation.adoc[]
endif::[]

192
misc-utils/enosys.c Normal file
View file

@ -0,0 +1,192 @@
/*
* Copyright (C) 2023 Thomas Weißschuh <thomas@t-8ch.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it would be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stddef.h>
#include <stdbool.h>
#include <getopt.h>
#include <linux/unistd.h>
#include <linux/filter.h>
#include <linux/seccomp.h>
#include <linux/audit.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
#include "c.h"
#include "exitcodes.h"
#include "nls.h"
#include "bitops.h"
#include "audit-arch.h"
#define UL_BPF_NOP (struct sock_filter) BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0)
#define IS_LITTLE_ENDIAN (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#define syscall_nr (offsetof(struct seccomp_data, nr))
#define syscall_arch (offsetof(struct seccomp_data, arch))
#define syscall_arg(n) (offsetof(struct seccomp_data, args[n]))
static int set_seccomp_filter(const void *prog)
{
#if defined(__NR_seccomp) && defined(SECCOMP_SET_MODE_FILTER) && defined(SECCOMP_FILTER_FLAG_SPEC_ALLOW)
if (!syscall(__NR_seccomp, SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_SPEC_ALLOW, prog))
return 0;
#endif
return prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, prog);
}
struct syscall {
const char *const name;
long number;
};
static const struct syscall syscalls[] = {
#define UL_SYSCALL(name, nr) { name, nr },
#include "syscalls.h"
#undef UL_SYSCALL
};
static_assert(sizeof(syscalls) > 0, "no syscalls found");
static void __attribute__((__noreturn__)) usage(void)
{
FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out, _(" %s [options] -- <command>\n"), program_invocation_short_name);
fputs(USAGE_OPTIONS, out);
fputs(_(" -s, --syscall syscall to block\n"), out);
fputs(_(" -l, --list list known syscalls\n"), out);
fputs(USAGE_SEPARATOR, out);
fprintf(out, USAGE_HELP_OPTIONS(25));
fprintf(out, USAGE_MAN_TAIL("enosys(1)"));
exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
{
int c;
size_t i;
bool found;
static const struct option longopts[] = {
{ "syscall", required_argument, NULL, 's' },
{ "list", no_argument, NULL, 'l' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{ 0 }
};
bool blocked_syscalls[ARRAY_SIZE(syscalls)] = {};
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
while ((c = getopt_long (argc, argv, "+Vhs:l", longopts, NULL)) != -1) {
switch (c) {
case 's':
found = 0;
for (i = 0; i < ARRAY_SIZE(syscalls); i++) {
if (strcmp(optarg, syscalls[i].name) == 0) {
blocked_syscalls[i] = true;
found = 1;
break;
}
}
if (!found)
errx(EXIT_FAILURE, _("Unknown syscall '%s'"), optarg);
break;
case 'l':
for (i = 0; i < ARRAY_SIZE(syscalls); i++)
printf("%s\n", syscalls[i].name);
return EXIT_SUCCESS;
case 'V':
print_version(EXIT_SUCCESS);
case 'h':
usage();
default:
errtryhelp(EXIT_FAILURE);
}
}
if (optind >= argc)
errtryhelp(EXIT_FAILURE);
#define N_FILTERS (ARRAY_SIZE(syscalls) * 2 + 12)
struct sock_filter filter[N_FILTERS] = {
[0] = BPF_STMT(BPF_LD | BPF_W | BPF_ABS, syscall_arch),
[1] = BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SECCOMP_ARCH_NATIVE, 1, 0),
[2] = BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_TRAP),
/* Blocking "execve" normally would also block our own call to
* it and the end of main. To distinguish between our execve
* and the execve to be blocked, compare the environ pointer.
*
* See https://lore.kernel.org/all/CAAnLoWnS74dK9Wq4EQ-uzQ0qCRfSK-dLqh+HCais-5qwDjrVzg@mail.gmail.com/
*/
[3] = BPF_STMT(BPF_LD | BPF_W | BPF_ABS, syscall_nr),
[4] = BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_execve, 0, 5),
[5] = BPF_STMT(BPF_LD | BPF_W | BPF_ABS, syscall_arg(2) + 4 * !IS_LITTLE_ENDIAN),
[6] = BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, (uint64_t)(uintptr_t) environ, 0, 3),
[7] = BPF_STMT(BPF_LD | BPF_W | BPF_ABS, syscall_arg(2) + 4 * IS_LITTLE_ENDIAN),
[8] = BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, (uint64_t)(uintptr_t) environ >> 32, 0, 1),
[9] = BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
[10] = BPF_STMT(BPF_LD | BPF_W | BPF_ABS, syscall_nr),
[N_FILTERS - 1] = BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
};
static_assert(ARRAY_SIZE(filter) <= BPF_MAXINSNS, "bpf filter too big");
for (i = 0; i < ARRAY_SIZE(syscalls); i++) {
struct sock_filter *f = &filter[11 + i * 2];
*f = (struct sock_filter) BPF_JUMP(
BPF_JMP | BPF_JEQ | BPF_K,
syscalls[i].number,
0, 1);
*(f + 1) = blocked_syscalls[i]
? (struct sock_filter) BPF_STMT(
BPF_RET | BPF_K, SECCOMP_RET_ERRNO | ENOSYS)
: UL_BPF_NOP;
}
struct sock_fprog prog = {
.len = ARRAY_SIZE(filter),
.filter = filter,
};
/* *SET* below will return EINVAL when either the filter is invalid or
* seccomp is not supported. To distinguish those cases do a *GET* here
*/
if (prctl(PR_GET_SECCOMP) == -1 && errno == EINVAL)
err(EXIT_NOTSUPP, _("Seccomp non-functional"));
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))
err_nosys(EXIT_FAILURE, _("Could not run prctl(PR_SET_NO_NEW_PRIVS)"));
if (set_seccomp_filter(&prog))
err_nosys(EXIT_FAILURE, _("Could not seccomp filter"));
if (execvp(argv[optind], argv + optind))
err(EXIT_NOTSUPP, _("Could not exec"));
}

View file

@ -44,7 +44,7 @@
struct colinfo {
const char *name;
const char * const name;
double whint;
int flags;
const char *help;
@ -57,7 +57,7 @@ enum {
COL_RES
};
static struct colinfo infos[] = {
static const struct colinfo infos[] = {
[COL_PAGES] = { "PAGES", 1, SCOLS_FL_RIGHT, N_("file data resident in memory in pages")},
[COL_RES] = { "RES", 5, SCOLS_FL_RIGHT, N_("file data resident in memory in bytes")},
[COL_SIZE] = { "SIZE", 5, SCOLS_FL_RIGHT, N_("size of the file")},

View file

@ -90,7 +90,7 @@ enum {
/* column names */
struct colinfo {
const char *name; /* header */
const char * const name; /* header */
double whint; /* width hint (N < 1 is in percent of termwidth) */
int flags; /* libsmartcols flags */
const char *help; /* column description */

View file

@ -158,7 +158,7 @@ enum {
/* column names */
struct colinfo {
const char *name; /* header */
const char * const name; /* header */
double whint; /* width hint (N < 1 is in percent of termwidth) */
int flags; /* SCOLS_FL_* */
const char *help;
@ -166,7 +166,7 @@ struct colinfo {
};
/* columns descriptions */
static struct colinfo infos[] = {
static const struct colinfo infos[] = {
[COL_ALIOFF] = { "ALIGNMENT", 6, SCOLS_FL_RIGHT, N_("alignment offset"), COLTYPE_NUM },
[COL_ID] = { "ID", 0.1, SCOLS_FL_NOEXTREMES, N_("udev ID (based on ID-LINK)") },
[COL_IDLINK] = { "ID-LINK", 0.1, SCOLS_FL_NOEXTREMES, N_("the shortest udev /dev/disk/by-id link name") },
@ -324,7 +324,7 @@ static int get_column_id(int num)
}
/* Returns column description for the column sequential number */
static struct colinfo *get_column_info(int num)
static const struct colinfo *get_column_info(int num)
{
return &infos[ get_column_id(num) ];
}
@ -2364,7 +2364,7 @@ int main(int argc, char *argv[])
}
for (i = 0; i < ncolumns; i++) {
struct colinfo *ci = get_column_info(i);
const struct colinfo *ci = get_column_info(i);
struct libscols_column *cl;
int id = get_column_id(i), fl = ci->flags;

View file

@ -0,0 +1,81 @@
//po4a: entry man manual
= lsclocks(1)
:doctype: manpage
:man manual: User Commands
:man source: util-linux {release-version}
:page-layout: base
:command: lsclocks
== NAME
lsclocks - display system clocks
== SYNOPSIS
*lsclocks* [option]
== DESCRIPTION
*lsclocks* is a simple command to display system clocks.
It allows to display information like current time and resolutionof clocks like
CLOCK_MONOTONIC, CLOCK_REALTIME and CLOCK_BOOTTIME.
== OPTIONS
*-J*, *--json*::
Use JSON output format.
*-n*, *--noheadings*::
Don't print headings.
*-o*, *--output* _list_::
Specify which output columns to print. See the *OUTPUT COLUMNS*
section for details of available columns.
*-r*, *--raw*::
Use raw output format.
*-r*, *--time* _clock_
Show current time of one specific clocks.
include::man-common/help-version.adoc[]
== OUTPUT COLUMNS
Each column has a type. Types are surround by < and >.
ID <``number``>::
Numeric clock ID.
CLOCK <``string``>::
Name in the form *CLOCK_*
NAME <``string``>::
Shorter, easier to read name.
TIME <``number``>::
Current clock timestamp as returned by *clock_gettime()*.
ISO_TIME <``string``>::
ISO8601 formatted version of *TIME*.
RESOLUTION <``number``>::
Clock resolution as returned by *clock_getres()*.
== AUTHORS
mailto:thomas@t-8ch.de[Thomas Weißschuh]
== SEE ALSO
*clock_getres*(2) *clock_gettime*(2)
include::man-common/bugreports.adoc[]
include::man-common/footer.adoc[]
ifdef::translation[]
include::man-common/translation.adoc[]
endif::[]

366
misc-utils/lsclocks.c Normal file
View file

@ -0,0 +1,366 @@
/*
* lsclocks(1) - display system clocks
*
* Copyright (C) 2023 Thomas Weißschuh <thomas@t-8ch.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it would be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include <inttypes.h>
#include <getopt.h>
#include <libsmartcols.h>
#include "c.h"
#include "nls.h"
#include "strutils.h"
#include "timeutils.h"
#include "closestream.h"
#include "xalloc.h"
#define CLOCKFD 3
#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#ifndef CLOCK_MONOTONIC
#define CLOCK_MONOTONIC 1
#endif
#ifndef CLOCK_MONOTONIC_RAW
#define CLOCK_MONOTONIC_RAW 4
#endif
#ifndef CLOCK_REALTIME_COARSE
#define CLOCK_REALTIME_COARSE 5
#endif
#ifndef CLOCK_MONOTONIC_COARSE
#define CLOCK_MONOTONIC_COARSE 6
#endif
#ifndef CLOCK_BOOTTIME
#define CLOCK_BOOTTIME 7
#endif
#ifndef CLOCK_REALTIME_ALARM
#define CLOCK_REALTIME_ALARM 8
#endif
#ifndef CLOCK_BOOTTIME_ALARM
#define CLOCK_BOOTTIME_ALARM 9
#endif
#ifndef CLOCK_TAI
#define CLOCK_TAI 11
#endif
struct clockinfo {
clockid_t id;
const char * const id_name;
const char * const name;
};
static const struct clockinfo clocks[] = {
{ CLOCK_REALTIME, "CLOCK_REALTIME", "realtime" },
{ CLOCK_MONOTONIC, "CLOCK_MONOTONIC", "monotonic" },
{ CLOCK_MONOTONIC_RAW, "CLOCK_MONOTONIC_RAW", "monotonic-raw" },
{ CLOCK_REALTIME_COARSE, "CLOCK_REALTIME_COARSE", "realtime-coarse" },
{ CLOCK_MONOTONIC_COARSE, "CLOCK_MONOTONIC_COARSE", "monotonic-coarse" },
{ CLOCK_BOOTTIME, "CLOCK_BOOTTIME", "boottime" },
{ CLOCK_REALTIME_ALARM, "CLOCK_REALTIME_ALARM", "realtime-alarm" },
{ CLOCK_BOOTTIME_ALARM, "CLOCK_BOOTTIME_ALARM", "boottime-alarm" },
{ CLOCK_TAI, "CLOCK_TAI", "tai" },
};
/* column IDs */
enum {
COL_ID,
COL_CLOCK,
COL_NAME,
COL_TIME,
COL_ISO_TIME,
COL_RESOLUTION,
};
/* column names */
struct colinfo {
const char * const name; /* header */
double whint; /* width hint (N < 1 is in percent of termwidth) */
int flags; /* SCOLS_FL_* */
int json_type; /* SCOLS_JSON_* */
const char * const help;
};
/* columns descriptions */
static const struct colinfo infos[] = {
[COL_ID] = { "ID", 1, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("numeric id") },
[COL_CLOCK] = { "CLOCK", 1, 0, SCOLS_JSON_STRING, N_("symbolic name") },
[COL_NAME] = { "NAME", 1, 0, SCOLS_JSON_STRING, N_("readable name") },
[COL_TIME] = { "TIME", 1, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("numeric time") },
[COL_ISO_TIME] = { "ISO_TIME", 1, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, N_("human readable ISO time") },
[COL_RESOLUTION] = { "RESOLUTION", 1, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("resolution") },
};
static int column_name_to_id(const char *name, size_t namesz)
{
size_t i;
for (i = 0; i < ARRAY_SIZE(infos); i++) {
const char *cn = infos[i].name;
if (!strncasecmp(name, cn, namesz) && !*(cn + namesz))
return i;
}
warnx(_("unknown column: %s"), name);
return -1;
}
static void __attribute__((__noreturn__)) usage(void)
{
FILE *out = stdout;
size_t i;
fputs(USAGE_HEADER, out);
fprintf(out, _(" %s [options]\n"), program_invocation_short_name);
fputs(USAGE_OPTIONS, out);
fputs(_(" -J, --json use JSON output format\n"), out);
fputs(_(" -n, --noheadings don't print headings\n"), out);
fputs(_(" -o, --output <list> output columns\n"), out);
fputs(_(" -r, --raw use raw output format\n"), out);
fputs(_(" -t, --time <clock> show current time of single clock\n"), out);
fputs(USAGE_SEPARATOR, out);
printf(USAGE_HELP_OPTIONS(25));
fprintf(out, USAGE_COLUMNS);
for (i = 0; i < ARRAY_SIZE(infos); i++)
fprintf(out, " %16s %-10s%s\n", infos[i].name,
infos[i].json_type == SCOLS_JSON_STRING? "<string>":
infos[i].json_type == SCOLS_JSON_ARRAY_STRING? "<string>":
infos[i].json_type == SCOLS_JSON_ARRAY_NUMBER? "<string>":
infos[i].json_type == SCOLS_JSON_NUMBER? "<number>":
"<boolean>",
_(infos[i].help));
printf(USAGE_MAN_TAIL("lslocks(1)"));
exit(EXIT_SUCCESS);
}
__attribute__ ((__format__ (__printf__, 3, 4)))
static void scols_line_asprintf(struct libscols_line *ln, size_t n, const char *format, ...)
{
char *data;
va_list args;
va_start(args, format);
xvasprintf(&data, format, args);
va_end(args);
scols_line_refer_data(ln, n, data);
}
static void scols_line_format_timespec(struct libscols_line *ln, size_t n, const struct timespec *ts)
{
scols_line_asprintf(ln, n, "%ju.%09" PRId32, (uintmax_t) ts->tv_sec, (uint32_t) ts->tv_nsec);
}
static clockid_t parse_clock(const char *name)
{
size_t i;
uint32_t id = -1;
int rc;
rc = ul_strtou32(name, &id, 10);
for (i = 0; i < ARRAY_SIZE(clocks); i++) {
if (!strcmp(name, clocks[i].id_name)
|| !strcmp(name, clocks[i].name))
return clocks[i].id;
if (rc == 0 && (clockid_t) id == clocks[i].id)
return id;
}
errx(EXIT_FAILURE, _("Unknown clock: %s"), name);
}
int main(int argc, char **argv)
{
size_t i, j;
char c;
int rc;
const struct colinfo *colinfo;
const struct clockinfo *clockinfo;
struct libscols_table *tb;
struct libscols_line *ln;
struct libscols_column *col;
bool noheadings = false, raw = false, json = false;
const char *outarg = NULL;
int columns[ARRAY_SIZE(infos) * 2];
size_t ncolumns = 0;
clockid_t clock = -1;
struct timespec resolution, now;
char buf[FORMAT_TIMESTAMP_MAX];
static const struct option longopts[] = {
{ "noheadings", no_argument, NULL, 'n' },
{ "output", required_argument, NULL, 'o' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{ "json", no_argument, NULL, 'J' },
{ "raw", no_argument, NULL, 'r' },
{ "time", required_argument, NULL, 't' },
{ 0 }
};
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
close_stdout_atexit();
while ((c = getopt_long(argc, argv, "no:Jrt:Vh", longopts, NULL)) != -1) {
switch (c) {
case 'n':
noheadings = true;
break;
case 'o':
outarg = optarg;
break;
case 'J':
json = true;
break;
case 'r':
raw = true;
break;
case 't':
clock = parse_clock(optarg);
break;
case 'V':
print_version(EXIT_SUCCESS);
case 'h':
usage();
default:
errtryhelp(EXIT_FAILURE);
}
}
if (argv[optind])
errtryhelp(EXIT_FAILURE);
if (clock != -1) {
rc = clock_gettime(clock, &now);
if (rc)
err(EXIT_FAILURE, _("failed to get time"));
printf("%ju.%09"PRId32"\n", (uintmax_t) now.tv_sec, (uint32_t) now.tv_nsec);
return EXIT_SUCCESS;
}
if (!ncolumns) {
columns[ncolumns++] = COL_ID;
columns[ncolumns++] = COL_CLOCK;
columns[ncolumns++] = COL_NAME;
columns[ncolumns++] = COL_TIME;
columns[ncolumns++] = COL_ISO_TIME;
columns[ncolumns++] = COL_RESOLUTION;
}
if (outarg && string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
&ncolumns, column_name_to_id) < 0)
return EXIT_FAILURE;
scols_init_debug(0);
tb = scols_new_table();
if (!tb)
errx(EXIT_FAILURE, _("failed to allocate output table"));
scols_table_set_name(tb, "clocks");
for (i = 0; i < ncolumns; i++) {
colinfo = &infos[columns[i]];
col = scols_table_new_column(tb, colinfo->name, colinfo->whint, colinfo->flags);
if (!col)
errx(EXIT_FAILURE, _("failed to allocate output column"));
scols_column_set_json_type(col, colinfo->json_type);
}
for (i = 0; i < ARRAY_SIZE(clocks); i++) {
clockinfo = &clocks[i];
ln = scols_table_new_line(tb, NULL);
if (!ln)
errx(EXIT_FAILURE, _("failed to allocate output line"));
/* outside the loop to guarantee consistency between COL_TIME and COL_ISO_TIME */
rc = clock_gettime(clockinfo->id, &now);
if (rc)
now.tv_nsec = -1;
for (j = 0; j < ncolumns; j++) {
switch (columns[j]) {
case COL_ID:
scols_line_asprintf(ln, j, "%ju", (uintmax_t) clockinfo->id);
break;
case COL_CLOCK:
scols_line_set_data(ln, j, clockinfo->id_name);
break;
case COL_NAME:
scols_line_set_data(ln, j, clockinfo->name);
break;
case COL_TIME:
if (now.tv_nsec == -1)
break;
scols_line_format_timespec(ln, j, &now);
break;
case COL_ISO_TIME:
if (now.tv_nsec == -1)
break;
rc = strtimespec_iso(&now,
ISO_GMTIME | ISO_DATE | ISO_TIME | ISO_T | ISO_DOTNSEC | ISO_TIMEZONE,
buf, sizeof(buf));
if (rc)
errx(EXIT_FAILURE, _("failed to format iso time"));
scols_line_set_data(ln, j, buf);
break;
case COL_RESOLUTION:
rc = clock_getres(clockinfo->id, &resolution);
if (!rc)
scols_line_format_timespec(ln, j, &resolution);
break;
}
}
}
scols_table_enable_json(tb, json);
scols_table_enable_raw(tb, raw);
scols_table_enable_noheadings(tb, noheadings);
scols_print_table(tb);
scols_unref_table(tb);
}

View file

@ -33,70 +33,74 @@ struct miscdev {
char *name;
};
struct cdev {
struct file file;
const char *devdrv;
const struct cdev_ops *cdev_ops;
void *cdev_data;
};
struct cdev_ops {
const struct cdev_ops *parent;
bool (*probe)(const struct cdev *);
char * (*get_name)(struct cdev *);
bool (*fill_column)(struct proc *,
struct cdev *,
struct libscols_line *,
int,
size_t,
char **);
void (*init)(const struct cdev *);
void (*free)(const struct cdev *);
int (*handle_fdinfo)(struct cdev *, const char *, const char *);
};
static bool cdev_fill_column(struct proc *proc __attribute__((__unused__)),
struct file *file __attribute__((__unused__)),
struct file *file,
struct libscols_line *ln,
int column_id,
size_t column_index)
{
struct cdev *cdev = (struct cdev *)file;
const struct cdev_ops *ops = cdev->cdev_ops;
char *str = NULL;
const char *devdrv;
const char *miscdev;
switch(column_id) {
case COL_NAME:
if (cdev->cdev_ops->get_name) {
str = cdev->cdev_ops->get_name(cdev);
if (str)
break;
}
return false;
case COL_TYPE:
if (scols_line_set_data(ln, column_index, "CHR"))
err(EXIT_FAILURE, _("failed to add output data"));
return true;
case COL_MISCDEV:
devdrv = get_chrdrv(major(file->stat.st_rdev));
if (devdrv && strcmp(devdrv, "misc") == 0) {
miscdev = get_miscdev(minor(file->stat.st_rdev));
if (miscdev)
str = xstrdup(miscdev);
else
xasprintf(&str, "%u",
minor(file->stat.st_rdev));
break;
}
return true;
case COL_DEVTYPE:
if (scols_line_set_data(ln, column_index,
"char"))
err(EXIT_FAILURE, _("failed to add output data"));
return true;
case COL_CHRDRV:
devdrv = get_chrdrv(major(file->stat.st_rdev));
if (devdrv)
str = xstrdup(devdrv);
if (cdev->devdrv)
str = xstrdup(cdev->devdrv);
else
xasprintf(&str, "%u",
major(file->stat.st_rdev));
break;
case COL_SOURCE:
devdrv = get_chrdrv(major(file->stat.st_rdev));
miscdev = NULL;
if (devdrv && strcmp(devdrv, "misc") == 0)
miscdev = get_miscdev(minor(file->stat.st_rdev));
if (devdrv) {
if (miscdev) {
xasprintf(&str, "misc:%s", miscdev);
} else {
xasprintf(&str, "%s:%u", devdrv,
minor(file->stat.st_rdev));
}
break;
}
/* FALL THROUGH */
case COL_MAJMIN:
xasprintf(&str, "%u:%u",
major(file->stat.st_rdev),
minor(file->stat.st_rdev));
break;
default:
while (ops) {
if (ops->fill_column
&& ops->fill_column(proc, cdev, ln,
column_id, column_index, &str))
goto out;
ops = ops->parent;
}
return false;
}
out:
if (!str)
err(EXIT_FAILURE, _("failed to add output data"));
if (scols_line_refer_data(ln, column_index, str))
@ -168,11 +172,220 @@ const char *get_miscdev(unsigned long minor)
return NULL;
}
/*
* generic (fallback implementation)
*/
static bool cdev_generic_probe(const struct cdev *cdev __attribute__((__unused__))) {
return true;
}
static bool cdev_generic_fill_column(struct proc *proc __attribute__((__unused__)),
struct cdev *cdev,
struct libscols_line *ln __attribute__((__unused__)),
int column_id,
size_t column_index __attribute__((__unused__)),
char **str)
{
struct file *file = &cdev->file;
switch(column_id) {
case COL_SOURCE:
if (cdev->devdrv) {
xasprintf(str, "%s:%u", cdev->devdrv,
minor(file->stat.st_rdev));
return true;
}
/* FALL THROUGH */
case COL_MAJMIN:
xasprintf(str, "%u:%u",
major(file->stat.st_rdev),
minor(file->stat.st_rdev));
return true;
default:
return false;
}
}
static struct cdev_ops cdev_generic_ops = {
.probe = cdev_generic_probe,
.fill_column = cdev_generic_fill_column,
};
/*
* misc device driver
*/
static bool cdev_misc_probe(const struct cdev *cdev) {
return cdev->devdrv && strcmp(cdev->devdrv, "misc") == 0;
}
static bool cdev_misc_fill_column(struct proc *proc __attribute__((__unused__)),
struct cdev *cdev,
struct libscols_line *ln __attribute__((__unused__)),
int column_id,
size_t column_index __attribute__((__unused__)),
char **str)
{
struct file *file = &cdev->file;
const char *miscdev;
switch(column_id) {
case COL_MISCDEV:
miscdev = get_miscdev(minor(file->stat.st_rdev));
if (miscdev)
*str = xstrdup(miscdev);
else
xasprintf(str, "%u",
minor(file->stat.st_rdev));
return true;
case COL_SOURCE:
miscdev = get_miscdev(minor(file->stat.st_rdev));
if (miscdev)
xasprintf(str, "misc:%s", miscdev);
else
xasprintf(str, "misc:%u",
minor(file->stat.st_rdev));
return true;
}
return false;
}
static struct cdev_ops cdev_misc_ops = {
.parent = &cdev_generic_ops,
.probe = cdev_misc_probe,
.fill_column = cdev_misc_fill_column,
};
/*
* tun devcie driver
*/
static bool cdev_tun_probe(const struct cdev *cdev)
{
const char *miscdev;
if ((!cdev->devdrv) || strcmp(cdev->devdrv, "misc"))
return false;
miscdev = get_miscdev(minor(cdev->file.stat.st_rdev));
if (miscdev && strcmp(miscdev, "tun") == 0)
return true;
return false;
}
static void cdev_tun_free(const struct cdev *cdev)
{
if (cdev->cdev_data)
free(cdev->cdev_data);
}
static char * cdev_tun_get_name(struct cdev *cdev)
{
char *str = NULL;
if (cdev->cdev_data == NULL)
return NULL;
xasprintf(&str, "iface=%s", (const char *)cdev->cdev_data);
return str;
}
static bool cdev_tun_fill_column(struct proc *proc __attribute__((__unused__)),
struct cdev *cdev,
struct libscols_line *ln __attribute__((__unused__)),
int column_id,
size_t column_index __attribute__((__unused__)),
char **str)
{
switch(column_id) {
case COL_MISCDEV:
*str = xstrdup("tun");
return true;
case COL_SOURCE:
*str = xstrdup("misc:tun");
return true;
case COL_TUN_IFACE:
if (cdev->cdev_data) {
*str = xstrdup(cdev->cdev_data);
return true;
}
}
return false;
}
static int cdev_tun_handle_fdinfo(struct cdev *cdev, const char *key, const char *val)
{
if (strcmp(key, "iff") == 0 && cdev->cdev_data == NULL) {
cdev->cdev_data = xstrdup(val);
return 1;
}
return false;
}
static struct cdev_ops cdev_tun_ops = {
.parent = &cdev_misc_ops,
.probe = cdev_tun_probe,
.free = cdev_tun_free,
.get_name = cdev_tun_get_name,
.fill_column = cdev_tun_fill_column,
.handle_fdinfo = cdev_tun_handle_fdinfo,
};
static const struct cdev_ops *cdev_ops[] = {
&cdev_tun_ops,
&cdev_misc_ops,
&cdev_generic_ops /* This must be at the end. */
};
static const struct cdev_ops *cdev_probe(const struct cdev *cdev)
{
const struct cdev_ops *r = NULL;
for (size_t i = 0; i < ARRAY_SIZE(cdev_ops); i++) {
if (cdev_ops[i]->probe(cdev)) {
r = cdev_ops[i];
break;
}
}
assert(r);
return r;
}
static void init_cdev_content(struct file *file)
{
struct cdev *cdev = (struct cdev *)file;
cdev->devdrv = get_chrdrv(major(file->stat.st_rdev));
cdev->cdev_data = NULL;
cdev->cdev_ops = cdev_probe(cdev);
if (cdev->cdev_ops->init)
cdev->cdev_ops->init(cdev);
}
static void free_cdev_content(struct file *file)
{
struct cdev *cdev = (struct cdev *)file;
if (cdev->cdev_ops->free)
cdev->cdev_ops->free(cdev);
}
static int cdev_handle_fdinfo(struct file *file, const char *key, const char *value)
{
struct cdev *cdev = (struct cdev *)file;
if (cdev->cdev_ops->handle_fdinfo)
return cdev->cdev_ops->handle_fdinfo(cdev, key, value);
return 0; /* Should be handled in parents */
}
const struct file_class cdev_class = {
.super = &file_class,
.size = sizeof(struct file),
.size = sizeof(struct cdev),
.initialize_class = cdev_class_initialize,
.finalize_class = cdev_class_finalize,
.fill_column = cdev_fill_column,
.free_content = NULL,
.initialize_content = init_cdev_content,
.free_content = free_cdev_content,
.handle_fdinfo = cdev_handle_fdinfo,
};

View file

@ -68,8 +68,8 @@ static bool fifo_fill_column(struct proc *proc __attribute__((__unused__)),
case COL_ENDPOINTS: {
struct fifo *this = (struct fifo *)file;
struct list_head *e;
char *estr;
list_for_each_backwardly(e, &this->endpoint.ipc->endpoints) {
foreach_endpoint(e, this->endpoint) {
char *estr;
struct fifo *other = list_entry(e, struct fifo, endpoint.endpoints);
if (this == other)
continue;
@ -107,6 +107,7 @@ static bool fifo_is_suitable_ipc(struct ipc *ipc, struct file *file)
static const struct ipc_class *fifo_get_ipc_class(struct file *file __attribute__((__unused__)))
{
static const struct ipc_class fifo_ipc_class = {
.size = sizeof(struct fifo_ipc),
.get_hash = fifo_get_hash,
.is_suitable_ipc = fifo_is_suitable_ipc,
.free = NULL,
@ -120,22 +121,18 @@ static void fifo_initialize_content(struct file *file)
struct ipc *ipc;
unsigned int hash;
INIT_LIST_HEAD(&fifo->endpoint.endpoints);
init_endpoint(&fifo->endpoint);
ipc = get_ipc(file);
if (ipc)
goto link;
ipc = xmalloc(sizeof(struct fifo_ipc));
ipc->class = fifo_get_ipc_class(file);
INIT_LIST_HEAD(&ipc->endpoints);
INIT_LIST_HEAD(&ipc->ipcs);
ipc = new_ipc(fifo_get_ipc_class(file));
((struct fifo_ipc *)ipc)->ino = file->stat.st_ino;
hash = fifo_get_hash(file);
add_ipc(ipc, hash);
link:
fifo->endpoint.ipc = ipc;
list_add(&fifo->endpoint.endpoints, &ipc->endpoints);
add_endpoint(&fifo->endpoint, ipc);
}
const struct file_class fifo_class = {

View file

@ -32,6 +32,7 @@
# endif
#endif
#include <linux/sched.h>
#include <sys/shm.h>
#include "xalloc.h"
#include "nls.h"
@ -39,12 +40,15 @@
#include "idcache.h"
#include "strutils.h"
#include "procfs.h"
#include "libsmartcols.h"
#include "lsfd.h"
static struct idcache *username_cache;
static size_t pagesize;
static const char *assocstr[N_ASSOCS] = {
[ASSOC_CWD] = "cwd",
[ASSOC_EXE] = "exe",
@ -102,18 +106,60 @@ static uint64_t get_map_length(struct file *file)
{
uint64_t res = 0;
if (is_association(file, SHM) || is_association(file, MEM)) {
static size_t pagesize = 0;
if (!pagesize)
pagesize = getpagesize();
if (is_association(file, SHM) || is_association(file, MEM))
res = (file->map_end - file->map_start) / pagesize;
}
return res;
}
void decode_source(char *buf, size_t bufsize,
unsigned int dev_major, unsigned int dev_minor,
enum decode_source_level level)
{
if (bufsize == 0)
return;
buf[0] = '\0';
if (level & DECODE_SOURCE_FILESYS_BIT) {
if (dev_major == 0) {
const char *filesystem = get_nodev_filesystem(dev_minor);
if (filesystem) {
xstrncpy(buf, filesystem, bufsize);
return;
}
}
}
if (level & DECODE_SOURCE_PARTITION_BIT) {
dev_t dev = makedev(dev_major, dev_minor);
const char *partition = get_partition(dev);
if (partition) {
xstrncpy(buf, partition, bufsize);
return;
}
}
if (level & DECODE_SOURCE_MAJMIN_BIT)
snprintf(buf, bufsize, "%u:%u",
dev_major,
dev_minor);
}
static char *strnrstr(const char *haystack, const char *needle, size_t needle_len)
{
char *last = strstr(haystack, needle);
if (last == NULL)
return NULL;
do {
char *current = strstr(last + needle_len, needle);
if (current == NULL)
return last;
last = current;
} while (1);
}
static bool file_fill_column(struct proc *proc,
struct file *file,
struct libscols_line *ln,
@ -122,7 +168,7 @@ static bool file_fill_column(struct proc *proc,
{
char *str = NULL;
mode_t ftype;
const char *partition;
char buf[BUFSIZ];
switch(column_id) {
case COL_COMMAND:
@ -130,8 +176,22 @@ static bool file_fill_column(struct proc *proc,
&& scols_line_set_data(ln, column_index, proc->command))
err(EXIT_FAILURE, _("failed to add output data"));
return true;
case COL_KNAME:
case COL_NAME:
if (file->name && file->stat.st_nlink == 0) {
char *d = strnrstr(file->name, "(deleted)",
sizeof("(deleted)") - 1);
if (d) {
int r;
*d = '\0';
r = scols_line_set_data(ln, column_index, file->name);
*d = '(';
if (r)
err(EXIT_FAILURE, _("failed to add output data"));
return true;
}
}
/* FALL THROUGH */
case COL_KNAME:
if (file->name
&& scols_line_set_data(ln, column_index, file->name))
err(EXIT_FAILURE, _("failed to add output data"));
@ -172,33 +232,27 @@ static bool file_fill_column(struct proc *proc,
int assoc = file->association * -1;
if (assoc >= N_ASSOCS)
return false; /* INTERNAL ERROR */
xasprintf(&str, "%s", assocstr[assoc]);
str = xstrdup(assocstr[assoc]);
}
break;
case COL_INODE:
xasprintf(&str, "%llu", (unsigned long long)file->stat.st_ino);
break;
case COL_SOURCE:
if (major(file->stat.st_dev) == 0) {
const char *filesystem = get_nodev_filesystem(minor(file->stat.st_dev));
if (filesystem) {
xasprintf(&str, "%s", filesystem);
break;
}
}
/* FALL THROUGH */
decode_source(buf, sizeof(buf), major(file->stat.st_dev), minor(file->stat.st_dev),
DECODE_SOURCE_FILESYS);
str = xstrdup(buf);
break;
case COL_PARTITION:
partition = get_partition(file->stat.st_dev);
if (partition) {
str = xstrdup(partition);
break;
}
/* FALL THROUGH */
decode_source(buf, sizeof(buf), major(file->stat.st_dev), minor(file->stat.st_dev),
DECODE_SOURCE_PARTITION);
str = xstrdup(buf);
break;
case COL_DEV:
case COL_MAJMIN:
xasprintf(&str, "%u:%u",
major(file->stat.st_dev),
minor(file->stat.st_dev));
decode_source(buf, sizeof(buf), major(file->stat.st_dev), minor(file->stat.st_dev),
DECODE_SOURCE_MAJMIN);
str = xstrdup(buf);
break;
case COL_RDEV:
xasprintf(&str, "%u:%u",
@ -242,6 +296,19 @@ static bool file_fill_column(struct proc *proc,
else
xasprintf(&str, "---");
break;
case COL_XMODE: {
char r, w, x;
char D = file->stat.st_nlink == 0? 'D': '-';
if (does_file_has_fdinfo_alike(file)) {
r = file->mode & S_IRUSR? 'r': '-';
w = file->mode & S_IWUSR? 'w': '-';
x = (is_mapped_file(file)
&& file->mode & S_IXUSR)? 'x': '-';
} else
r = w = x = '-';
xasprintf(&str, "%c%c%c%c", r, w, x, D);
break;
}
case COL_POS:
xasprintf(&str, "%" PRIu64,
(does_file_has_fdinfo_alike(file))? file->pos: 0);
@ -268,7 +335,7 @@ static bool file_fill_column(struct proc *proc,
break;
default:
return false;
};
}
if (!str)
err(EXIT_FAILURE, _("failed to add output data"));
@ -304,11 +371,63 @@ static void file_free_content(struct file *file)
free(file->name);
}
static unsigned long get_minor_for_sysvipc(void)
{
int id;
void *start;
pid_t self = getpid();
struct path_cxt *pc = NULL;
char map_file[sizeof("map_files/0000000000000000-ffffffffffffffff")];
struct stat sb;
unsigned long m = 0;
id = shmget(IPC_PRIVATE, pagesize, IPC_CREAT | 0600);
if (id == -1)
return 0;
start = shmat(id, NULL, SHM_RDONLY);
if (start == (void *) -1) {
shmctl(id, IPC_RMID, NULL);
return 0;
}
pc = ul_new_path(NULL);
if (!pc)
goto out;
if (procfs_process_init_path(pc, self) != 0)
goto out;
snprintf(map_file, sizeof(map_file),
"map_files/%lx-%lx", (long)start, (long)start + pagesize);
if (ul_path_stat(pc, &sb, 0, map_file) < 0)
goto out;
m = minor(sb.st_dev);
out:
if (pc)
ul_unref_path(pc);
shmdt(start);
shmctl(id, IPC_RMID, NULL);
return m;
}
static void file_class_initialize(void)
{
unsigned long m;
if (!pagesize)
pagesize = getpagesize();
username_cache = new_idcache();
if (!username_cache)
err(EXIT_FAILURE, _("failed to allocate UID cache"));
m = get_minor_for_sysvipc();
if (m)
add_nodev(m, "tmpfs");
}
static void file_class_finalize(void)
@ -463,3 +582,122 @@ const struct file_class nsfs_file_class = {
.fill_column = nsfs_file_fill_column,
.handle_fdinfo = NULL,
};
/*
* POSIX Mqueue
*/
struct mqueue_file {
struct file file;
struct ipc_endpoint endpoint;
};
struct mqueue_file_ipc {
struct ipc ipc;
ino_t ino;
};
bool is_mqueue_dev(dev_t dev)
{
const char *fs = get_nodev_filesystem(minor(dev));
if (fs && (strcmp (fs, "mqueue") == 0))
return true;
return false;
}
static inline char *mqueue_file_xstrendpoint(struct file *file)
{
char *str = NULL;
xasprintf(&str, "%d,%s,%d%c%c",
file->proc->pid, file->proc->command, file->association,
(file->mode & S_IRUSR)? 'r': '-',
(file->mode & S_IWUSR)? 'w': '-');
return str;
}
static bool mqueue_file_fill_column(struct proc *proc __attribute__((__unused__)),
struct file *file __attribute__((__unused__)),
struct libscols_line *ln,
int column_id,
size_t column_index)
{
switch (column_id) {
case COL_TYPE:
if (scols_line_set_data(ln, column_index, "mqueue"))
err(EXIT_FAILURE, _("failed to add output data"));
return true;
case COL_ENDPOINTS: {
char *str = NULL;
struct mqueue_file *this = (struct mqueue_file *)file;
struct list_head *e;
foreach_endpoint(e, this->endpoint) {
char *estr;
struct mqueue_file *other = list_entry(e, struct mqueue_file,
endpoint.endpoints);
if (this == other)
continue;
if (str)
xstrputc(&str, '\n');
estr = mqueue_file_xstrendpoint(&other->file);
xstrappend(&str, estr);
free(estr);
}
if (!str)
return false;
if (scols_line_refer_data(ln, column_index, str))
err(EXIT_FAILURE, _("failed to add output data"));
return true;
}
default:
return false;
}
}
static unsigned int mqueue_file_get_hash(struct file *file)
{
return (unsigned int)(file->stat.st_ino % UINT_MAX);
}
static bool mqueue_file_is_suitable_ipc(struct ipc *ipc, struct file *file)
{
return ((struct mqueue_file_ipc *)ipc)->ino == file->stat.st_ino;
}
static const struct ipc_class *mqueue_file_get_ipc_class(struct file *file __attribute__((__unused__)))
{
static const struct ipc_class mqueue_file_ipc_class = {
.size = sizeof(struct mqueue_file_ipc),
.get_hash = mqueue_file_get_hash,
.is_suitable_ipc = mqueue_file_is_suitable_ipc,
};
return &mqueue_file_ipc_class;
}
static void init_mqueue_file_content(struct file *file)
{
struct mqueue_file *mqueue_file = (struct mqueue_file *)file;
struct ipc *ipc;
unsigned int hash;
init_endpoint(&mqueue_file->endpoint);
ipc = get_ipc(file);
if (ipc)
goto link;
ipc = new_ipc(mqueue_file_get_ipc_class(file));
((struct mqueue_file_ipc *)ipc)->ino = file->stat.st_ino;
hash = mqueue_file_get_hash(file);
add_ipc(ipc, hash);
link:
add_endpoint(&mqueue_file->endpoint, ipc);
}
const struct file_class mqueue_file_class = {
.super = &file_class,
.size = sizeof(struct mqueue_file),
.initialize_content = init_mqueue_file_content,
.fill_column = mqueue_file_fill_column,
.get_ipc_class = mqueue_file_get_ipc_class,
};

Some files were not shown because too many files have changed in this diff Show more