Commit graph

25388 commits

Author SHA1 Message Date
Lennart Poettering dc44c96d97 core: pass parse error to log functions when parsing timer expressions 2019-04-01 18:25:43 +02:00
Lennart Poettering 25a04ae55e core: simply timer expression parsing by using ".ltype" field of conf-parser logic
No change of behaviour. Let's just not parse the lvalue all the time
with timer_base_from_string() if we can already pass it in parsed.
2019-04-01 18:25:43 +02:00
Yu Watanabe 76e62a4d22 udev: move udev_ctrl_cleanup() into manager_free() 2019-04-01 15:20:03 +02:00
Lennart Poettering 245d386a03
Merge pull request #12157 from yuwata/network-netdev-name-conflict
network: handle NetDev.Name= conflict nicely
2019-04-01 15:17:07 +02:00
Yu Watanabe 4b4a6c9b41 udev: shorten code a bit 2019-04-01 10:30:31 +09:00
Yu Watanabe c6e77d7b22 network: add '=' to config key names in log
Also, long lines are wrapped.
2019-04-01 10:30:31 +09:00
Yu Watanabe b519908cac network: do not abort execution when NetDev.Name= conflicts
This also changes that .netdev files are loaded in ascending order.
Otherwise, when NetDev.ifname= setting conflicts with other .netdev file,
then .netdev file with large prefix number wins.
2019-04-01 10:30:31 +09:00
Yu Watanabe 18268197fa bootspec: fix memleak caused by setting invalid cleanup function 2019-03-31 23:31:29 +09:00
Yu Watanabe 7226337574 bootspec: add missing free() in boot_config_free() 2019-03-31 23:30:30 +09:00
Yu Watanabe b07b19dff8
Merge pull request #12147 from yuwata/network-gre-key-12144
network: make GRE and GRETAP support Key= or friends
2019-03-31 22:12:34 +09:00
Yu Watanabe a8b9a65c50 network: make GRE and GRETAP support Key=, InputKey=, OutputKey=, and SerializeTunneledPackets=
This also merge netdev_gre_fill_message_create() and netdev_erspan_fill_message_create().
2019-03-30 21:16:03 +09:00
Zbigniew Jędrzejewski-Szmek d923021aeb
Merge pull request #12048 from jengelh/master
rpm: avoid hiding errors from systemd commands
2019-03-29 22:27:31 +01:00
Yu Watanabe 9282f75bf4 network: make erspan netdev can be specified in Network.Tunnel= 2019-03-30 03:52:25 +09:00
Yu Watanabe 1a9bc3d8f6 network: do not continue when appending data to netlink message fails 2019-03-30 03:52:21 +09:00
Zbigniew Jędrzejewski-Szmek 6ea07d4fb4
Merge pull request #12140 from poettering/copy-early
chattr/copy.c fixes
2019-03-29 15:02:50 +01:00
Zbigniew Jędrzejewski-Szmek 983616735e
Merge pull request #12137 from poettering/socket-var-run
warn about sockets in /var/run/ too
2019-03-29 15:00:25 +01:00
Zbigniew Jędrzejewski-Szmek 2818ddc8f4
Merge pull request #12133 from poettering/rseq-whitelist
whitelist rseq() system call in `@default` syscall group
2019-03-29 14:59:00 +01:00
Lennart Poettering 196f306795 analyze: check both possible mount points of tracefs
Let's try the new one first, the old one second.
2019-03-29 14:57:37 +01:00
Lennart Poettering bd169c2be0 fsck: copy out device argument from argv[] before forking
We nowadays rename our child processes, hence argv[] will be clobbered,
let's hence copy the device path to dynamic memory before forking.

This is fall-out from 60ffa37a65 since we
now a lot more often end up overriding the argv[] buffer than before,
simple because we know what to override.

These kind of bugs kinda suck. THere are only two options here: stop
overriding argv[] for all cases (or just these cases) or explicitly
copying out everything we need in child processes before forking. With
this patch I opt for the latter, though I am not 100% convinced this is
a great solution. Just a better solution than everything else, i.e.
allowing argv[] to remain out of sync with what others see.

Fixes: #12135
2019-03-29 08:18:25 +01:00
Jörg Thalheim 7232c1f9da wireguard: fix exponential backoff when resolving hosts
It should stop at 25s, not start.
Fixes #12134
2019-03-28 20:00:19 +01:00
Zbigniew Jędrzejewski-Szmek f2dc22b447 headers: add missing includes
Fixes #12125.
2019-03-28 19:59:56 +01:00
Lennart Poettering b8a736d7a0 sd-bus: change "int" → "signed int" on bitfield
Apparently by the C standard "int" bitfields can have any signedness
(unlike non-bitfield declarations which are "signed" if the signedness
is not specified).

