The function read_buffer() implements read and clear functionally, but
we do not differentiate between these actions in main() for error
messages, and one generic "dmesg: read kernel buffer failed" is used
in all cases. That's a bug.
This patch removes the "clear" action from read_buffer() and keeps it
for buffer reading only. The "clear" action is implemented in main()
by separate klogctl(SYSLOG_ACTION_CLEAR) for cases. It means also for
"dmesg --read-clear"; we do not use SYSLOG_ACTION_READ_CLEAR anymore.
Now "clear+read" is:
* syslog: SYSLOG_ACTION_READ_ALL + SYSLOG_ACTION_CLEAR
* kmsg: /dev/kmsg read() + SYSLOG_ACTION_CLEAR
In old versions "dmesg --syslog --read-clear" (syalog backed) was
implemented by logctl(SYSLOG_ACTION_READ_CLEAR) and it returns no
data for non-root users (due to EPERM), "dmesg --read-clear" (kmsg)
returns data and EPERM for the "clear" action.
Now the command "dmesg --syslog --read-clear" and "dmesg --read-clear"
behaves in the same way -- returns data and EPERM for the "clear"
action.
Fixes: https://github.com/karelzak/util-linux/issues/1255
Signed-off-by: Karel Zak <kzak@redhat.com>
>>> CID 365738: Uninitialized variables (UNINIT)
>>> Using uninitialized value "ret". Field "ret" is uninitialized.
326 return ret;
Signed-off-by: Karel Zak <kzak@redhat.com>
The previous commit 7a08784ab0 reduced
number of situation when we need fallback when kbytes calculated for
shmall pages, but there is still possible to see overflows.
This patch add fallback also for kbytes.
Signed-off-by: Karel Zak <kzak@redhat.com>
Avoid computing the number of bytes in shmall, by only
computing and printing the number of Kbytes. This avoids
some overflows, e.g.
$ echo "4503599627370496" > /proc/sys/kernel/shmall
$ ipcs -l | grep 'max total shared memory'
Before:
max total shared memory (kbytes) = 18014398509481980
After:
max total shared memory (kbytes) = 18014398509481984
$ echo "99993599627370500" > /proc/sys/kernel/shmall
99993599627370500
$ ipcs -l | grep 'max total shared memory'
Before:
max total shared memory (kbytes) = 18014398509481980
After:
max total shared memory (kbytes) = 399974398509482000
v1->v2:
Print the non-overflow KB value only for IPC_UNIT_KB and
IPC_UNIT_DEFAULT.
This way --bytes and --human options will still get an expected
output
(but not avoiding the overflow).
Signed-off-by: Vasilis Liaskovitis <vliaskovitis@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
It seems like overkill to provide this #ifdef. For example coreutils
use "char *" for all selinux contexts (since 2014).
Signed-off-by: Karel Zak <kzak@redhat.com>
* '2020wk47' of https://github.com/kerolasa/util-linux:
build-sys: sort various lists in configure.ac
mkswap: tell how to fix insecure permissions and owner in warning
lsipc: make default output byte sizes to be in human units
man: add missing backslash to caret printing macro
lscpu: fix variable shadowing
uuidgen: give hint in usage() what uuid namepaces can be used
uuidgen: use errx() rather than fprintf() when priting errors
libuuid: simplify uuid_is_null() check
uuidparse: use uuid type definitions from libuuid header
uuidparse: use libuuid function to test nil uuid
The man-page indicates that mount expects UUIDs to be lower case.
Mention that NTFS and FAT volume IDs are to be specified in upper case.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Recent request to make ipcs(1) list sizes in human format caused the
observation lsipc(1) is not doing that either. This commit changes sizes to
human format, assuming --bytes option is not used.
Reference: https://github.com/karelzak/util-linux/issues/1199
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/lscpu-virt.c: In function ‘lscpu_read_virtualization’:
sys-utils/lscpu-virt.c:574:9: warning: declaration of ‘buf’ shadows a previous local [-Wshadow]
574 | char buf[256];
| ^~~
sys-utils/lscpu-virt.c:506:7: note: shadowed declaration is here
506 | char buf[BUFSIZ];
| ^~~
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/hwclock-rtc.c: In function 'synchronize_to_clock_tick_rtc':
sys-utils/hwclock.c:169:28: warning: 'now.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c:215:24: note: 'now.tv_usec' was declared here
sys-utils/hwclock.c:168:28: warning: 'now.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c:215:24: note: 'now.tv_sec' was declared here
sys-utils/hwclock.c:169:28: warning: 'begin.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c:215:17: note: 'begin.tv_usec' was declared here
sys-utils/hwclock.c:168:28: warning: 'begin.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c:215:17: note: 'begin.tv_sec' was declared here
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/blkdiscard.c: In function 'main':
sys-utils/blkdiscard.c:304:33: warning: 'now.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c:152:17: note: 'now.tv_usec' was declared here
sys-utils/blkdiscard.c:305:37: warning: 'now.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c:152:17: note: 'now.tv_sec' was declared here
sys-utils/blkdiscard.c:304:33: warning: 'last.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c:152:22: note: 'last.tv_usec' was declared here
sys-utils/blkdiscard.c:305:65: warning: 'last.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c:152:22: note: 'last.tv_sec' was declared here
Signed-off-by: Karel Zak <kzak@redhat.com>
Since the range of the ino_t data type is platform-specific (depending on
the wordsize), a usage of the fixed format specifier %PRIu64 is not correct
for ino_t on some 32-bit architectures, eg. ARM (Raspberry Pi 1). This issue
may lead to undefinied output and is not reported by gcc (in version 10.2.0
and 8.3.0-6+rpi1) even though -Wformat is enabled by -Wall. Therefore it is
most likely that it seems to be a false negative error in gcc's format
specifier check, so that this issue was never detected before.
This change fixes the issue by the use of a cast, since there is no
platform-independent format specifier for ino_t available. The wrong format
specifier %PRIu64 is replaced by %ju, where its corresponding variable of
type ino_t is casted to uintmax_t. The type uintmax_t represents the largest
platform-specific unsigned integer, so that all integer values are preserved
for a platform-independent printing.
Fixes: https://github.com/karelzak/util-linux/issues/1211
Signed-off-by: Manuel Bentele <development@manuel-bentele.de>
The shells are very restrictive about variable names, only [:alnum:]
chars are allowed (and alphabetic chars as the first char). The
library will replace "bad" chars with "_". The char '%' at the end is
replaced by _PCT.
Addresses: https://github.com/karelzak/util-linux/issues/1201
Signed-off-by: Karel Zak <kzak@redhat.com>
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.
- 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".
* 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
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
* 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>
Let's make it more robust and readable. The sysinfo file on s390 may
contain zeros, so we need to check the values and fallback to data
from shared maps if necessary.
Signed-off-by: Karel Zak <kzak@redhat.com>
Note that cxt->ncaches is number of all instances, but we split
output according to split output according to caches names.
Signed-off-by: Karel Zak <kzak@redhat.com>
The file /sys/devices/system/cpu/cpu*/cache/index*/id is not available
in old kernels. This patch add code to generate IDs according to cache
type and level.
Signed-off-by: Karel Zak <kzak@redhat.com>
* keep one sharedmap per cache instance
* initialize topology IDs to -1
* rewrite -e code to use a new data structs
Signed-off-by: Karel Zak <kzak@redhat.com>
The Dynamic and Static MHz are /proc/cpuinfo s390 per-CPU fields, but
we display it as a single value according the first parsed CPU. For
this purpose we store the values from the first CPU in lscpu_cputype.
For -p and -e outputs we will print per CPU values.
Signed-off-by: Karel Zak <kzak@redhat.com>
The cache is identified by Type, Level and ID, the ID is unique cache
instance identifier (of the type).
This changes forces lscpu allocate more lscpu_cache instances (than
old version), but now we're ready for arbitrary scenario where
different CPU types share caches and the same cache type uses
different size in different instances, etc.
Signed-off-by: Karel Zak <kzak@redhat.com>
This is the first step in conversion from old lscpu to the new code.
The patch removes obsolete code from lscpu.c and lscpu.h. The old
output code in lscpu.c is temporary disabled by #ifdef due to
incompatibility between old and new internal APIs -- this will be
changed later by small steps to make all all the changes review-able.
Signed-off-by: Karel Zak <kzak@redhat.com>
Don't use global CPU masks (like "online" or "present") to
calculate type specific number of threads due systems with
mixed CPU types.
It's also necessary to check all thread_siblings maps to get the
highest number, because some threads (CPUs) may be disables, for
example old lscpu calculates number of threads from the cpu0 and
if you disable cpu0's sibling (cpu4):
CPU(s): 8
On-line CPU(s) list: 0-7
Thread(s) per core: 2 <---
Core(s) per socket: 4
Socket(s): 1
# chcpu --disable 4
CPU 4 disabled
CPU(s): 8
On-line CPU(s) list: 0-3,5-7
Off-line CPU(s) list: 4
Thread(s) per core: 1 <--- !
Core(s) per socket: 4
Socket(s): 1
because 'thread_siblings' contains only one thread for cpu0:
# cat /sys/devices/system/cpu/cpu{0,1,2,3,4,5,6,7}/topology/thread_siblings_list
0
1,5
2,6
3,7
cat: /sys/devices/system/cpu/cpu4/topology/thread_siblings_list: No such file or directory
1,5
2,6
3,7
Signed-off-by: Karel Zak <kzak@redhat.com>
* move structs definitions to header file
* define set of /proc/cpuinfo parsing patterns for cpu-type and for
CPUs
Signed-off-by: Karel Zak <kzak@redhat.com>
The current lscpu assumes that all CPUs in the system are the same.
Unfortunately this is not true. We need to split all internal CPUs
descriptions to CPU-type and CPU.
This patch add lscpu-cputype.c where will be CPU-type description --
mostly based on /proc/cpuinfo.
Signed-off-by: Karel Zak <kzak@redhat.com>
When calling variadic functions, NULL must be explicitly cast to a
desired type.
This is noted in the exec(3) manpage.
The call in newgrp.c was changed for consistency.
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
Up on successful fdopendir(3) file descriptior that will be closed, that
happens in recursiveRemove() switch_root(8) function.
CID: 360697
Reference: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdopendir.html
Co-Author: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
If a call to chroot is not followed by a call to chdir("/") the chroot jail
confinement can be violated. See also CWE-243.
CID: 360718
CID: 360800
Reference: http://cwe.mitre.org/data/definitions/243.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Variable cap was 32 bits and shifting it by 64 bits resulted to the shift
going over a variable boundary.
CID: 360799
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
In 9995da0 we added support to fstrim to be able to fall back to
`/proc/self/mountinfo` if `/etc/fstab` didn't exist, but we forgot
to remove the `/etc/fstab` condition from the timer. Let's remove
that condition from the timer so we can go back to periodically
running `fstrim.service`.
issue report:
if i run the heavy duty test from #16859 a couple of times I can get
the loopback layer in the kernel into a state where there's a loopback
block device allocated, that you can open, but where both LOOP_CLR_FD
and _SET_FD fail with EBUSY. and /dev/loop-control still returns it as
the next free one... weird state util-linux losetup when called to
allocate a new device then freezes
This commit:
* restrict number of attempts to 16
* use 200000ms sleep between attempts
* add note about non-atomic loop device setup to the man page
Reported-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
The library is not distributed and almost all code in this ar(1)
archive is Public Domain or LGPL ... but let's avoid any doubts and do
not mix non-GPL and GPL code there.
Addresses: https://github.com/karelzak/util-linux/issues/1157
Signed-off-by: Karel Zak <kzak@redhat.com>