Commit Graph

14887 Commits

Author SHA1 Message Date
Sami Kerola 084efcee43
uuidd: move option parsing to separate function
Moving the option parsing to a separate function will allow moving some
variables from main() heap to be in scope that free them later.  That should
make the uuidd to have a little bit smaller runtime memory allocation.

The static long options is changed to be local variable.  That should make
it to be part of heap for a bit, until removed.  Earlier the variable was in
data segment and permanently in runtime memory.  Whether this makes any
impact either way is not entirely clear, but hope is the runtime memory
allocation is tiny bit smaller.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 21:34:40 +00:00
Sami Kerola b03ffec18c
uuidd: add command-line option values struct
The struct will help seeing where the variable values are coming from.  This
will also help upcoming refactoring.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 21:34:40 +00:00
Sami Kerola c14e0f6239
uuidd: use pid_t type when referring to process id
Earlier use of a variable that holds switch enabling boolean to hold process
id was a little bit strange, and not exactly correct.  An int should be good
enough to hold any pid, but it is better to be precise and use the type that
is meant for the job.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 21:34:39 +00:00
Karel Zak 1e416dc0b9 Merge branch 'master' of https://github.com/pali/util-linux
* 'master' of https://github.com/pali/util-linux:
  libblkid: drbdmanage: use blkid_probe_strncpy_uuid instead of blkid_probe_set_id_label
2020-11-23 10:21:17 +01:00
Karel Zak 9b9954a9c4 Merge branch 'privfix' of https://github.com/ericonr/util-linux 2020-11-23 10:19:01 +01:00
Pali Rohár 3a9a6036a4 libblkid: drbdmanage: use blkid_probe_strncpy_uuid instead of blkid_probe_set_id_label
Function blkid_probe_strncpy_uuid() is better suitable for setting UUID
than function blkid_probe_set_id_label().

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-11-22 19:44:09 +01:00
Érico Rolim 93de9f687d setpriv: allow using [-+]all for capabilities.
The initial change to lib/caputils that allowed this was commit
5d95818757, which made it possible to
trust the value returned by cap_last_cap().

The error message was also somewhat misleading, since cap_last_cap()
being smaller than CAP_LAST_CAP happens when setpriv itself is built
with kernel headers older than the currently running kernel, not due to
libcap-ng.
2020-11-20 12:45:39 -03:00
Érico Rolim 0eba195d9e setpriv: small clean-up.
- Add _() calls for some strings which were missing it.
- In print_caps(), use the same error checking done in
  list_known_caps(); it is expected that libcap-ng will always return a
  string, even if it's only "cap_%d".
2020-11-20 12:33:23 -03:00
Karel Zak 57b74b0dcb Merge branch 'w45'
* w45:
  fdformat: remove command from default build
  more: improve error messaging when input file is directory
  ul: make set_column() zero check more obvious
  colrm: fix argument parsing
  rfkill: stop execution when rfkill device cannot be opened
  cifuzz: reindent yaml file
  man: make tilde and caret characters to render correctly
2020-11-20 12:01:22 +01:00
Karel Zak 966420219c lib/caputils: split to multiple functions, add test
Let's split the code to make it possible to test separately bsearch as
well as procfs based cap_last_cap().

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

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

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-20 10:40:31 +01:00
Karel Zak 61dc5ae39a Merge branch 'caps' of https://github.com/ericonr/util-linux
* 'caps' of https://github.com/ericonr/util-linux:
  lib/caputils: add fall back for last cap using prctl.
  lib/procutils: add proc_is_procfs helper.
2020-11-20 10:21:19 +01:00
Masayoshi Mizuma f42f105b07 lscpu: show the number of physical socket on aarch64 machine without ACPI PPTT
Show the number of the number of physical socket even if the sysfs doesn't
have the physical socket information.

Note, lscpu shows the number of physical socket as 'Socket(s):' only if
root user runs it because accessing the DMI table requires root
privilege.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00
Masayoshi Mizuma 788f90d69a lscpu: add helper to get physical sockets
Add a helper function, get_number_of_physical_sockets_from_dmi(),
to get physical sockets from DMI table in case of the sysfs for
cpu topology doesn't have the physical socket information.

get_number_of_physical_sockets_from_dmi() parse the DMI table
and counts the number of SMBIOS Processor Information (Type04)
structure.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00
Masayoshi Mizuma 3cd676f5ec lscpu-dmi: Move some functions related to DMI to lscpu-dmi
Move some functions related to DMI to lscpu-dmi.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00
Masayoshi Mizuma b04ab8dd8a lscpu-virt: split hypervisor_from_dmi_table()
Split hypervisor_from_dmi_table() to parsing dmi table and checking the
hypervisor vendor.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00
Masayoshi Mizuma 73c0a766ff lscpu: use cluster on aarch64 machine which doesn't have ACPI PPTT
lscpu may show the wrong number of sockets if the machine is aarch64 and
doesn't have ACPI PPTT.

