Commit graph

4704 commits

Author SHA1 Message Date
Jonathon Kowalski 791cd15993 Fail RequisiteOf units with oneshots
Fixes: #11422

Oneshots going to inactive directly without ever entering UNIT_ACTIVE is
considered success. This however means that if something both Requires=
and Requisites= a unit of such nature, the verify-active job getting
merged into the start job makes it lose this property of failing the
depending jobs, as there, the start job has the result JOB_DONE on
success, so we never walk over RequisiteOf units.

This change makes sure that such units always go down. It is also only
meaningful with After=, but so is Requisite= itself. Also, we also catch
cases like a oneshot having RemainAfterExit= true making us start up
properly in such a setting, but then removing it, reloading the unit,
and restarting it. In such a case, we go down due to restart propagation
before them, and our start job waits on theirs, properly failing with
the JOB_DEPENDENCY result.

This covers cases where ConditionXYZ= creates a similar situation as
well.
2019-02-15 13:42:54 +01:00
Lennart Poettering eca3d5d567
Merge pull request #9594 from filbranden/cpu_quota_period1
core: add CPUQuotaPeriodSec=
2019-02-15 12:11:42 +01:00
Lennart Poettering bd0a4a3da8
Merge pull request #11617 from topimiettinen/backlight-handle-zero-file-load
backlight: handle loading truncated file
2019-02-15 11:32:58 +01:00
Lennart Poettering dcf3c3c3d9 core: export $PIDFILE env var for services, derived from PIDFile= 2019-02-15 11:32:19 +01:00
Lennart Poettering 7ca9289ca2
Merge pull request #11373 from tomty89/auto
mount/generators: do not make unit wanted by its device unit
2019-02-15 11:31:55 +01:00
Lennart Poettering c49adafa82
Merge pull request #11506 from bl33pbl0p/reload-fix
Return -EAGAIN instead of -EALREADY from unit_reload
2019-02-15 11:31:00 +01:00
Filipe Brandenburger 527ede0c63 core: downgrade CPUQuotaPeriodSec= clamping logs to debug
After the first warning log, further messages are downgraded to LOG_DEBUG.
2019-02-14 11:04:42 -08:00
Filipe Brandenburger 10f2864111 core: add CPUQuotaPeriodSec=
This new setting allows configuration of CFS period on the CPU cgroup, instead
of using a hardcoded default of 100ms.

Tested:
- Legacy cgroup + Unified cgroup
- systemctl set-property
- systemctl show
- Confirmed that the cgroup settings (such as cpu.cfs_period_ns) were set
  appropriately, including updating the CPU quota (cpu.cfs_quota_ns) when
  CPUQuotaPeriodSec= is updated.
- Checked that clamping works properly when either period or (quota * period)
  are below the resolution of 1ms, or if period is above the max of 1s.
2019-02-14 11:04:42 -08:00
Tom Yan d0fe45cb15 mount: remove unused mount_is_auto and mount_is_automount 2019-02-15 00:16:54 +08:00
Tom Yan 142b8142d7 mount/generators: do not make unit wanted by its device unit
As device units will be reloaded by systemd whenever the corresponding device generates a "changed" event, if the mount unit / cryptsetup service is wanted by its device unit, the former can be restarted by systemd unexpectedly after the user stopped them explicitly. It is not sensible at all and can be considered dangerous. Neither is the behaviour conventional (as `auto` in fstab should only affect behaviour on boot and `mount -a`) or ever documented at all (not even in systemd, see systemd.mount(5) and crypttab(5)).
2019-02-15 00:16:54 +08:00
Alberts Muktupāvels 52c6c9eaec core: when we uninstall a job, add unit to dbus queue
Commit e6d05912cb added unit to dbus
queue on job install. Do same on job uninstall to make sure we get
PropertiesChanged signal.
2019-02-12 16:55:45 +01:00
Stephan E ac8956efa2 Update mount.c
typo in output
2019-02-13 00:41:57 +09:00
Jan Engelhardt a6fe3b4894 rpm: use sh compatible redirects
&> is bash-specific. Switch to something that will work with dash
and pbosh.
2019-02-08 17:58:31 +01:00
NeilBrown 1cae151d8e automount: don't pass non-blocking pipe to kernel.
Creating a pipe with O_NONBLOCK causes both the read and the write end to
be marked as non-blocking.
The "write" end is passed to the kernel autofs module, and it does not
expect a non-blocking pipe.  If it gets -EAGAIN when trying to write
(which is unlikely, but not completely impossible), it will close the
write end of the pipe, which leads to unexpected errors.

