Commit Graph

4417 Commits

Author SHA1 Message Date
Lennart Poettering bedea99dce core: expose bus client names currently reffing a unit as property
This is useful for debugging client-side ref counting of units: for each
ref taken on a unit the client's sender name is listed. If a client has
multiple refs on the same unit it is listed multiple times.
2018-11-09 17:15:34 +01:00
Lennart Poettering e5c36295d8 unit: enqueue cgroup empty check event if the last ref on a unit is dropped 2018-11-09 17:08:59 +01:00
Lennart Poettering c20076a8c1 pid1: add a new AbandonScope() method call on the Manager object
This is the same as Abandon() on the Scope object, but saves clients
from first translating a unit name into a unit object path. This logic
matches how all the other unit methods have counterparts on the Manager
object too (e.g. StopUnit() on the Manager object matching Stop() on the
Unit object), this one was simply forgotten so far.
2018-11-09 17:08:59 +01:00
Lennart Poettering c2baf11c36 cgroup: actually reset the cgroup invalidation mask after we made our changes
Previously we never unmasked the mask after it was set once. Let's fix
that.
2018-11-08 15:20:52 +01:00
Lennart Poettering 6529ccfa20 unit: replace three non-type-safe macros by type-safe inline functions
Behaviour is prett ymuch the same, but there's some additional type
checking done on the input parameters.

(In the case of UNIT_WRITE_FLAGS_NOOP() the C compiler won't actually do
the type checking necessarily, but static chckers at least could)
2018-11-08 13:55:25 +01:00
Yu Watanabe 64af816228 core/device: use LIST_FOREACH_AFTER() or friend 2018-11-08 10:58:25 +01:00
Lennart Poettering bbf1120623 unit: make UNIT() cast function deal with NULL pointers
Fixes: #10681
2018-11-08 10:47:08 +01:00
Yu Watanabe b9c04eafb8 core: introduce exec_params_clear()
Follow-up for 1ad6e8b302.

Fixes #10677.
2018-11-08 09:36:37 +01:00
Zbigniew Jędrzejewski-Szmek e44c5a3ba6
Merge pull request #10594 from poettering/env-reload-fix
change handling of environment block of PID1's manager object
2018-11-07 12:49:13 +01:00
Lennart Poettering ed63705975
Merge pull request #10650 from yuwata/udevadm-trigger-use-write-string-file
udevadm: use write_string_file() helper function
2018-11-06 16:46:25 +03:00
Giuseppe Scrivano 875622c39e core, sysctl: skip ENOENT for /proc/sys/net/unix/max_dgram_qlen
sysctl is disabled for /proc mounted from an user namespace thus entries like
/proc/sys/net/unix/max_dgram_qlen do not exist.  In this case, skip the error
and do not try to change the default for the AF_UNIX datagram queue length.
2018-11-06 16:41:34 +03:00
Yu Watanabe 57512c893e tree-wide: set WRITE_STRING_FILE_DISABLE_BUFFER flag when we write files under /proc or /sys 2018-11-06 21:24:03 +09:00
Lennart Poettering 1ad6e8b302 core: split environment block mantained by PID 1's Manager object in two
This splits the "environment" field of Manager into two:
transient_environment and client_environment. The former is generated
from configuration file, kernel cmdline, environment generators. The
latter is the one the user can control with "systemctl set-environment"
and similar.

Both sets are merged transparently whenever needed. Separating the two
sets has the benefit that we can safely flush out the former while
keeping the latter during daemon reload cycles, so that env var settings
from env generators or configuration files do not accumulate, but
dynamic API changes are kept around.

Note that this change is not entirely transparent to users: if the user
first uses "set-environment" to override a transient variable, and then
uses "unset-environment" to unset it again things will revert to the
original transient variable now, while previously the variable was fully
removed. This change in behaviour should not matter too much though I
figure.

Fixes: #9972
2018-10-31 18:00:53 +01:00
Lennart Poettering bea1a01310 strv: wrap strv_new() in a macro so that NULL sentinel is implicit 2018-10-31 18:00:52 +01:00
Joerg Behrmann 56ef8db9f5 core: apply WorkingDirectory after enforce_user
If WorkingDirectory is on NFS, root might only have the privileges of
nobody and the chdir to the WorkingDirectory might fail, even if the
user running the service would have the proper privileges to chdir to
that directory.

Fixes #10568
2018-10-31 12:07:24 +01:00
Insun fee04d7f3a core: don't drop timer expired but not yet processed when system date is changed
There is difference between time set by the user and real elapsed time because of accuracy feature.
If you change the system date(or time) between these times, the timer drops.

You can easily reproduce it with the following command.
-----------------------------------------------------------
$ systemd-run --on-active=3s ls; sleep 3; date -s "`date`"
-----------------------------------------------------------