Let's fix the LGTM warning about this hence and be explicit that we mean
"signed" here.
2019-03-28 19:07:51 +01:00
Lennart Poettering d629ba7045 tmpfiles: move full chattr flag set to chattr-util.h
It's a pretty generic concept and fits will there, hence let's move it.
2019-03-28 18:43:05 +01:00
Lennart Poettering 75006470ce tmpfiles: support the FS_PROJINHERIT_FL chattr flag 2019-03-28 18:43:04 +01:00
Lennart Poettering 8a016c746e util-lib: when copying files make sure to apply some chattrs early, some late
Some chattrs only work sensible if you set them right after opening a
file for create (think: FS_NOCOW_FL). Others only work when they are
applied when the file is fully written (think: FS_IMMUTABLE_FL). Let's
take that into account when copying files and applying a chattr to them.
2019-03-28 18:43:04 +01:00
Lennart Poettering c3272fd4df missing: add FS_PROJINHERIT_FL
It's available since kernel 4.5, but not in older kernels.
2019-03-28 18:43:04 +01:00
Lennart Poettering 4a66b5c9bf core: complain and correct /var/run/ → /run/ for listening sockets
We already do that for PIDFile= paths, and for tmpfiles.d/ snippets,
let's also do this for .socket paths.
2019-03-28 16:59:57 +01:00
Lennart Poettering 7d2c9c6b50 load-fragment: use TAKE_PTR() where we can 2019-03-28 16:46:27 +01:00
Michal Sekletar 48da47eeca cryptsetup-generator: set high OOM score for systemd-cryptsetup instances
With new LUKS2 header format it is possible to use Argon2 key derivation
function. This function is "memory-hard" hence keyslot unlocking can
potentially use a lot of RAM as this increases resistance to massively
parallel GPU based password cracking.

However, when multiple systemd-cryptsetup binaries run at the same
time it is very likely that system using Argon2 (e.g. Fedora 30)
will encounter memory-pressure during early boot, following OOM killing
spree.

This patch aims to lower the damage done by OOM killer and sets OOMScore
for systemd-cryptsetup units to 500. Hopefully OOM killer will then
shoot us down and leave rest of the system services alone.
2019-03-28 15:52:41 +01:00
Lennart Poettering e8413b651b
Merge pull request #12130 from keszybz/fix-ndebug-builds
Fix ndebug builds
2019-03-28 15:52:27 +01:00
Lennart Poettering 6fee3be0b4 seccomp: add rseq() to default list of syscalls to whitelist
Apparently glibc is going to call this implicitly soon, hence let's
whitelist this by default.

Fixes: #12127
2019-03-28 12:09:38 +01:00
Lennart Poettering acd142af79 core: break overly long line 2019-03-28 12:09:38 +01:00
Lennart Poettering 2f6b9110fc core: parse '@default' seccomp group permissively
We are about to add system calls (rseq()) not available on old
libseccomp/old kernels, and hence we need to be permissive when parsing
our definitions.
2019-03-28 12:09:38 +01:00
Zbigniew Jędrzejewski-Szmek c6335c3b51
Merge pull request #12115 from poettering/verbose-job-enqueue
add "systemctl --show-transaction start" as a more verbose "systemctl start" that shows enqueued jobs
2019-03-28 11:04:26 +01:00
Zbigniew Jędrzejewski-Szmek ee36fed438 core: avoid unnecessary cast 2019-03-28 09:45:19 +01:00
Zbigniew Jędrzejewski-Szmek 3b1e405f36 test-terminal-util: fix sigsegv when compiled without asserts
I couldn't figure out what is going on here, because LTO inlines everything and
then the backtrace reported a different spot. But when compiled with NDEBUG but
no LTO, it's fairly obvious ;)

C.f. #12008.
2019-03-28 09:45:19 +01:00
Zbigniew Jędrzejewski-Szmek 10c353e1c5 Remove variable only used for an assert
When compiled with -DNDEBUG, we get warnings about set-but-unused variables.
In general, it's not something we care about, but since removing those
variables arguably makes the code nicer, let's just to it in this case.
2019-03-28 09:03:06 +01:00
Zbigniew Jędrzejewski-Szmek 4e494d17db test-terminal-util: add function logging 2019-03-28 09:03:06 +01:00
Lennart Poettering 0a6991e0bb tree-wide: reorder various structures to make them smaller and use fewer cache lines
Some "pahole" spelunking.
2019-03-27 18:11:11 +01:00
Lennart Poettering 6990fb6bc6 tree-wide: (void)ify a few unlink() and rmdir()
Let's be helpful to static analyzers which care about whether we
knowingly ignore return values. We do in these cases, since they are
usually part of error paths.
2019-03-27 18:09:56 +01:00
Lennart Poettering 36dbf97170
Merge pull request #12119 from keszybz/voidify-mkdir-p
Voidify mkdir_p() and normalize util.h includes
2019-03-27 15:05:51 +01:00
Zbigniew Jędrzejewski-Szmek 330b8fb379 journalctl: voidify mkdir_p() call and unify two similar code paths
Let's unify the two similar code paths to watch /run/systemd/journal.
The code in manager.c is similar, but it uses mkdir_p_label(), and unifying
that would be too much trouble, so let's just adjust the error messages to
be the same.

CID #1400224.
2019-03-27 13:01:44 +01:00
Lennart Poettering 1fd4c4edce terminal-util: add paranoid overflow check 2019-03-27 12:43:34 +01:00
Lennart Poettering f171decd3f terminal-util: modernize things with TAKE_PTR a bit 2019-03-27 12:43:34 +01:00
Lennart Poettering 85d9b5981b systemctl: add new --show-transaction switch
This new switch uses the new method call EnqueueUnitJob() for enqueuing
a job and showing the jobs it enqueued.

