Commit graph

2697 commits

Author SHA1 Message Date
Lennart Poettering f8a8579e84 tmpfile-util: simplify umask reset declaration 2019-05-24 15:07:55 +02:00
Lennart Poettering 2dbb7e94af fs-util: rewrite chmod_and_chown()
Inspired by #12431 let's also rework chmod_and_chown() and make sure we
never add more rights to a file not owned by the right user.

Also, let's make chmod_and_chown() just a wrapper arond
fchmod_and_chown().

let's also change strategy: instead of chown()ing first and stating
after on failure and supressing errors, let's avoid the chown in the
firts place, in the interest on keeping things minimal.
2019-05-24 15:07:55 +02:00
Lennart Poettering d631a760e0
Merge pull request #12601 from keszybz/two-log-color-adjustments
Two log color adjustments
2019-05-24 10:43:07 +02:00
Zbigniew Jędrzejewski-Szmek 4c6d51390c basic/utf8: reduce memory usage 2019-05-22 10:22:20 +02:00
Zbigniew Jędrzejewski-Szmek e3b4efd28f Add 8bit-version of get_process_cmdline() and use in cgroup-show.c
This restores show_pid_array() output in legacy locales on the console.
Only one call to get_process_cmdline() is changed, all others retain
utf8-only mode. This affects systemd-cgls, systemctl status, etc, when
working locally.