So change the code to only set O_NONBLOCK on the "read" end of the
pipe.  This is the only end that systemd interacts with, so the only end
it should be configuring.
2019-02-08 10:33:26 +01:00
Yu Watanabe 64242fd307 core/dbus-service: empty assignment to PIDFile= resets the value
Follow-up for a9353a5c5b.
2019-02-06 17:58:52 +01:00
Yu Watanabe c79d66fc7e core/dbus-service: write PIDFile= setting to transient unit file
Follow-up for a9353a5c5b.
2019-02-06 17:58:40 +01:00
Yu Watanabe b8055c05e2 core/load-fragment: empty assignment to PIDFile= resets the value
Follow-up for a9353a5c5b.
2019-02-06 17:58:24 +01:00
Topi Miettinen a21760454d Detect file truncation earlier in a few places
Users of read_one_line_file() for APIVFS entries are ignored as they are
assumed to never get truncated.
2019-02-02 16:25:32 +02:00
Lennart Poettering 92dc48ac45
Merge pull request #11540 from taro-yamada/mytest
ReFix #11128
2019-01-29 11:27:42 +01:00
Taro Yamada 6cff72eb0a Add a warning about the difference in permissions between existing directories and unit settings.
To follows the intent of 30c81ce, this change does not execute chmod() and just add warnings.
2019-01-29 09:52:21 +09:00
Taro Yamada ff9e7900c0 Revert "Fixes #11128"
This reverts commit 0bf05f0122 because it breaks 30c81ce.
Please see #11540.
2019-01-27 13:43:30 +09:00
Lennart Poettering a90d944359
Merge pull request #11562 from yuwata/fix-11558
core/mount: do not add Before=local-fs.target or remote-fs.target if nofail mount option is set
2019-01-26 14:46:48 +01:00
Lennart Poettering f2500feadf
Merge pull request #11466 from keszybz/fix-loop-remounts
pid1: fix cleanup of stale implicit deps based on /proc/self/mountinfo
2019-01-26 14:42:02 +01:00
Zbigniew Jędrzejewski-Szmek c52c2dc64f pid1: fix cleanup of stale implicit deps based on /proc/self/mountinfo
The problem was introduced in a37422045fbb68ad68f734e5dc00e0a5b1759773:
we have a unit which has a fragment, and when we'd update it based on
/proc/self/mountinfo, we'd say that e.g. What=/dev/loop8 has origin-fragment.
This commit changes two things:
- origin-fragment is changed to origin-mountinfo-implicit
- when we stop a unit, mountinfo information is flushed and all deps based
  on it are dropped.

The second step is important, because when we restart the unit, we want to
notice that we have "fresh" mountinfo information. We could keep the old info
around and solve this in a different way, but keeping stale information seems
inelegant.

Fixes #11342.
2019-01-26 14:40:50 +01:00
Lennart Poettering 67216ef8f2
Merge pull request #11530 from keszybz/journal-cache-trimming
Journal cache trimming
2019-01-26 13:55:55 +01:00
Yu Watanabe 8c8203db90 core/mount: do not add Before=local-fs.target or remote-fs.target if nofail mount option is set
Follow-up for d54bab90e6.

Fixes #11558.
2019-01-26 12:00:18 +01:00
Chris Lamb 4605de118d Correct more spelling errors. 2019-01-23 23:34:52 +01:00
Zbigniew Jędrzejewski-Szmek c482724aa5 procfs-util: expose functionality to query total memory
procfs_memory_get_current is renamed to procfs_memory_get_used, because
"current" can mean anything, including total memory, used memory, and free
memory, as long as the value is up to date.