That's because lscpu shows the number of sockets by using a sysfs entry
(cpu/cpuX/topology/core_siblings). The sysfs entry is set by MPIDR_EL1
register if the machine doesn't have ACPI PPTT. MPIDR_EL1 doesn't show
the physical socket information directly. It shows the affinity level.

According to linux/arch/arm64/kernel/topology.c:store_cpu_topology(),
the top level of affinity is called as 'Cluster'.

Use Cluster instead of Socket on the machine which doesn't have ACPI PPTT.

This patch is useful for aarch64 machine which is based on ARM
SBBR v1.0 and v1.1, the specs don't require ACPI PPTT. ARM SBBR v1.2
requires ACPI PPTT.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00
Karel Zak ffe8cabd1f lib/signames: change license to public domain
The file is simple list of signal names and trivial function to search
in the list. We do not need any extra license here and as public
domain it will be more portable to other tools (GPL and BSD) in the
util-linux.

All previous contributors (Sami, Niklas and me) agree with this change.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-19 12:04:08 +01:00
Karel Zak 1c675ebee0 lscpu: fix resource leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-19 12:00:58 +01:00
Karel Zak b9b28b641e lscpu: fix possible null dereferences [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-19 11:57:36 +01:00
Karel Zak 77a3708489 umount: ignore --no-canonicalize,-c for non-root users
It seems better to ignore this option than drop-permissions and later
exit with EPERMs. This change makes umount(8) more compatible with
fuser user umounts by systemd where -c is used to reduce overhead etc.

Addresses: https://github.com/karelzak/util-linux/issues/1192
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-19 11:12:06 +01:00
Karel Zak 52f730e478 libmount: don't use "symfollow" for helpers on user mounts
Addresses: https://github.com/karelzak/util-linux/issues/1193
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-19 09:49:16 +01:00
Érico Rolim 5d95818757 lib/caputils: add fall back for last cap using prctl.
This allows the rest of the programs using cap_last_cap to trust the
value returned by it, since it will either be obtained from procfs
(straight from kernel) or with prctl.

Also checked if the file under /proc is actually mounted in a procfs.
2020-11-18 14:39:33 -03:00
Érico Rolim e411b8a63d lib/procutils: add proc_is_procfs helper.
Also add missing include in procutils.h for the definition of pid_t.
2020-11-18 14:30:50 -03:00
Karel Zak 95b1f7c776 Merge branch 'hwclock-syscall-nr' of https://github.com/pinotree/util-linux
* 'hwclock-syscall-nr' of https://github.com/pinotree/util-linux:
  hwclock: do not assume __NR_settimeofday_time32
2020-11-18 10:32:39 +01:00
Pino Toscano 367972fae1 hwclock: do not assume __NR_settimeofday_time32
Check that __NR_settimeofday_time32 exists before trying to use it as
syscall number.

Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
2020-11-17 11:32:45 +01:00
Pino Toscano 5547316c85 build-sys: do not build plymouth-ctrl.c w/ disabled plymouth
Do not build plymouth-ctrl.c in agetty and sulogin in case the plymouth
support is disabled.

Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
2020-11-17 11:27:48 +01:00
Érico Rolim b3ea5aaa64 lscpu-virt: fix return type of read_hypervisor_cpuid for non x86. 2020-11-15 11:53:39 -03:00
Sami Kerola 13b26e3c36
fdformat: remove command from default build
It should be safe assumption a command related to floppy disks does not
need to be part of default build.  Notice that the reference commit removed
floppy driver from linux about year ago.  Virtual floppies might exist they
should not need low-level formatting.  But if someone really needs this
enabling the build in that case is better than pushing the binary by
default to many many systems that install util-linux.

Reference: 47d6a76074
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 16:07:05 +00:00
Sami Kerola 32a4efc567
more: improve error messaging when input file is directory
Before this change the error message about directory was not informative,
and a little bit out of place.

    $ touch empty ; ./more ./empty /
    ::::::::::::::
    ./empty
    ::::::::::::::
    magic failed: cannot read fd 4 (Is a directory)
    ::::::::::::::
    /
    ::::::::::::::

After the change messaging is reverted back to what it used to be.

    $ ./more ./empty /
    ::::::::::::::
    ./empty
    ::::::::::::::

    *** /: directory ***

And while on it lets remove repeated fstat() call.

Fixes: 09070e1a65
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 16:07:05 +00:00
Sami Kerola 792ff9fcee
ul: make set_column() zero check more obvious
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 16:07:05 +00:00
Sami Kerola c7ad82209a
colrm: fix argument parsing
Short options had all sortss of characters listed, that were clearly copied
from col(1) command getopt_long() invocation.  Luckily both -V and -h were
part of the short options, but lets get rid of the unnecessary ones.

Fixes: 1647d032a7
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 16:06:56 +00:00
Sami Kerola 06229abccf
rfkill: stop execution when rfkill device cannot be opened
Without this two error messages are printed when rfkill device
cannot be opened.

    $ rfkill
    rfkill: cannot open /dev/rfkill: No such file or directory
    rfkill: cannot read /dev/rfkill: Bad file descriptor

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 15:22:34 +00:00
Sami Kerola a371c3f71e
cifuzz: reindent yaml file
Fixex two yamllint indentation warning, the truthy is false positive.

    util-linux $ yamllint ./.github/workflows/cifuzz.yml
      6:1       warning  truthy value should be one of [false, true]  (truthy)
      14:2      error    wrong indentation: expected 2 but found 1  (indentation)
      22:4      error    wrong indentation: expected 5 but found 3  (indentation)

Reference: https://github.com/adrienverge/yamllint
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 15:22:34 +00:00
Sami Kerola 3ea54b843c
man: make tilde and caret characters to render correctly
As mentioned in 'Generating optimal glyphs' title in the manual page
mentioned in reference:

    Where a proper caret (^) that renders well in both a terminal and PDF is
    required, use "\(ha".

    Using a naked "~" character results in a poor rendering in PDF.  Instead
    use "\(ti".

Reference: https://man7.org/linux/man-pages/man7/man-pages.7.html#STYLE_GUIDE
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 15:22:34 +00:00
Karel Zak d4cb6a0335 lscpu: fix memory leaks
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 10:20:33 +01:00
Masayoshi Mizuma 8014104bea lscpu-arm: Add "BIOS Vendor ID" and "BIOS Model name" to show the SMBIOS information.
After commit: 367c85c47 ("lscpu: use SMBIOS tables on ARM for lscpu"),
Model name for A64FX shows like as:

   Model name:       461F0010

That's because 367c85c47 changes to get the modelname from Processor
Version of SMBIOS.

To fix that, use the hard corded table to show the "Model name" and
add two new lines; "BIOS Vendor ID" and "BIOS Model name" to show the
SMBIOS information.

lscpu shows the SMBIOS information when root user runs it because
accessing the SMBIOS information requires root privilege.

[kzak@redhat.com: - port the patch to new lscpu code]

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 10:06:26 +01:00
Jeremy Linton dbc2772305 lscpu: Even more Arm part numbers
Over the past two years Arm has published further MIDR/part numbers
on https://developer.arm.com/ip-products/processors/cortex-a.

Lets sync the arm_part structure for A65, A76AE, A77 and A78*.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
2020-11-13 09:33:32 +01:00
Karel Zak 76b6666c0e lscpu: (arm) reuse parsed vendor ID
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 10b71aede2 lscpu: remove unused code
lscpu-dmi.c is no more used by new lscpu code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 60e7ccb8e8 lscpu: Adapt MIPS cpuinfo
Port commit

  commit 6cb8af7be2
  Author: Jiaxun Yang <jiaxun.yang@flygoat.com>
  Date:   Sat Mar 28 12:19:42 2020 +0800

to new lscpu code.

References: 6cb8af7be2
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak ddc92e3993 lscpu: add shared cached info for s390 lscpu -C
Port commit
 commit 318542e060
 Author: Sumanth Korikkar <sumanthk@linux.ibm.com>
 Date:   Fri Jun 5 18:15:10 2020 +0200

to new lscpu code.

References: 318542e060
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Thomas Abraham 80fcd2c802 lscpu: avoid segfault on PowerPC systems with valid hardware configurations
ntypes greater than 1 is valid in some hardware configurations, and an assert()
on the value isn't necessary or very future proof

[kzak@redhat.com: - port this patch to new code]

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 3e35c90170 lscpu: update tests
* cpu MHz is per-CPU value and not printed in summary anymore
* topology is reordered
* number of NUMA nodes is moved to NUMA section
* parsable output uses cache ID from kernel if avalable

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 05b9c556f6 lscpu: fix MHZ parsing
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak cc94324ebd lscpu: improve bogomips use
* keep global (cputype) bogomips
* add per-CPU bogomips
* use bogomips from the first CPU as global (for cputype) if /proc/cpuinfo does not provide global bogomips
* add BOGOMIPS column for to -e/-p output

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 6321d34f0f lscpu: add note about cache IDs
We read the ID from /sys/devices/system/cpu/cpu*/cache/index*/id.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 6d880d3d46 lscpu: add MHZ column
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 7155a57d34 lscpu: don't use section for extra caches
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak d4228e9de2 lscpu: fix for sparc64
We do not read CPUs from cpuinfo on sparc.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00