In the following command, the problem is rarely reproduced. But it exists.
---------------------------------------------------------------------------------------------
$ systemd-run --on-active=3s --timer-property=AccuracySec=1us ls ; sleep 1; date -s "`date`"
---------------------------------------------------------------------------------------------

Note : Global AccuracySec value.
----------------------------------------------------------------------
$ cat /etc/systemd/system.conf
DefaultTimerAccuracySec=1min
----------------------------------------------------------------------
2018-10-30 15:38:45 +01:00
Franck Bui 651b3b6c92 core: skip unit deserialization and move to the next one when unit_deserialize() fails
If unit_deserialize() fails (because one read line is overly long), it returns
an error and we would have assumed that the next read would point to the next
unit to deserialize.

But instead unit_deserialize() can leave the file offset in the middle of a
line.

Therefore we need to ignore and skip the current unit in this case too.

While at it, move unit deserialization in a dedicated functions. That should
make the code easier to read.
2018-10-30 14:52:13 +01:00
Lennart Poettering 6897dfe85a core: add free_and_replace() at one more place 2018-10-26 19:49:15 +02:00
Lennart Poettering 7593c3ecbf tree-wide: add a few missing _sentinel_ decorators 2018-10-26 19:49:15 +02:00
Lennart Poettering cd6b7d50c3 chown-recursive: TAKE_FD() is your friend 2018-10-26 15:13:26 +02:00
Lennart Poettering f89bc84f32 chown-recursive: also drop ACLs when recursively chown()ing
Let's better be safe than sorry and also drop ACLs.
2018-10-26 15:13:26 +02:00
Lennart Poettering 5de6cce58b chown-recursive: let's rework the recursive logic to use O_PATH
That way we can pin a specific inode and analyze it and manipulate it
without it being swapped out beneath our hands.

Fixes a vulnerability originally found by Jann Horn from Google.

CVE-2018-15687
LP: #1796692
https://bugzilla.redhat.com/show_bug.cgi?id=1639076
2018-10-26 15:13:26 +02:00
Lennart Poettering aa8c4bbf6a service: when starting a service make a copy of the watchdog timeout and use that
When we start a service process we pass the selected watchdog timeout to
it with the $WATCHDOG_USEC environment variable. If the unit file is
reconfigured later, we need to make sure to continue to honour the
original timeout, i.e. watch $WATCHDOG_USEC was set to, otherwise we'll
expect the ping at a different time as the service process is sending it
to us.

Hence, whenever we start a unit, save the watchdog timeout, and stick to
that for everything we do.

Fixes: #9467
2018-10-26 13:00:04 +02:00
Lennart Poettering 34b3f625f2 service: continue to use the overriden timeout when forking off again
Let's make sure we always use the right watchdog timeout: when a service
has overwritten it, then stick to it, also for follow-up processes of
the same service.
2018-10-26 13:00:04 +02:00
Lennart Poettering 95d0d8ed0a service: rename service_reset_watchdog_timeout() → service_override_watchdog_timeout()
This is what the function really does, hence name it that way.
2018-10-26 13:00:04 +02:00
Lennart Poettering ec35a7f6b0 service: rework service_extend_timeout()
Let's unify common code: let's extend the watchdog timeout and the
regular timeout with the same helper function.
2018-10-26 13:00:04 +02:00
Lennart Poettering 9fb1cdb480 service: explicit stop the watchdog when we shall not use it
This is useful so that WATCHDOG_USEC=0 sent from a process does the
right thing if turning off the watchdog logic.
2018-10-26 12:53:17 +02:00
Lennart Poettering d68c645bd3 core: rework serialization
Let's be more careful with what we serialize: let's ensure we never
serialize strings that are longer than LONG_LINE_MAX, so that we know we
can read them back with read_line(…, LONG_LINE_MAX, …) safely.

In order to implement this all serialization functions are move to
serialize.[ch], and internally will do line size checks. We'd rather
skip a serialization line (with a loud warning) than write an overly
long line out. Of course, this is just a second level protection, after
all the data we serialize shouldn't be this long in the first place.