Calls to get_process_cmdline() that cross a process boundary always use
utf8. It's the callers responsibility to convert this to some encoding that
they use. This means that we always pass utf8 over the bus.
2019-05-22 10:16:00 +02:00
Zbigniew Jędrzejewski-Szmek 09c1dceef1 basic/process-util: convert bool arg to flags
In preparation for the next commit…
2019-05-22 10:15:49 +02:00
Zbigniew Jędrzejewski-Szmek 70d558199c basic/escape: add truncation to xescape too
This does for ASCII and non-unicode encodings what utf8_escape_non_printable_full()
does for utf8-based encodings.
2019-05-22 10:11:00 +02:00
Zbigniew Jędrzejewski-Szmek 0e85cbcfc3 util-lib: do not truncate kernel comm names
It turns out that the kernel allows comm names higher than our expected limit
of 16.
$ wc -c /proc/*/comm|sort -g|tail -n3
35 /proc/1292317/comm
35 /proc/1293610/comm
36 /proc/1287112/comm
$ cat /proc/1287112/comm
kworker/u9:3-kcryptd/253:0
2019-05-22 10:09:35 +02:00
Zbigniew Jędrzejewski-Szmek bc28751ed2 Rework cmdline printing to use unicode
The functions to retrieve and print process cmdlines were based on the
assumption that they contain printable ASCII, and everything else
should be filtered out. That assumption doesn't hold in today's world,
where people are free to use unicode everywhere.

This replaces the custom cmdline reading code with a more generic approach
using utf8_escape_non_printable_full().
For kernel threads, truncation is done on the parenthesized name, so we'll
get "[worker]", "[worker…]", …, "[w…]", "[…", "…" as we reduce the number of
available columns.

This implementation is most likely slower for very long cmdlines, but I don't
think this is very important. The common case is to have short commandlines,
and should print those properly. Absurdly long cmdlines are the exception,
which needs to be handled correctly and safely, but speed is not too important.

Fixes #12532.

v2:
- use size_t for the number of columns. This change propagates into various
  other functions that call get_process_cmdline(), increasing the size of the
  patch, but the changes are rather trivial.
2019-05-22 10:08:17 +02:00
Zbigniew Jędrzejewski-Szmek da88f542d9 util-lib: add truncation based on printable width to utf8_escape_non_printable() 2019-05-22 09:50:19 +02:00
Zbigniew Jędrzejewski-Szmek 21c491e106 Introduce sc_arg_max() helper
Just a cast and an assert.
2019-05-21 10:57:23 +02:00
Topi Miettinen 0a51b45ce4 small fixes: make get_process_state() static and fix typo 2019-05-20 16:23:22 +02:00
Yu Watanabe 2968913e64 util: introduce in6_addr_hash_ops 2019-05-18 12:27:27 +09:00
Yu Watanabe c9f0f21e28
Merge pull request #12593 from AdrianBunk/master
Small changes from Yocto/musl builds
2019-05-18 10:25:59 +09:00
Zbigniew Jędrzejewski-Szmek a9009769de terminal-util: define yellow as "Khaki3"
Previously used "highlight yellow" was not visible on urxvt, because it
was too light. This color is shown as bold black by urxvt, but at least
it is readable. On other terminals it is shown as various hues of yellow,
pleasant on the eyes and not too bright. The color shown on linux console
could be called orange rather than yellow, but it is still readable.

(I also tried non-highlight "yellow", but it is not as readable.)

This is a follow-up for bb40c12569.
2019-05-17 15:06:59 +02:00
Andrej Valek 56e3c9581e fs-util.h: add missing sys/stat include
fix error:
| error: passing argument 5 of 'chase_symlinks_and_stat' from incompatible pointer type [-Werror=incompatible-pointer-types]
2019-05-17 09:40:46 +03:00
Chen Qi 56fb30d93e socket-util.h: include string.h
Fix the following compile error:
src/basic/socket-util.h:187:30: error: implicit declaration of function 'strnlen'; did you mean 'strlen'? [-Werror=implicit-function-declaration]
2019-05-17 09:38:06 +03:00
Zbigniew Jędrzejewski-Szmek e6042f682f
Merge pull request #12535 from poettering/color-grey
redefine how we select the ANSI color grey
2019-05-16 21:15:06 +02:00
Lennart Poettering 8550506439 random-util: add a longer comment explaining our RDRAND use 2019-05-16 19:23:08 +02:00
Lennart Poettering 9725f1a10f
Merge pull request #12378 from rbalint/vt-kbd-reset-check
VT kbd reset check
2019-05-16 16:39:38 +02:00
Yu Watanabe a3824444e5 linux: update headers from current kernel master 2019-05-16 10:24:47 +09:00
Balint Reczey 13a43c73d8 Add check to switch VTs only between K_XLATE or K_UNICODE
Switching to K_UNICODE from other than L_XLATE can make the keyboard
unusable and possibly leak keypresses from X.

BugLink: https://launchpad.net/bugs/1803993
2019-05-15 22:28:56 +02:00
Lennart Poettering 1c53d4a070 random-util: eat up bad RDRAND values seen on AMD CPUs
An ugly, ugly work-around for #11810. And no, we shouldn't have to do
this. This is something for AMD, the firmware or the kernel to
fix/work-around, not us. But nonetheless, this should do it for now.

Fixes: #11810
2019-05-10 15:31:46 -04:00
Lennart Poettering 003aa3e045 terminal-util: add complete set of inline functions for all colors we define
We don#t actually use all combinations, but it's kinda nice if we can
output all combinations in a test, and this is preparation so that we
can do so nicely.
2019-05-10 15:00:55 -04:00
Lennart Poettering 1530bf251a terminal-util: reduce colors we define a bit
three of these colors we never use, so let's drop them. Let's however
add a highlight version of grey, so that at least for all colors we do
define we have all possible styles defined.
2019-05-10 15:00:55 -04:00
Lennart Poettering bb40c12569 terminal-util: define grey as 256color ANSI sequence
Apparently all relevant terminals implement these sequences, including
the Linux kernel, rxvt, xterm, and of course gnome terminal. Hence it
should be OK to use them, and fixate the grey color in a way that maps
to the same color in all terminals.

Ideally we'd stick to the more symbolic colors that allow terminal
emulators to implement color styles, but this apparently doesn#t work,
since rxvt maps grey to something unreadable by default.

Note that this change has negative effects besides the non-themability
of the palette: the midrange grey this uses maps to regular white on the
linux console. However, that's probably not too bad: allowing things to
be unreadable on some terminals is probably worse than showing no color
on some terminals.

Fixes: #12482
2019-05-10 15:00:55 -04:00
Lennart Poettering e95be7def2
Merge pull request #12411 from keszybz/pr/12394
run: when emitting the calendarspec warning, use red
2019-05-08 10:11:32 -04:00
Evgeny Vereshchagin 7f2cdceaed util-lib: fix a typo in rdrand
Otherwise, the fuzzers will fail to compile with MSan:
```
../../src/systemd/src/basic/random-util.c:64:40: error: use of undeclared identifier 'sucess'; did you mean 'success'?
        msan_unpoison(&success, sizeof(sucess));
                                       ^~~~~~
                                       success
../../src/systemd/src/basic/alloc-util.h:169:50: note: expanded from macro 'msan_unpoison'
                                                 ^
../../src/systemd/src/basic/random-util.c:38:17: note: 'success' declared here
        uint8_t success;
                ^
1 error generated.
[80/545] Compiling C object 'src/basic/a6ba3eb@@basic@sta/process-util.c.o'.
ninja: build stopped: subcommand failed.
Fuzzers build failed
```
2019-05-08 16:10:06 +02:00
Zbigniew Jędrzejewski-Szmek ad3b2109c3
Merge pull request #12507 from poettering/random-fixlets
three minor fixes to random-util.c
2019-05-08 12:02:02 +02:00
Zbigniew Jędrzejewski-Szmek 0d0464d39d journalctl,shared/log: use yellow for warnings
In program output, highlighting warnings with ANSI_HIGHLIGHT is not enough,
because it doesn't stand out enough. Yellow is more appropriate.

I was worried that yellow wouldn't be visible on white background, but (at
least gnome-terminal) uses a fairly dark yellow that is fully legible on white
and light-colored backgrounds. We also used yellow in many places,
e.g. systemctl, so this should be fine.

Note: yellow is unreadable on urxvt with white background (urxvt +rv). But
grey, which we already used, is also unreadable, so urxvt users would have
to disable colors anyway, so this change does not make the problem
intrinsically worse. See
https://github.com/systemd/systemd/issues/12482#issuecomment-490374210.
2019-05-08 09:50:38 +02:00
Zbigniew Jędrzejewski-Szmek 37b8d2f699 basic/log: use colors to highlight messages like journalctl 2019-05-08 09:45:38 +02:00
Lennart Poettering 328f850e36 random-util: rename "err" to "success"
After all rdrand returns 1 on success, and 0 on failure, hence let's
name this accordingly.
2019-05-07 18:51:26 -04:00
Lennart Poettering 80eb560a5b random-util: hash AT_RANDOM getauxval() value before using it
Let's be a bit paranoid and hash the 16 bytes we get from getauxval()
before using them. AFter all they might be used by other stuff too (in
particular ASLR), and we probably shouldn't end up leaking that seed
though our crappy pseudo-random numbers.
2019-05-07 17:31:20 -04:00
Lennart Poettering cc28145d51 random-util: use gcc's bit_RDRND definition if it exists 2019-05-07 17:31:20 -04:00
Lennart Poettering 1a0ffa1e73 random-util: rename RANDOM_DONT_DRAIN → RANDOM_MAY_FAIL
The old flag name was a bit of a misnomer, as /dev/urandom cannot be
"drained". Once it's initialized it's initialized and then is good
forever. (Only /dev/random has a concept of 'draining', but we never use
that, as it's an obsolete interface).

The flag is still useful though, since it allows us to suppress accesses
to the random pool while it is not initialized, as that trips up the
kernel and it logs about any such attempts, which we really don't want.
2019-05-07 17:30:40 -04:00
Zbigniew Jędrzejewski-Szmek 6695c200bd shared/utmp-wtmp: silence gcc warning about strncpy truncation
Unfortunately the warning must be known, or otherwise the pragma generates a
warning or an error. So let's do a meson check for it.

Is it worth doing this to silence the warning? I think so, because apparently
the warning was already emitted by gcc-8.1, and with the recent push in gcc to
catch more such cases, we'll most likely only get more of those.
2019-05-07 21:05:26 +02:00
Zbigniew Jędrzejewski-Szmek 3759c0bdd3
Merge pull request #12440 from poettering/realloc-again
another shot at the malloc_usable_size() thing
2019-05-06 17:17:22 +02:00
Mike Gilbert 5797a12223 basic/mountpoint-util: whitelist 'exfat' in fstype_can_uid_gid 2019-05-06 16:43:22 +02:00
Lennart Poettering e59054270c alloc-util: reintroduce malloc_usable_size() into greedy_realloc()
This is another attempt at d4b604baea and #12438

Instead of blindly using the extra allocated space, let's do so only
after telling libc about it, via a second realloc(). The second
realloc() should be quick, since it never has to copy memory around.
2019-05-02 14:53:40 +02:00
Lennart Poettering 650c7a2e8b umask-util: simplify RUN_WITH_UMASK()
Why have a struct to store the iteration bit if we actually have plenty
place in mode_t?
2019-04-30 09:52:35 +02:00
Zbigniew Jędrzejewski-Szmek cb9ff7532b
Merge pull request #12434 from poettering/rm-rf-children-take-ptr
minor rm_rf_children() modernizations
2019-04-30 08:23:13 +02:00
Aaron Barany fcc72fd0f1 alloc-util: don't use malloc_usable_size() to determine allocated size
This reverts commit d4b604baea.

When realloc() is called, the extra memory between the originally
requested size and the end of malloc_usable_size() isn't copied. (at
least with the version of glibc that currently ships on Arch Linux)
As a result, some elements get lost and use uninitialized memory, most
commonly 0, and can lead to crashes.

fixes #12384
2019-04-30 08:20:59 +02:00
Lennart Poettering 987719d37d
Merge pull request #12414 from keszybz/detect-podman
Detect podman as separate container type
2019-04-29 19:07:24 +02:00
Ben Boeckel 5238e95759 codespell: fix spelling errors 2019-04-29 16:47:18 +02:00
Lennart Poettering 50b6eec154 rm-rf: simplify rm_rf_children() a bit by using _cleanup_close_ 2019-04-29 16:21:01 +02:00
Lennart Poettering c0ba6b9286 switch-root: modernize rm_rf_children() invocation a bit 2019-04-29 16:17:29 +02:00
Zbigniew Jędrzejewski-Szmek 90fb1f0938 basic/virt: treat "podman" as separate container type
We would detect podman as container-other. Let's assign a name to it.
Inspired by https://github.com/containers/libpod/issues/2996.
2019-04-29 15:36:26 +02:00
Zbigniew Jędrzejewski-Szmek 342bed0208 basic/virt: try the /proc/1/sched hack also for PID1
If a container manager does not set $container, we could end up
in a strange situation when detect-virt returns container-other when
run as non-pid-1 and none when run as pid-1.
2019-04-29 15:36:26 +02:00
Balint Reczey bb5ac84d79 Move verify_vc_kbmode() to terminal-util.c as vt_verify_kbmode() 2019-04-24 18:01:40 +02:00
Zbigniew Jędrzejewski-Szmek 67962036f6 basic/socket-util: put a limit on the loop to flush connections
Follow-up for #12346.
2019-04-23 15:24:56 +02:00