Fixes: #2297
2019-03-27 12:37:37 +01:00
Lennart Poettering 94369fc066 systemctl: split out extra args generation into helper function of its own 2019-03-27 12:37:37 +01:00
Lennart Poettering 5fd77930ad systemctl: reindent table 2019-03-27 12:37:37 +01:00
Lennart Poettering ee4296496f systemctl: more SYNTHETIC_ERRNO() conversion 2019-03-27 12:37:37 +01:00
Lennart Poettering c45e5fb877 systemctl: replace switch statement by table of structures 2019-03-27 12:37:37 +01:00
Lennart Poettering 50cbaba4fe core: add new API for enqueing a job with returning the transaction data 2019-03-27 12:37:37 +01:00
Zbigniew Jędrzejewski-Szmek 6e5dcce4b1 Voidify more mkdir_p calls 2019-03-27 11:53:12 +01:00
Zbigniew Jędrzejewski-Szmek ca78ad1de9 headers: remove unneeded includes from util.h
This means we need to include many more headers in various files that simply
included util.h before, but it seems cleaner to do it this way.
2019-03-27 11:53:12 +01:00
Zbigniew Jędrzejewski-Szmek b45556375e test-fileio: do not use variable before checking return value
Coverity is unhappy because we use "line" in the assert that checks
the return value. It doesn't matter much, but let's clean this up.
Also, let's not assume that /proc/cmdline contains anything.

CID #1400219.
2019-03-27 11:52:54 +01:00
Lennart Poettering 49bd196d69
Merge pull request #12110 from keszybz/sysv-compat-fix
Sysv-compat compilation fix
2019-03-27 09:29:13 +01:00
Lennart Poettering 175b43cb8e
Merge pull request #12116 from keszybz/mock-compilation-fixes
Fixes for compilation in Fedora 30 mock
2019-03-27 09:27:20 +01:00
Zbigniew Jędrzejewski-Szmek 10fd1d46fc shared/install: try even harder to make sure variable is initalized
Apparently the fix in a05294ff05 was
not sufficient. Let's declare the two arrays as static variables.
2019-03-26 19:58:17 +01:00
Zbigniew Jędrzejewski-Szmek be3f37528e util-lib: fix sentence in comment 2019-03-26 19:06:48 +01:00
Zbigniew Jędrzejewski-Szmek 2771aaf571 systemctl: define less stuff when !HAVE_SYSV_COMPAT
We'd translate our action to sysv runlevel action, only to discard the result
in talk_initctl(). Let's just ifdef the whole thing away.

Fixes #12103.
2019-03-26 19:06:48 +01:00
Zbigniew Jędrzejewski-Szmek 9ca5828475 test-execute: skip flaky test when we can't unshare namespaces
When running in Fedora "mock", / is a tmpfs and /home is not mounted. The test
assumes that /home will be a tmpfs only and only if we can unshare. Obviously,
this does not hold in this case, because unsharing is not possible, but /home
is still a tmpfs. Let's just skip the test, since it's fully legitimate to
mount either or both of / and /home as tmpfs.
2019-03-26 18:53:53 +01:00
Zbigniew Jędrzejewski-Szmek 6aed6a1157 test-execute: provide custom failure message
test_exec_ambientcapabilities: exec-ambientcapabilities-nobody.service: exit status 0, expected 1

Sometimes we get just the last line, for example from the failure summary,
so make it as useful as possible.
2019-03-26 18:53:53 +01:00
Lennart Poettering aed9834289 sleep: (void)ify some call 2019-03-26 11:17:23 +01:00
Lennart Poettering 427646ea9d sleep: use negative_errno() where appropriate 2019-03-26 11:17:23 +01:00
Lennart Poettering adca059d55
Merge pull request #12044 from keszybz/ttyname-malloc-simplification
util-lib: use a fixed buffer size for terminal path
2019-03-26 10:05:29 +01:00
Lennart Poettering 0d53f53bbd tests: add simple testcase for getttyname_malloc() 2019-03-26 09:10:21 +01:00
Zbigniew Jędrzejewski-Szmek e1af3bc62a
Merge pull request #12106 from poettering/nosuidns
add "nosuid" flag to exec directory mounts of DynamicUser=1 services
2019-03-26 08:58:00 +01:00
Zbigniew Jędrzejewski-Szmek 83eee14f46 logind: reword the polkit prompt for reboot parameter
Let's opt for the simplest description possible so that users actually
understand what we have in mind.
2019-03-26 08:52:18 +01:00
Zbigniew Jędrzejewski-Szmek 99f57a4fea
Merge pull request #12105 from poettering/api-vfs-mount-flags
some API VFS mount flag tweaks
2019-03-26 08:32:53 +01:00
Lennart Poettering 607b358ef2 core: drop suid/sgid bit of files/dirs when doing recursive chown
This adds some extra paranoia: when we recursively chown a directory for
use with DynamicUser=1 services we'll now drop suid/sgid from all files
we chown().

Of course, such files should not exist in the first place, and noone
should get access to those dirs who isn't root anyway, but let's better
be safe than sorry, and drop everything we come across.
2019-03-26 08:29:37 +01:00
Lennart Poettering 25e68fd397 nspawn: minor improvements to --help text 2019-03-26 08:06:00 +01:00
Lennart Poettering 9ce4e4b0f6 namespace: when DynamicUser=1 is set, mount StateDirectory= bind mounts "nosuid"
Add even more suid/sgid protection to DynamicUser= envionments: the
state directories we bind mount from the host will now have the nosuid
flag set, to disable the effect of nosuid on them.
2019-03-25 19:57:15 +01:00
Lennart Poettering 849b9b85b8 nspawn: mount mqueue with nodev,noexec,nosuid, too
The host mounts it like that, nspawn hence should do too.

