Commit Graph
34349 Commits
Author SHA1 Message Date
Lennart Poettering 78eee6ce4d repart: use free_and_strdup_warn() where appropriate 2021-04-19 23:16:02 +02:00
Lennart Poettering be9ce0188e repart: deal with empty partition label sensibly
libfdisk appears to return NULL when encountering an empty partition
label, let's handle this sanely, and treat NULL and "" for the current
label as the same, but for the new label as distinct: there NULL means
nothing is set, and "" means an actual empty label.
2021-04-19 23:16:02 +02:00
Lennart Poettering 22163eb51b repart: handle DISCARD failing with EBUSY gracefully 2021-04-19 23:16:02 +02:00
Lennart Poettering 55d380144a repart: add one more overflow check 2021-04-19 23:16:02 +02:00
Lennart Poettering d17db7b2bf repart: when we can't fit in all partitions explain how large the image would have to be 2021-04-19 23:16:02 +02:00
Lennart Poettering 252d626711 repart: add --image= switch
This is similar to the --image= switch in the other tools, like
systemd-sysusers or systemd-tmpfiles, i.e. it apply the configuration
from the image to the image.

This is particularly useful for downloading minimized GPT image, and
then extending it to the desired size via:

   # systemd-repart --image=foo.image --size=5G
2021-04-19 23:16:02 +02:00
Lennart Poettering 8e5f3cecdf repart: slightly improve error message if partition is not on dm-crypt/dm-verity 2021-04-19 23:16:02 +02:00
Lennart Poettering 0efb3f83da repart: move NOP destructors into shared code 2021-04-19 23:16:02 +02:00
Lennart Poettering ef9c184d3d dissect: split read-only flag into two
Let's have one flag to request that when dissecting an image the
loopback device is made read-only, and another one to request that when
it is mounted to make it read-only. Previously both concepts were always
done read-only together.

(Of course, making the loopback device read-only but mounting it
read-write doesn't make too much sense, but the kernel should catch that
for us, no need to make restrictions from our side there)

Use-case for this: in systemd-repart we'd like to operate on images for
adding partitions. Thus we'd like to have the loopback device writable,
but if we read repart.d/ snippets from it, we want to do that read-only.
2021-04-19 23:16:02 +02:00
Lennart Poettering 0ade2213e6 repart: port more code to generic path_simplify_and_warn()
We have this nice helper, hence use it when parsing paths and logging
about it.
2021-04-19 23:16:02 +02:00
Lennart Poettering a0ff997180 repart: fix incorrect error code propagation 2021-04-19 23:16:02 +02:00
Zbigniew Jędrzejewski-Szmek 05e13b3558 udev/cdrom_id: add forgotten return and fix typo
Fixup for 092c05717c.
2021-04-19 18:25:17 +01:00
Jason Francis a8310e39e9 sd-login: correct prototype of sd_peer_get_cgroup 2021-04-19 12:13:03 -04:00
Yu Watanabe 4e6c50a5d4 core: add RestrictAddressFamilies=none to deny all address families
Closes #15753.
2021-04-19 11:47:08 +01:00
Zbigniew Jędrzejewski-Szmek 59e8042ecd basic/log: change error for unset errno to ESTRPIPE
EIO is used in other contexts, so change ot something otherwise unused.
ENOTRECOVERABLE was also suggested, but it's used in various other places
in the code.