While we are at it also clean up logging: while serializing make sure to
always log about errors immediately. Also, (void)ify all calls we don't
expect errors in (or catch errors as part of the general
fflush_and_check() at the end.
2018-10-26 10:52:41 +02:00
Lennart Poettering cdd620e346 core: make manager_serialize() a bit easier to read by adding predicate function
The predicate function manager_timestamp_shall_serialize() simply says
whether to serialize or not serialize a timestamp, and should make
things a bit easier to read.
2018-10-26 10:40:01 +02:00
Lennart Poettering c475e57d67 core: strjoina() in a loop is never OK
Let's use plain strjoin() instead.
2018-10-26 10:40:01 +02:00
Lennart Poettering a2a444440f automount: fix deserialization of dev_t
let's prefer "unsigned long" rather than "unsigned", in case there are
archs that have 32bit int, but 64bit dev_t.

(Also one cast was wrong anyway.)
2018-10-26 10:40:01 +02:00
Lennart Poettering 3eac1bcae9 core: enforce a limit on STATUS= texts recvd from services
Let's better be safe than sorry, and put a limit on what we receive.
2018-10-26 10:40:01 +02:00
Lennart Poettering 8948b3415d core: when deserializing state always use read_line(…, LONG_LINE_MAX, …)
This should be much better than fgets(), as we can read substantially
longer lines and overly long lines result in proper errors.

Fixes a vulnerability discovered by Jann Horn at Google.

CVE-2018-15686
LP: #1796402
https://bugzilla.redhat.com/show_bug.cgi?id=1639071
2018-10-26 10:40:01 +02:00
Lennart Poettering 1d445eda4e core: reword polkit request a bit (#10524)
"killing" is very UNIX terminology, and not really what this is about.
Let's be more correct and say "send a UNIX signal" for the operation.

Otherwise things are really weird if users call "journalctl --rotate"
from the command line, which internally asks systemd to send SIGUSR2 to
to journald: when german locale is selected this asks the user — roughly
transliterated — whether they want to "eliminate" journald, which is
definitely not the intended meaning.
2018-10-26 06:01:41 +09:00
Martin Wilck e1e74614aa core: don't create Requires for workdir if "missing ok"
Don't add an implicit RequiresMountsFor depenency for the
WorkingDirectory of a unit if the "-" character was used to
indicate that "a missing working directory is not considered fatal"
(see systemd.exec(5)). Otherwise systemd might fail the unit
because of missing dependencies.
2018-10-25 11:35:59 +02:00
Lennart Poettering 2194547e3b execute: if we fail to do namespacing, explain why we refuse to continue in a debug message 2018-10-24 17:08:12 +02:00
Lennart Poettering 77d28bd10f
Merge pull request #10483 from yuwata/udev-cleanup-10
tree-wide: use log_device_*()
2018-10-24 10:51:53 +02:00
Yu Watanabe ec9d636b37 core: use ascii_toupper() instead of everytime judging whether it is the first message 2018-10-24 04:58:08 +09:00
Yu Watanabe 71f79b56cf core/device: use log_device_*() 2018-10-23 22:44:07 +09:00
Lennart Poettering 41159592f8
Merge pull request #10470 from yuwata/log-message-updates
Log message updates
2018-10-19 22:58:53 +02:00
Yu Watanabe 14cb109d45 tree-wide: replace 'unsigned int' with 'unsigned' 2018-10-19 22:19:12 +02:00
Yu Watanabe 5e1ee764e1 core: include error cause in log message 2018-10-20 01:40:42 +09:00
Lennart Poettering 490c5a37cb tree-wide: some automatic coccinelle fixes (#10463)
Nothing fancy, just coccinelle doing its work.
2018-10-20 00:07:46 +09:00
Evgeny Vereshchagin 2ac1ff68f2 core: stop ignoring errors in connect_logger_as
When journald reaches the maximum number of active streams, it,
basically, starts to decline new connections. On the client
side it can be detected by getting EPIPE and, if the writing
process isn't lucky enough, getting SIGPIPE soon afterwards.
systemd has always ignored EPIPE, which makes it very hard
to keep track of services losing logs. This patch should make
it easier to detect such services by just staring at the logs
carefully.

In case anyone is interested, the following one-liner run as any user
can be used to paralyze all the stream logging on a machine:

for i in {1..4096}; do systemd-cat -t HEY-$i & done
2018-10-19 10:32:21 +02:00
Lennart Poettering 6ab1853953
Merge pull request #10460 from yuwata/setsockopt_int-more
tree-wide: use setsockopt_int() more
2018-10-19 10:12:00 +02:00
Lennart Poettering a87b1faad3 core: beautify per-unit consumed resources log message a bit. (#10390)
Shorten message to say "no IP traffic" if there is no IP traffic, rather
than "received 0B IP traffic, sent 0B IP traffic".

Fixes: #9816
2018-10-19 09:04:12 +09:00
Yu Watanabe 17acb7ef9a
Merge pull request #10450 from poettering/foreach-line-excorcism
FOREACH_LINE excorcism
2018-10-19 08:44:51 +09:00
Yu Watanabe 9e5b649655 tree-wide: use setsockopt_int() more 2018-10-19 05:52:42 +09:00
Lennart Poettering 986c8af1b8
Merge pull request #10456 from poettering/setsockopt-int
add a setsockopt_int() helper and make use of it everywhere
2018-10-18 21:53:01 +02:00
Lennart Poettering 6d4150cb45 job: add a comment that JOB_DONE also means skipped due to condition (#10453) 2018-10-19 03:55:30 +09:00