Moreover, mount the file system after doing CLONEW_NEWIPC so that it
actually reflects the right mqueues. Finally, mount it wthout
considering it fatal, since POSIX mqueue support is little used and it
should be fine not to support it in the kernel.
2019-03-25 19:53:05 +01:00
Lennart Poettering 64e82c1976 mount-util: beef up bind_remount_recursive() to be able to toggle more than MS_RDONLY
The function is otherwise generic enough to toggle other bind mount
flags beyond MS_RDONLY (for example: MS_NOSUID or MS_NODEV), hence let's
beef it up slightly to support that too.
2019-03-25 19:33:55 +01:00
Lennart Poettering f0a95a2c6d mount-util: use set_put_strdup() where appropriate 2019-03-25 19:33:55 +01:00
Lennart Poettering f8b1904f96 mount-util: don't clobber return value in umount_recursive()
We shouldn't override 'r' with the result of cunescape(), since we use
it to return the last error of umount().
2019-03-25 19:33:55 +01:00
Lennart Poettering 867189b545 namespace: get rid of {} around single-line if blocks 2019-03-25 19:33:55 +01:00
Lennart Poettering 39e91a2777 namespace: get rid of local variable 2019-03-25 19:33:55 +01:00
Lennart Poettering 1019a48f40 namespace: (void)ify a number of syscalls 2019-03-25 19:33:55 +01:00
Lennart Poettering 5f7a690aaa namespace: replace one case of stack allocation with heap allocation
The list of mounts might grow quite large, let's avoid the stack for
this. Better safe than sorry.
2019-03-25 19:33:55 +01:00
Lennart Poettering 1d52a931c6 systemctl: move --failed close to --state= in help text 2019-03-25 15:25:58 +01:00
Lennart Poettering 8e54300425 systemctl: underline sections in help text
Taking inspiration from the recent commit that added that to nspawn's
help text.
2019-03-25 15:25:58 +01:00
Lennart Poettering 3bfa8668b0 systemctl: use structured initialization 2019-03-25 15:25:57 +01:00
Lennart Poettering 2f50e59f2b systemctl: use SYNTHETIC_ERRNO everywhere 2019-03-25 15:23:08 +01:00
Lennart Poettering 63a3b3cb70 systemctl: split out some SysV compat stuff into its own C file
systemctl.c is way to large already. Let's split out some stuff out that
is easy to split out.
2019-03-25 15:23:08 +01:00
Lennart Poettering b82f71c7ff tree-wide: constify a few static string tables 2019-03-25 14:04:34 +01:00
Lennart Poettering ebfb1b5724 dbus-unit: remove redundant check
We checked this with an assert() a few lines up aleady, no need to check
this again.
2019-03-25 13:48:53 +01:00
Lennart Poettering e59ba56d78 core: remove unnecessary heap allocation 2019-03-25 13:48:53 +01:00
Yu Watanabe 1beabe08d6 network,udev: explicitly declare 'conditions' is a list 2019-03-24 00:35:39 +09:00
Yu Watanabe 7bb55ed099 util: fix condition_free_list_type()
This fixes a bug introduced by c4f58deab5.

Closes oss-fuzz#13878, oss-fuzz#13882, oss-fuzz#13884, oss-fuzz#13886, and
oss-fuzz#13888.
2019-03-24 00:34:33 +09:00
Lennart Poettering 16b4623620
Merge pull request #11602 from vesajaaskelainen/dbus-reboot-with-parameters
dbus-manager: Add RebootWithParameters d-bus method
2019-03-22 21:07:47 +01:00
Lennart Poettering 83276695c6
Merge pull request #12079 from keszybz/fuzz-nspawn-oci
Add fuzzer for nspawn-oci
2019-03-22 21:06:17 +01:00
Jan Engelhardt b0ca726585 rpm: avoid hiding errors from systemd commands
Humans are susceptible to making orthographic errors sometimes. A
misspelled "%systemd_post caek.service" would go unnoticed due to all
output from systemctl being discarded if and when %post runs.

To alleviate this, cease hiding outputs. Then, to account for the
potential absence of systemd from the system, add file checks so as
to not generate a "command not found" error.
2019-03-22 20:54:59 +01:00
Vesa Jääskeläinen 428b296a59 logind: Add support for RebootParameter
This adds support for user to set & get reboot parameter for reboot.

As callee would be next issuing Reboot call same policy checks are being used.

If unit file issuing the reboot action defines RebootArgument (or similar) that
setting takes precedence.
2019-03-22 20:30:33 +02:00
Lennart Poettering e4077ff6f3 nspawn: don't free "fds" twice
Previously both run() and run_container() would free 'fds'. Let's fix
that, and let run() free it but make run_container() already remove all
fds from it, because that's what we actually want to do.

Fixes: #12073
2019-03-22 18:11:27 +01:00
Zbigniew Jędrzejewski-Szmek b2645747b7 nspawn-oci: fix double free
Also rename function to make it clear that it also frees the array
object itself.
2019-03-22 17:39:12 +01:00
Zbigniew Jędrzejewski-Szmek 54ed9f88dc udev/link-config: rename MACPolicy to MACAddressPolicy
Things are clearer if the same name is used everywhere, and we don't gain
much by saving a few bytes.
2019-03-22 17:16:17 +01:00
Zbigniew Jędrzejewski-Szmek 094eecd29d
Merge pull request #12055 from poettering/save-argc-argv
main-func.h and systemctl argc/argv improvements
2019-03-22 16:58:18 +01:00
Zbigniew Jędrzejewski-Szmek 4210e60eb6
Merge pull request #12072 from poettering/string-table-fixes
three small string table fixes
2019-03-22 16:49:56 +01:00
Vesa Jääskeläinen ce7f10707d logind: relocate function return_test_polkit()
Relocate function return_test_polkit() upper in file for easier access from other functions.
2019-03-22 17:38:54 +02:00
Vesa Jääskeläinen 77defcf538 systemctl: restore "systemctl reboot ARG" functionality
Commit d85515edcf changed logic how reboot is
executed. That commit changed behavior to use emergency action reboot code path
to perform the reboot.