No functional change.
2019-01-22 17:43:13 +01:00
Lennart Poettering 04ba6ed167
Merge pull request #11501 from yuwata/fix-9426
sd-device: do not save e.g., DEVPATH or INTERFACE properties to udev database
2019-01-22 11:57:06 +01:00
Taro Yamada 0bf05f0122 Fixes #11128 2019-01-22 11:14:51 +01:00
Zbigniew Jędrzejewski-Szmek 3a57413c26
Merge pull request #11448 from poettering/rlimit-pid1-fixo
RLIMIT_MEMLOCK fixes
2019-01-22 10:07:52 +01:00
Yu Watanabe 302ddcdc0a core/device: fix log message 2019-01-22 14:51:02 +09:00
Jonathon Kowalski 78218e6243 Enable some more debug logging for transaction building 2019-01-21 11:39:06 +01:00
Jonathon Kowalski 6255af75d7 Return -EAGAIN instead of -EALREADY from unit_reload
Fixes: #11499

Let's return -EAGAIN so that on state change, unit_process_job tries to
add our job to run_queue again so that all the reloads that coalesced
into the installed reload (which itself merged into a running one)
inititally atleast runs *once*. This should ensure service picks up all
config changes reliably.

See the issue being fixed for a detailed explanation.
2019-01-20 22:12:24 +00:00
Lennart Poettering ce932d2d33 execute: make sure to call into PAM after initializing resource limits
We want that pam_limits takes precedence over our settings, after all.

Fixes: #11386
2019-01-18 17:31:36 +01:00
Lennart Poettering 99a2fd3bca main: when generating the resource limit to pass to children, take FD_SETSIZE into consideration
When we synthesize a "struct rlimit" structure to pass on for
RLIMIT_NOFILE to our children, let's explicitly make sure that the soft
limit is not above FD_SETSIZE, for compat reason with select().

Note this only applies when we derive the "struct rlimit" from what we
inherited. If the user configures something explicitly it always takes
precedence.
2019-01-18 17:31:36 +01:00
Lennart Poettering cda7faa9a5 main: don't bump resource limits if they are higher than we need them anyway
This matters in particular in the case of --user, since there we lack
the privs to bump the limits up again later on when invoking children.
2019-01-18 17:31:36 +01:00
Lennart Poettering ddfa8b0b3b main: add commenting, clean up handling of saved resource limits
This doesn't really change behaviour, but adds comments and uses more
symbolic names for everything, to make this more readable.
2019-01-18 17:31:36 +01:00
Lennart Poettering c0d7695908 main: when bumping RLIMIT_MEMLOCK, save the previous value to pass to children
Let's make sure that the bumping of RLIMIT_MEMLOCK does not leak into
our children.
2019-01-18 17:31:36 +01:00
Zbigniew Jędrzejewski-Szmek b7bbf89025 core/mount: move static function earlier in file
No functional change.
2019-01-18 14:04:26 +01:00
Jonathon Kowalski 03ff2dc71e Change job mode of manager triggered restarts to JOB_REPLACE
Fixes: #11305
Fixes: #3260
Related: #11456

So, here's what happens in the described scenario in #11305. A unit goes
down, and that triggeres stop jobs for the other two units as they were
bound to it. Now, the timer for manager triggered restarts kicks in and
schedules a restart job with the JOB_FAIL job mode. This means there is
a stop job installed on those units, and now due to them being bound to
us they also get a restart job enqueued. This however is a conflicts, as
neither stop can merge into restart, nor restart into stop. However,
restart should be able to replace stop in any case. If the stop
procedure is ongoing, it can cancel the stop job, install itself, and
then after reaching dead finish and convert itself to a start job.
However, if we increase the timer, then it can always take those units
from inactive -> auto-restart.

We change the job mode to JOB_REPLACE so the restart job cancels the
stop job and installs itself.

Also, the original bug could be worked around by bumping RestartSec= to
avoid the conflicting.

This doesn't seem to be something that is going to break uses. That is
because for those who already had it working, there must have never been
conflicting jobs, as that would result in a desctructive transaction by
virtue of the job mode used.

After this change, the test case is able to work nicely without issues.
2019-01-18 13:50:52 +01:00
Lennart Poettering 5356ad6c36
Merge pull request #11465 from poettering/daemon-bus-flush
flush+close bus connections explicitly when our daemons go down
2019-01-18 13:48:52 +01:00
Lennart Poettering 92e29d82e6 tree-wide: fix some trailing whitespace
@bl33pbl0p, please fix your editor