https://github.com/systemd/systemd/pull/19317#discussion_r614887661
2021-04-19 08:46:19 +02:00
Zbigniew Jędrzejewski-Szmek 19cdcd5dca logind: tweak log message
https://github.com/systemd/systemd/pull/19317#pullrequestreview-637765222
2021-04-19 08:37:57 +02:00
Zbigniew Jędrzejewski-Szmek 092c05717c udev/cdrom_id: use random_u64_range() and tweak log messages
https://github.com/systemd/systemd/pull/19317#pullrequestreview-637765222
2021-04-19 08:37:39 +02:00
Yu Watanabe 6604fb0207 fileio: use take_fdopen_unlocked()
This fixes maybe-uninitialized warning:
```
../src/basic/fileio.c: In function ‘chase_symlinks_and_fopen_unlocked’:
../src/basic/fileio.c:1026:19: warning: ‘f’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1026 |         *ret_file = f;
      |         ~~~~~~~~~~^~~

```
2021-04-17 00:22:12 +09:00
Yu Watanabe b4bc798f87 Merge pull request #19332 from yuwata/log_xxx_yyy_errno-follow-ups-19317
core,timedate,network: make log_unit_error_errno() or friends refuse zero errno
2021-04-16 23:44:32 +09:00
Yu Watanabe 74bd6ad016 network: update log message
In some optimization level with gcc, including netdev->ifname in log
message causes error.
2021-04-16 19:48:54 +09:00
Zbigniew Jędrzejewski-Szmek b990afe152 Merge pull request #19290 from yuwata/network-dhcp-do-not-configure-twice
network: refuse to configure DHCP client more than once
2021-04-16 12:36:23 +02:00
Zbigniew Jędrzejewski-Szmek b7c3447a2f Merge pull request #19310 from yuwata/network-dhcp-anonymize
network: dhcp4: several fixes and cleanups for Anonymize=
2021-04-16 11:12:22 +02:00
Yu Watanabe 6064344894 network: make log_netdev_xxx_errno() refuse zero errno 2021-04-16 09:17:28 +09:00
Yu Watanabe 5b098203fd timedate: make log_unit_xxx_errno() refuse zero errno 2021-04-16 08:46:51 +09:00
Yu Watanabe ac51363496 core: make log_unit_xxx_errno() refuse zero errno 2021-04-16 08:46:11 +09:00
Lennart Poettering bc32241e6a core: use UNIT_TRIGGER at more places
Just some minor simplification.
2021-04-15 20:38:20 +01:00
Luca Boccassi 2969369130 Merge pull request #19318 from yuwata/udev-ignore-additional-newline-on-verify-19314
udev: ignore additional newline at the end on verify
2021-04-15 20:36:55 +01:00
Luca Boccassi 2d8c8549ab Merge pull request #19317 from keszybz/check-return-values-from-log_errno-functions
Check return values from log_errno functions
2021-04-15 20:33:54 +01:00
Zbigniew Jędrzejewski-Szmek 8d1c9489ef Assert zero is not passed to log_{device,rule,token}_*_errno() 2021-04-15 11:56:22 +02:00
Zbigniew Jędrzejewski-Szmek 9d9fed9ef4 Voidify log_{device,token,rule}_debug()
See analogous change for log_debug() for discussion.
2021-04-15 11:45:44 +02:00
Lennart Poettering 5c9f1c68f0 core: drop pointless assert()
We checked this literally two lines earlier, no point in checking so
quickly again.
2021-04-15 11:26:40 +02:00
Zbigniew Jędrzejewski-Szmek 2669c66614 core/selinux: fix wrong assertion when 0 is passed to log_debug
https://github.com/systemd/systemd/pull/19317#issuecomment-820245680
2021-04-15 11:18:37 +02:00
Zbigniew Jędrzejewski-Szmek 3d346b8106 udev/cdrom_id: drop unnecessary cleanup and simplify loop 2021-04-15 07:51:58 +02:00
Zbigniew Jędrzejewski-Szmek ec77d1ab3b udev/cdrom_id: do not pass ioctl return value to log_debug_errno()
While at it, let's print the tray status in human readable form.
2021-04-15 07:49:31 +02:00
Zbigniew Jędrzejewski-Szmek 828b603a79 libsystemd-network: fix dhcp option buffer confusion
We were writing to the wrong buffer with a wrong offset :(
Bug present since the original introduction of the code in
04b28be1a3.
2021-04-15 13:46:48 +09:00
Zbigniew Jędrzejewski-Szmek 00dd6d7770 libsystemd-network: check that errno==0 is not passed to log functions 2021-04-14 23:32:10 +02:00
Zbigniew Jędrzejewski-Szmek a0c2541b6b libsystemd-network: use macro for definitions of log_{lldp,dhcp,…}_errno
No functional change.
2021-04-14 23:32:07 +02:00
Zbigniew Jędrzejewski-Szmek f407219cd1 Check that errno passed log_{interface,link}_*_errno() is non-zero 2021-04-14 22:53:49 +02:00
Yu Watanabe 22bbba8444 sd-dhcp-client: introduce sd_dhcp_client_is_running() 2021-04-14 22:31:28 +02:00
Zbigniew Jędrzejewski-Szmek e89f6ed476 Voidify log_link_debug
See analogous change for log_debug() for discussion.
2021-04-14 22:20:20 +02:00
Luca Boccassi 9264fb47d9 Merge pull request #19315 from yuwata/network-wait-online-address-family-follow-ups
network: several follow-ups for #19069
2021-04-14 21:17:00 +01:00
Zbigniew Jędrzejewski-Szmek cf5a2ee825 journald: fix %m usage 2021-04-14 22:06:02 +02:00
Yu Watanabe 6fb61918cc udev: ignore additional newline in sysfs attribute on verify
Some driver may automatically add additional newline at the end.
E.g., portno attribute for qeth driver.

Fixes #19314.
2021-04-15 01:46:58 +09:00
Yu Watanabe 6873d20392 fileio: introduce a new flag to make write_string_file() ignore trailing newline
When writing a sysfs attribute, kernel may automatically append newline
at the end, e.g., 'portno' attribute for qeth driver.
2021-04-15 01:40:52 +09:00
Zbigniew Jędrzejewski-Szmek 75029e150b Do not try to return 0 from log_debug()
As @yuwata correctly points out, this became broken when log_debug()
started returning -EIO. I wanted to preserve this pattern, but it turns
out it is not very widely used, and preserving it would make the whole
thing, already quite complicated, even more complex.

log_debug() is made like log_info() and friends, and returns void.
2021-04-14 17:45:11 +02:00
Zbigniew Jędrzejewski-Szmek a2eb2267e4 shared/module-util: fix errno value passed to log function
If r == 0, no harm done. But if r > 0, this would be interpreted as an
errno value, wrongly.
2021-04-14 17:10:36 +02:00
Zbigniew Jędrzejewski-Szmek a626cb15c0 basic/log: assert that 0 is not passed as errno, except in test code
Let's assert if we ever happen to pass 0 to one of the log functions.
With the preceding commit to return -EIO from log_*(), passing 0 wouldn't
affect the return value any more, but it is still most likely an error.
The unit test code is an exception: we fairly often pass the return value
to print it, before checking what it is. So let's assert that we're not
passing 0 in non-test code. As with the previous check for %m, this is only
done in developer mode. We are depending on external code setting
errno correctly for us, which might not always be true, and which we can't
test, so we shouldn't assert, but just handle this gracefully.

I did a bunch of greps to try to figure out if there are any places where
we're passing 0 on purpose, and couldn't find any.
The one place that failed in tests is adjusted.

About "zerook" in the name: I wanted the suffix to be unambiguous. It's a
single "word" because each of the words in log_full_errno is also meaningful,
and having one term use two words would be confusing.
2021-04-14 17:07:06 +02:00
Zbigniew Jędrzejewski-Szmek c5cb37d95e Merge pull request #19302 from bluca/uninit
tree-wide: avoid uninitialized warning on _cleanup_ variables
2021-04-14 16:25:35 +02:00
Zbigniew Jędrzejewski-Szmek 63275a7032 basic/log: assert that %m is not used when error is not set
This is only done in developer mode. It is a pretty rare occurence that we
make this kind of mistake. And even if it happens, the result is just a misleading
error message. So let's only do the check in non-release builds.
2021-04-14 16:19:54 +02:00
Zbigniew Jędrzejewski-Szmek cbe97b9c92 basic/log: force log_*_errno() to return negative
This silences some warnigns where gcc thinks that some variables are
unitialized. One particular case:

../src/journal/journald-server.c: In function 'ache_space_refresh':
../src/journal/journald-server.c:136:28: error: 'vfs_avail' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  136 |         uint64_t vfs_used, vfs_avail, avail;
      |                            ^~~~~~~~~
../src/journal/journald-server.c:136:18: error: 'vfs_used' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  136 |         uint64_t vfs_used, vfs_avail, avail;
      |                  ^~~~~~~~
cc1: all warnings being treated as errors

which is caused by

   d = opendir(path);
   if (!d)
           return log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR,
                                 errno, "Failed to open %s: %m", path);
   if (fstatvfs(dirfd(d), &ss) < 0)
           return log_error_errno(errno, "Failed to fstatvfs(%s): %m", path);

For some reason on aarch64 gcc thinks we might return non-negative here. In
principle errno must be set in both cases, but it's hard to say for certain.
So let's make sure that our code flow is correct, even if somebody forgot to
set the global variable somewhere.
2021-04-14 16:19:54 +02:00