This inadvertently broke rebooting with argument:
$ systemctl reboot custom-reason

Restore original behavior so that if reboot service unit similar to
systemd-reboot.service is executed it is possible to override reboot reason
with "systemctl reboot ARG".

When "systemctl reboot ARG" is executed ARG is placed in file
/run/systemd/reboot-param and reboot is issued using logind's Reboot
dbus-service.

If RebootArgument is specified in systemd-reboot.service it takes precedence
over what systemctl sets.

Fixes: #11828
2019-03-22 17:38:54 +02:00
Evgeny Vereshchagin 53294d9496 network: add missing nulstr terminator
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=13821
2019-03-22 13:25:42 +01:00
Lennart Poettering c425c7c245 dbus-execute: don't needlessly override error code 2019-03-22 12:25:16 +01:00
Lennart Poettering b1ea85dc08 dbus-execute: lets use exec_directory_type_from_string() to simplify things 2019-03-22 12:25:03 +01:00
Lennart Poettering 0f4b93c4b5 udev: use string_table_lookup() where we can 2019-03-22 12:21:12 +01:00
Lennart Poettering 63c691c648 string-table: use string_table_lookup() in our own macros everywhere 2019-03-22 12:21:12 +01:00
Zbigniew Jędrzejewski-Szmek b1f13b0e75 nspawn-oci: mount source is optional 2019-03-22 12:04:32 +01:00
Zbigniew Jędrzejewski-Szmek b2e07b1a02 nspawn-oci: use _cleanup_ in one more place 2019-03-22 11:51:21 +01:00
Zbigniew Jędrzejewski-Szmek 9ddd62cda1 fuzz-nspawn-oci: add fuzzer for the oci bundle loader 2019-03-22 11:09:52 +01:00
Lennart Poettering ae408d77a9 nspawn: conditionalize libseccomp use
We support compilation without libseccomp, hence don't rely on its
symbols.
2019-03-22 11:07:03 +01:00
Yu Watanabe 3f4c9bc04c
Merge pull request #12066 from yuwata/fix-network-tunnel-12041
network: fix netdev_tunnel_verify()
2019-03-22 05:57:38 +09:00
Lennart Poettering e947830460
Merge pull request #12046 from keszybz/simplify-invocation-id-check
sd-id128: look for invocation id in environment first, keyring second
2019-03-21 19:15:49 +01:00
Jan Engelhardt 085f826676 rpm: check argument counts for systemd macros
Invoking %systemd_tmpfiles (in %post) without any arguments, while
possible, will cause systemd-tmpfiles to process the entire system
configuration, rather than just the newly installed configuration
files. In https://github.com/systemd/systemd/pull/12048, it was
established that processing everything constitutes unusual practice,
and should be flagged as a mistake at build time.