(Apparently you never configured the source tree? If you did, then the
git pre-commit hook would have been enabled which doesn't allow
commiting non-whitespace clean stuff...)
2019-01-17 20:06:28 +01:00
Lennart Poettering 81a40363f5 core: shorten code by using new helper 2019-01-17 16:12:38 +01:00
Lennart Poettering b1a4981aed tree-wide: whenever we allocate a new bus object, close it before dropping final ref
This doesn't really change much, but feels more correct to do, as it
ensures that all messages currently queued in the bus connections are
definitely unreffed and thus destryoing of the connection object will
follow immediately.

Strictly speaking this change is entirely unnecessary, since nothing
else could have acquired a ref to the connection and queued a message
in, however, now that we have the new sd_bus_close_unref() helper it
makes a lot of sense to use it here, to ensure that whatever happens
nothing that might have been queued fucks with us.
2019-01-17 16:12:38 +01:00
Lennart Poettering bd62b74486 sd-bus: add sd_bus_close_unref() helper
It's similar to sd_bus_flush_close_unref() but doesn't do the flushing.
This is useful since this will still discnnect the connection properly
but not synchronously wait for the peer to take our messages.

Primary usecase is within _cleanup_() expressions where synchronously
waiting on the peer is not OK.
2019-01-17 16:12:38 +01:00
Aaron Plattner 119f0f2876 core: Fix -EOPNOTSUPP emergency action error string
The error string for operations that are not supported (e.g. "shutdown" for
user-defined units) should take two arguments, where the first one is the type
of action being defined (i.e. "FailureAction" vs. "SuccessAction") and the
second is the string that was invalid.

Currently, the code prints this:

 $ systemd-run --user --wait -p SuccessAction=poweroff true
 Failed to start transient service unit: EmergencyAction setting invalid for manager type: SuccessAction

Change the format string to instead print:

 $ systemd-run --user --wait -p SuccessAction=poweroff true
 Failed to start transient service unit: SuccessAction setting invalid for manager type: poweroff
2019-01-17 09:17:15 +01:00
Aaron Plattner db2df5500e core: Fix return argument check for parse_emergency_action
This function returns 0 on success and a negative value on failure. On success,
it writes the parsed action to the address passed in its third argument.

`bus_set_transient_emergency_action` does this:

 r = parse_emergency_action(s, system, &v);
 if (v < 0)
     // handle failure

However, `v` is not updated if the function fails, and this should be checking
`r` instead of `v`.

The result of this is that if an invalid failure (or success) action is
specified, systemd ends up creating the unit anyway and then misbehaves if it
tries to run the failure action because the action value comes from
uninitialized stack data. In my case, this resulted in a failed assertion:

 Program received signal SIGABRT, Aborted.
 0x00007fe52cca0d7f in raise () from /snap/usr/lib/libc.so.6
 (gdb) bt
 #0  0x00007fe52cca0d7f in raise () from /snap/usr/lib/libc.so.6
 #1  0x00007fe52cc8b672 in abort () from /snap/usr/lib/libc.so.6
 #2  0x00007fe52d66f169 in log_assert_failed_realm (realm=LOG_REALM_SYSTEMD, text=0x56177ab8e000 "action < _EMERGENCY_ACTION_MAX", file=0x56177ab8dfb8 "../src/core/emergency-action.c", line=33, func=0x56177ab8e2b0 <__PRETTY_FUNCTION__.14207> "emergency_action") at ../src/basic/log.c:795
 #3  0x000056177aa98cf4 in emergency_action (m=0x56177c992cb0, action=2059118610, options=(unknown: 0), reboot_arg=0x0, exit_status=1, reason=0x7ffdd2df4290 "unit run-u0.service failed") at ../src/core/emergency-action.c:33
 #4  0x000056177ab2b739 in unit_notify (u=0x56177c9eb340, os=UNIT_ACTIVE, ns=UNIT_FAILED, flags=(unknown: 0)) at ../src/core/unit.c:2504
 #5  0x000056177aaf62ed in service_set_state (s=0x56177c9eb340, state=SERVICE_FAILED) at ../src/core/service.c:1104
 #6  0x000056177aaf8a29 in service_enter_dead (s=0x56177c9eb340, f=SERVICE_SUCCESS, allow_restart=true) at ../src/core/service.c:1712
 #7  0x000056177aaf9233 in service_enter_signal (s=0x56177c9eb340, state=SERVICE_FINAL_SIGKILL, f=SERVICE_SUCCESS) at ../src/core/service.c:1854
 #8  0x000056177aaf921b in service_enter_signal (s=0x56177c9eb340, state=SERVICE_FINAL_SIGTERM, f=SERVICE_SUCCESS) at ../src/core/service.c:1852
 #9  0x000056177aaf8eb3 in service_enter_stop_post (s=0x56177c9eb340, f=SERVICE_SUCCESS) at ../src/core/service.c:1788
 #10 0x000056177aaf91eb in service_enter_signal (s=0x56177c9eb340, state=SERVICE_STOP_SIGKILL, f=SERVICE_SUCCESS) at ../src/core/service.c:1850
 #11 0x000056177aaf91bc in service_enter_signal (s=0x56177c9eb340, state=SERVICE_STOP_SIGTERM, f=SERVICE_FAILURE_EXIT_CODE) at ../src/core/service.c:1848
 #12 0x000056177aaf9759 in service_enter_running (s=0x56177c9eb340, f=SERVICE_FAILURE_EXIT_CODE) at ../src/core/service.c:1941
 #13 0x000056177ab005b7 in service_sigchld_event (u=0x56177c9eb340, pid=112, code=1, status=1) at ../src/core/service.c:3296
 #14 0x000056177aad84b5 in manager_invoke_sigchld_event (m=0x56177c992cb0, u=0x56177c9eb340, si=0x7ffdd2df48f0) at ../src/core/manager.c:2444
 #15 0x000056177aad88df in manager_dispatch_sigchld (source=0x56177c994710, userdata=0x56177c992cb0) at ../src/core/manager.c:2508
 #16 0x00007fe52d72f807 in source_dispatch (s=0x56177c994710) at ../src/libsystemd/sd-event/sd-event.c:2846
 #17 0x00007fe52d730f7d in sd_event_dispatch (e=0x56177c993530) at ../src/libsystemd/sd-event/sd-event.c:3229
 #18 0x00007fe52d73142e in sd_event_run (e=0x56177c993530, timeout=18446744073709551615) at ../src/libsystemd/sd-event/sd-event.c:3286
 #19 0x000056177aad9f71 in manager_loop (m=0x56177c992cb0) at ../src/core/manager.c:2906
 #20 0x000056177aa7c876 in invoke_main_loop (m=0x56177c992cb0, ret_reexecute=0x7ffdd2df4bff, ret_retval=0x7ffdd2df4c04, ret_shutdown_verb=0x7ffdd2df4c58, ret_fds=0x7ffdd2df4c70, ret_switch_root_dir=0x7ffdd2df4c48, ret_switch_root_init=0x7ffdd2df4c50, ret_error_message=0x7ffdd2df4c60) at ../src/core/main.c:1792
 #21 0x000056177aa7f251 in main (argc=2, argv=0x7ffdd2df4e78) at ../src/core/main.c:2573

Fix this by checking the correct variable.
2019-01-17 09:17:15 +01:00
bl33pbl0p 28d78d0726 Log the job being merged
Makes it easier to understand what was merged (and easier to realize why).

Example is a start job running, and another unit triggering a verify-active job. It is not clear what job was it that from baz.service that merged into the installed job for bar.service in the debug logs. This makes it useful when debugging issues.

Jan 15 11:45:58 jupiter systemd[1218]: baz.service: Trying to enqueue job baz.service/start/replace
Jan 15 11:45:58 jupiter systemd[1218]: baz.service: Installed new job baz.service/start as 498
Jan 15 11:45:58 jupiter systemd[1218]: bar.service: Merged into installed job bar.service/start as 497
Jan 15 11:45:58 jupiter systemd[1218]: baz.service: Enqueued job baz.service/start as 498

It becomes:
Jan 15 11:45:58 jupiter systemd[1218]: bar.service: Merged bar.service/verify-active into installed job bar.service/start as 497
2019-01-16 12:34:54 +01:00
Topi Miettinen a1e92eee3e Remove 'inline' attributes from static functions in .c files (#11426)
Let the compiler perform inlining (see #11397).
2019-01-15 08:12:28 +01:00