Furthermore, invoking %systemd_post without any arguments will cause
the underlying `systemctl preset` to outright return an error ("Too
few arguments") when run. This can be flagged during build time in
the same manner.

As I have found no ways to successfully nest %if clauses inside a
macro[1], I am helping myself by reusing the recursive variable
expansion technique pioneered in [2].

Now, when %systemd_post or %systemd_tmpfiles is incorrectly used,
rpm gives accurate line number reporting, too:

	error: This macro requires some arguments
	error: line 11: %{systemd_post}

	error: This macro requires two arguments
	error: line 13: %{tmpfiles_create_package meh more more}

[1] what has been tried: %{expand:%%if "%#" == 0 \\\
    %%{error:you have given me %# args} \\\
    %%endif}

[2] http://git.savannah.gnu.org/cgit/automake.git/commit/?id=e0bd4af16da88e4c2c61bde42675660eff7dff51
2019-03-21 19:01:33 +01:00
Yu Watanabe b239288f72
Merge pull request #11931 from yuwata/condition-test-list
split static condition tests from net_match_config()
2019-03-22 02:30:57 +09:00
Lennart Poettering 8d1ee64829 systemctl: make a copy of the "verb" from argv[] before forking off a child 2019-03-21 18:10:06 +01:00
Lennart Poettering a0c6f3cb66 main-func: make sure we destruct memory and stuff last
Let's terminate pagers and agents before releasing all memory.
2019-03-21 18:10:06 +01:00
Lennart Poettering 290cb8e883 systemctl: tiny optimization 2019-03-21 18:10:06 +01:00
Lennart Poettering b1dffbb91b systemctl: add missing OOM check 2019-03-21 18:10:06 +01:00
Lennart Poettering 3483460cb8 systemctl: document argv[] array 2019-03-21 18:10:06 +01:00
Lennart Poettering d86e4c979a systemctl: use saved_argv where we can
No need to have another variable where we keep the original argv[].
Let's juse reuse the one DEFINE_MAIN_FUNCTION() stores for us anyway.
2019-03-21 18:10:06 +01:00
Lennart Poettering 60ffa37a65 main-func: implicitly save argc/argv in DEFINE_MAIN_FUNCTION() functions
Let's remove the risk of forgetting to save argc/argv if
DEFINE_MAIN_FUNCTION() is used.
2019-03-21 18:10:06 +01:00
Lennart Poettering 36fea15565 util: introduce save_argc_argv() helper 2019-03-21 18:08:56 +01:00
Lennart Poettering c82cfae00b
Merge pull request #12062 from poettering/nspawn-main-func
nspawn: port to DEFINE_MAIN_FUNCTION()
2019-03-21 18:08:27 +01:00
Yu Watanabe bb9683e096 network: fix netdev_tunnel_verify()
Fixes #12041.
2019-03-22 01:47:38 +09:00
Zbigniew Jędrzejewski-Szmek bb068de080 nspawn: add --no-pager switch
It only matters for --help.
2019-03-21 17:42:43 +01:00
Zbigniew Jędrzejewski-Szmek 9dd6ccf7c0
Merge pull request #12014 from poettering/systemctl-exit-fix
systemctl fallback error propagation fix
2019-03-21 17:37:09 +01:00
Zbigniew Jędrzejewski-Szmek 05a8a7a0fb
Merge pull request #12052 from poettering/systemctl-fixlets
systemctl refactorings
2019-03-21 17:33:44 +01:00
Zbigniew Jędrzejewski-Szmek c8c194a982
Merge pull request #12057 from poettering/chown-tty
chown TTY back to root:tty after a service terminates that used them
2019-03-21 17:31:19 +01:00
Lennart Poettering 04f590a4a4 nspawn: voidify sd_notify() calls 2019-03-21 16:32:46 +01:00
Lennart Poettering 6145bb4f78 nspawn: port to static destructors 2019-03-21 16:32:46 +01:00
Lennart Poettering 44dbef90f1 nspawn: port to main-func.h logic 2019-03-21 16:32:46 +01:00
Yu Watanabe c4f58deab5 network,udev: split static condition tests from net_match_config() 2019-03-21 23:37:39 +09:00
Yu Watanabe 2bd0da7a05 network: drop unnecessary strdup() 2019-03-21 23:37:39 +09:00
Yu Watanabe f9f88198ce core/unit: use condition_test_list() 2019-03-21 23:37:39 +09:00
Yu Watanabe 828fa6108b condition: introduce condition_test_list() 2019-03-21 23:37:39 +09:00
Yu Watanabe f6d6d53237 log: expose log_object_internalv() 2019-03-21 23:37:39 +09:00
Zbigniew Jędrzejewski-Szmek fa28e4e377
Merge pull request #12059 from poettering/nspawn-typos
some typo and other fixes result of the OCI nspawn merge
2019-03-21 15:14:11 +01:00
Lennart Poettering c3d13d2ad5
Merge pull request #12058 from keszybz/oci-simplifications
Follow-ups for nspawn-oci review
2019-03-21 13:55:09 +01:00
Lennart Poettering f4e803c809 nspawn: add a few missing flags from --help text 2019-03-21 13:31:09 +01:00
Lennart Poettering 2514865391 nspawn: reorder --help text, and add section
The list is so long, let's add a bit of structure and order things a
bit.
2019-03-21 13:27:19 +01:00
Lennart Poettering 2c9b7a7e62 mount: when we fail to establish an inaccessible mount gracefully, undo the mount 2019-03-21 12:41:02 +01:00
Lennart Poettering 74b6ce90a0 capability: add a test that fails if we ever enter > 64bit capability territory 2019-03-21 12:38:18 +01:00
Lennart Poettering 46eda04373 capability: also cap CAP_LAST_CAP at 63 2019-03-21 12:37:30 +01:00
Lennart Poettering 664ff517d3 capability: typo fix 2019-03-21 12:31:36 +01:00
Lennart Poettering 246bb37044 capability: use UINT64_C() where appropriate 2019-03-21 12:31:29 +01:00
Lennart Poettering bff749416e capability: minimize scope of a few variables 2019-03-21 12:31:14 +01:00
Lennart Poettering 15ce3f2664 capability: minor coding style updates 2019-03-21 12:30:49 +01:00
Lennart Poettering d09a25855f capability: add missing ')'
As pointed out by @polarina

d0b6a10c00 (commitcomment-32857641)
2019-03-21 12:29:18 +01:00
Zbigniew Jędrzejewski-Szmek c924888ffd sd-id128: look for invocation id in environment first, keyring second
As general principle, we generally check command line args first, the
enviroment second, and external configuration and system state only later.
In case of the invocation ID, checking the keyring before the environment
was implemented as a poor-man's security measure. But this is not really
useful, since we're moving within the same security boundary. So let's just
do the expected thing, and check environment first.

Prompted by https://github.com/systemd/systemd/pull/11991#issuecomment-474647652.
2019-03-21 12:06:15 +01:00
Zbigniew Jędrzejewski-Szmek 6757a01356 util-lib: get rid of a helper variable 2019-03-21 11:08:58 +01:00
Zbigniew Jędrzejewski-Szmek f1531db5af nspawn-oci: add helper function for free_and_strdup with oom check 2019-03-21 11:08:58 +01:00
Zbigniew Jędrzejewski-Szmek d0b6a10c00
Merge pull request #9762 from poettering/nspawn-oci
OCI runtime support for nspawn
2019-03-21 11:01:53 +01:00
Zbigniew Jędrzejewski-Szmek 19130626a0 nspawn-oci: use SYNTHETIC_ERRNO 2019-03-21 10:51:43 +01:00
Lennart Poettering 6f765baf23 core: rework how we reset the TTY after use by a service
This makes two changes:

1. Instead of resetting the configured service TTY each time after a
   process exited, let's do so only when the service goes back to "dead"
   state. This should be preferable in case the started processes leave
   background child processes around that still reference the TTY.

2. chmod() and chown() the TTY at the same time. This should make it
   safe to run "systemd-run -p DynamicUser=1 -p StandardInput=tty -p
   TTYPath=/dev/tty8 /bin/bash" without leaving a TTY owned by a dynamic
   user around.
2019-03-20 21:28:02 +01:00
Lennart Poettering 6c0ae73956 execute: split check if we might touch a tty out of exec_context_may_touch_console()
Some simple refactoring that'll come handy in a later commit.
2019-03-20 21:20:00 +01:00
Lennart Poettering 955f1c852e execute: use path_equal() to compare tty names
After all they might be strings such as pts/1 which we really should
consider the same as pts//1.
2019-03-20 21:18:59 +01:00
Lennart Poettering 4bf953d91b
Merge pull request #12049 from keszybz/assorted-fixups
Assorted fixups
2019-03-20 18:27:34 +01:00
David Michael 82bd4da71e shared/install: Preserve escape characters for escaped unit names
Since switching to extract_first_word with no flags for parsing
unit names in 4c9565eea5, escape
characters will be stripped from escaped unit names such as
"mnt-persistent\x2dvolume.mount" resulting in the unit not being
configured as defined.  Preserve escape characters again for
compatibility with existing preset definitions.
2019-03-20 18:26:24 +01:00
Lennart Poettering 2e13c0c354 systemctl: start_unit() returns > 0 on error, let's catch that properly
Let's make sure we fall back correctly to initctl when start_unit()
returns an error > 0.

Fixes: #11546
2019-03-20 15:05:27 +01:00
Lennart Poettering 9dccc6d3ae systemctl: use strv_consume() where we can 2019-03-20 14:53:07 +01:00
Lennart Poettering 61ff45db95 systemctl: port to static destructors 2019-03-20 14:53:07 +01:00
Zbigniew Jędrzejewski-Szmek d3bdba3816 test-fileio: avoid warning about ineffective comparison
On arm64 with gcc-8.2.1-5.fc29.aarch64:
../src/test/test-fileio.c:645:29: warning: comparison is always false due to limited range of data type [-Wtype-limits]
                 assert_se(c == EOF || safe_fgetc(f, &c) == 1);
                             ^~

Casting c to int is not enough, gcc is able to figure out that the original
type was unsigned and still warns. So let's just silence the warning like
in test-sizeof.c.
2019-03-20 14:00:12 +01:00
Zbigniew Jędrzejewski-Szmek afd5c1e373 sd-bus: reduce scope of variable 2019-03-20 13:34:35 +01:00
Zbigniew Jędrzejewski-Szmek 96d2e0978d sd-bus: avoid IN_SET() invocation with two identical values
Fixes #12036.

../../../src/systemd/src/libsystemd/sd-bus/bus-objects.c: In function ‘add_object_vtable_internal’:
../../../src/systemd/src/basic/macro.h:423:19: error: duplicate case value
2019-03-20 13:28:29 +01:00
Zbigniew Jędrzejewski-Szmek cc99274d7d test-alloc-util: add a smoke test for greedy_realloc 2019-03-20 13:17:27 +01:00
Zbigniew Jędrzejewski-Szmek a49945e663
Merge pull request #12033 from fbuihuu/watched-process-improvments
Watched process improvments
2019-03-20 13:03:06 +01:00
Zbigniew Jędrzejewski-Szmek ec7b77642c
Merge pull request #12047 from poettering/cryptsetup-fixlets
some small cryptsetup, ask-password and allocation fixlets
2019-03-20 13:02:34 +01:00
Chris Morin 08f9e80b3f journal-file: handle SIGBUS on offlining thread
The thread launched in journal_file_set_offline() accesses a memory
mapped file, so it needs to handle SIGBUS. Leave SIGBUS unblocked on the
offlining thread so that it uses the same handler as the main thread.

The result of triggering SIGBUS in a thread where it's blocked is
undefined in Linux. The tested implementations were observed to cause
the default handler to run, taking down the whole journald process.

We can leave SIGBUS unblocked in multiple threads since it's handler is
thread-safe. If SIGBUS is sent to the journald process asynchronously
(i.e. with kill, sigqueue, or raise), either thread handling it will
result in the same behavior: it will install the default handler and
reraise the signal, killing the process.

Fixes: #12042
2019-03-20 13:02:04 +01:00
Zbigniew Jędrzejewski-Szmek 45ce112002
Merge pull request #12024 from poettering/bindtoifindex
use SO_BINDTOIFINDEX where appropriate
2019-03-20 11:16:51 +01:00
Franck Bui 01542056aa scope: tiny cleanup: UNIT(s) -> u
No functional changes.
2019-03-20 10:51:49 +01:00
Franck Bui 846a07b505 core: only watch processes when it's really necessary
If we know that main pid is our child then it's unnecessary to watch all
other processes of a unit since in this case we will get SIGCHLD when the main
process will exit and will act upon accordingly.

So let's watch all processes only if the main process is not our child since in
this case we need to detect when the cgroup will become empty in order to
figure out when the service becomes dead. This is only needed by cgroupv1.
2019-03-20 10:51:49 +01:00
Franck Bui f75f613d25 core: reduce the number of stalled PIDs from the watched processes list when possible
Some PIDs can remain in the watched list even though their processes have
exited since a long time. It can easily happen if the main process of a forking
service manages to spawn a child before the control process exits for example.

However when a pid is about to be mapped to a unit by calling unit_watch_pid(),
the caller usually knows if the pid should belong to this unit exclusively: if
we just forked() off a child, then we can be sure that its PID is otherwise
unused. In this case we take this opportunity to remove any stalled PIDs from
the watched process list.

If we learnt about a PID in any other form (for example via PID file, via
searching, MAINPID= and so on), then we can't assume anything.
2019-03-20 10:51:49 +01:00
Franck Bui 4d05154600 process-util: introduce pid_is_my_child() helper
No functional changes.
2019-03-20 10:51:49 +01:00
Lennart Poettering 054b6be05b ask-password: add extra paranoid overflow check 2019-03-20 10:48:33 +01:00
Lennart Poettering 32ae18206f alloc-util: typo fix 2019-03-20 10:48:33 +01:00
Lennart Poettering d4b604baea alloc-util: use malloc_usable_size() to determine allocated size
It's a glibc-specific API, but supported on FreeBSD and musl too at
least, hence fairly common. This way we can reduce our calls to
realloc() as much as possible.
2019-03-20 10:48:33 +01:00
Lennart Poettering 23964f7faf alloc-util: add extra overflow checks to GREEDY_REALLOC() 2019-03-20 10:48:33 +01:00
Lennart Poettering e5e21a0507 alloc-util: extra paranoid overflow check 2019-03-20 10:48:33 +01:00
Lennart Poettering e1ed99c8c8 ask-password: erase character read with _cleanup_
This is much nicer, since it means we erase the character regardless how
we exit the scope.
2019-03-20 10:48:33 +01:00
Lennart Poettering d5d1ae153f cryptsetup: small refactoring 2019-03-20 10:48:33 +01:00
Zbigniew Jędrzejewski-Szmek dc502f8916
Merge pull request #12034 from poettering/stdio-bridge-fixes
small stdio-bridge and errno-util.h improvements and fixes
2019-03-20 10:46:32 +01:00
Zbigniew Jędrzejewski-Szmek 30222f4b2c util-lib: use a fixed buffer size for terminal path
The loop around ttyname_r() makes it look like we use unbounded stack
allocations. We know that that paths have a maximum size, so let's simplify
the whole thing.

Replaces #12043.
2019-03-20 09:36:45 +01:00
Lennart Poettering 08f6769675 execute: generalize uid/gid handling in two cases for any kind of uid/gid 2019-03-19 16:57:33 +01:00
Lennart Poettering 206e9864de core: change ownership/mode of the execution directories also for static users
It's probably unexpected if we do a recursive chown() when dynamic users
are used but not on static users.

hence, let's tweak the logic slightly, and recursively chown in both
cases, except when operating on the configuration directory.

Fixes: #11842
2019-03-19 16:57:33 +01:00
Lennart Poettering d484580ca6 execute: remove one redundant comparison check 2019-03-19 16:52:28 +01:00
Lennart Poettering 40cd2ecc26 execute: also do the private/ symlink dance when runtime dir preservation is requested
In that case it's not safe to leave a regular dir around, hence, move it
to private/ too.
2019-03-19 16:52:28 +01:00
Lennart Poettering edbfeb1204 execute: use path_join() where appropriate 2019-03-19 16:52:28 +01:00
Lennart Poettering 30ff18d8a2 fs-util: change chmod_and_chown() to not complain if stat data already matches
Let's reduce the chance of failure: if we can't apply the chmod/chown
requested, check if it's applied anyway, and if so, supress the error.

This is even race-free since we operate on an O_PATH fd anyway.
2019-03-19 16:52:28 +01:00
Lennart Poettering a70984c049 tests: add tests for ConditionMemory= + ConditionCPUs 2019-03-19 15:55:08 +01:00
Lennart Poettering 754f719af2 condition: add ConditionMemory= and ConditionCPUs=
We have all the building blocks in place already, let's add this.

Fixes: #8990
2019-03-19 15:55:08 +01:00
Lennart Poettering 2877d42870 condition: for completenes sake at != comparator for ConditionKernelVersion= 2019-03-19 15:55:08 +01:00
Lennart Poettering 78d7652549 condition: use structured initialization 2019-03-19 15:55:07 +01:00
Lennart Poettering 20ee849d57 process-util: add new helper cpus_in_affinity_mask()
Let's add a new helper for determining how many CPUs are configured for
us
2019-03-19 15:55:07 +01:00
Lennart Poettering ba22ff13a0 condition: split out kernel version comparison steps
Let's split out the operator parsing and the final verdict
determination. That way we can reuse this logic for other purposes later
on.
2019-03-19 15:55:07 +01:00
Lennart Poettering f60a028a4e tree-wide: use ERRNO_IS_DISCONNECT() at more places 2019-03-19 15:41:30 +01:00
Lennart Poettering dd90e39cb6 util: add one more disconnect errno code 2019-03-19 15:39:07 +01:00
Lennart Poettering d1ded478ee stdio-bridge: slightly optimize formatting of structure 2019-03-19 15:29:44 +01:00
Lennart Poettering 451e16e0cb stdio-bridge: use SYNTHETIC_ERRNO() where appropriate 2019-03-19 15:29:44 +01:00
Lennart Poettering b6056ea37c stdio-bridge: tweak getopt() case statement a bit 2019-03-19 15:29:44 +01:00
Lennart Poettering 578e95de48 stdio-bridge: fix getopt() parameter list to match reality 2019-03-19 15:29:44 +01:00
Lennart Poettering 4e17e5c2bf stdio-bridge: use ERRNO_IS_DISCONNECT() to detect disconnects
Let's use the macro we already have to make this safer. Moreover log
about all other errors.
2019-03-19 15:29:44 +01:00
Lennart Poettering c3fecddf0d util: move ERRNO_IS_xyz macros to errno-util.h
It's where they fit much better.
2019-03-19 15:29:44 +01:00