summaryrefslogtreecommitdiff
path: root/src/core/dbus-unit.c
Commit message (Collapse)AuthorAgeFilesLines
* cgroup: introduce support for cgroup v2 CPUSET controllerPavel Hrdina2019-09-241-0/+48
| | | | | | | | | | | | | | Introduce support for configuring cpus and mems for processes using cgroup v2 CPUSET controller. This allows users to limit which cpus and memory NUMA nodes can be used by processes to better utilize system resources. The cgroup v2 interfaces to control it are cpuset.cpus and cpuset.mems where the requested configuration is written. However, it doesn't mean that the requested configuration will be actually used as parent cgroup may limit the cpus or mems as well. In order to reflect the real configuration cgroup v2 provides read-only files cpuset.cpus.effective and cpuset.mems.effective which are exported to users as well.
* pid1: rename start_limit to start_ratelimitZbigniew Jędrzejewski-Szmek2019-09-201-6/+6
| | | | | This way it is clearer what the type is. We also have auto_stop_ratelimit adjacent, and it feels ugly to have a different suffix for those two.
* Create src/shared/unit-file.[ch] for unit-file related opsZbigniew Jędrzejewski-Szmek2019-07-191-0/+1
| | | | | So far we put such functinos in install.[ch], but that is tied too closely to enable/disable. Let's start moving things to a place with a better name.
* pid1: fix GetUnitProcessesZbigniew Jędrzejewski-Szmek2019-07-151-1/+1
| | | | | | | This effectively reverts one chunk of 657ee2d82b73818d0ee8c3c5962c1cb2dbd52b76. For a while I couldn't figure out why 'systemctl status -- -.slice' fails to list any processes...
* core: expose new clean operation on the busLennart Poettering2019-07-111-0/+106
| | | | | This adds CanClean() and Clean() as new methods on the Unit object that initiate the cleaning operation.
* tree-wide: replace strjoin() with path_join()Yu Watanabe2019-06-211-1/+1
|
* basic/process-util: convert bool arg to flagsZbigniew Jędrzejewski-Szmek2019-05-221-1/+1
| | | | In preparation for the next commit…
* Rework cmdline printing to use unicodeZbigniew Jędrzejewski-Szmek2019-05-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* codespell: fix spelling errorsBen Boeckel2019-04-291-1/+1
|
* croup: expose IO accounting data per unitLennart Poettering2019-04-121-0/+34
| | | | | | | | | | | This was the last kind of accounting still not exposed on for each unit. Let's fix that. Note that this is a relatively simplistic approach: we don't expose per-device stats, but sum them all up, much like cgtop does. This kind of metric is probably the most interesting for most usecases, and covers the "systemctl status" output best. If we want per-device stats one day we can of course always add that eventually.
* core: use string_table_lookup() at more placesLennart Poettering2019-04-121-13/+11
|
* core: add new API for enqueing a job with returning the transaction dataLennart Poettering2019-03-271-18/+139
|
* dbus-unit: remove redundant checkLennart Poettering2019-03-251-1/+1
| | | | | We checked this with an assert() a few lines up aleady, no need to check this again.
* core: remove unnecessary heap allocationLennart Poettering2019-03-251-6/+3
|
* core: simplify and check validity of paths for RequiresMountsFor=Yu Watanabe2019-03-081-0/+8
| | | | Prompted by #11910.
* core: Fix -EOPNOTSUPP emergency action error stringAaron Plattner2019-01-171-1/+1
| | | | | | | | | | | | | | | | | 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
* core: Fix return argument check for parse_emergency_actionAaron Plattner2019-01-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* core: clarify that the CollectMode bus property is constantLennart Poettering2018-12-011-1/+1
| | | | it's configured from unit files only, and hence is constant.
* core: send out unit change events when a new invocation ID is acquiredLennart Poettering2018-12-011-1/+1
| | | | | It's free, as this generally coincides with unit_start(), but let's make this clean and explicit.
* core: invalidate invidual Assert/Condition properties when sending out ↵Lennart Poettering2018-12-011-2/+2
| | | | | | | | | change messages Let's inform the clients about assert/condition property changes as they happen, it's basically for free because assert/condition property changes generally coincide with other unit state changes (after all these checks are done on unit_start())
* core: before returning new job path to clients, force out JobNew signalsLennart Poettering2018-12-011-0/+3
| | | | | | | When a client requests a new job, let's make sure we for out the JobNew signals for it, before we return successfully from the method call. After all we shouldn't return a path that is not announced yet, as announcement of jobs should be considered part of the job setup.
* core: whenever we change state of a unit, force out PropertiesChanged bus signalLennart Poettering2018-12-011-0/+21
| | | | | | | | | | | | | | | | | This allows clients to follow our internal state changes safely. Previously, quick state changes (for example, when we restart a unit due to Restart= after it quickly transitioned through DEAD/FAILED states) would be coalesced into one bus signal event, with this change there's the guarantee that all state changes after the unit was announced ones are reflected on th bus. Note we only do this kind of guaranteed flushing only for unit state changes, not for other unit property changes, where clients still have to expect coalescing. This is because the unit state is a very important, high-level concept. Fixes: #10185
* core: allow to set exit status when using SuccessAction=/FailureAction=exit ↵Lennart Poettering2018-11-271-0/+40
| | | | | | | | | | | in units This adds SuccessActionExitStatus= and FailureActionExitStatus= that may be used to configure the exit status to propagate in when SuccessAction=exit or FailureAction=exit is used. When not specified let's also propagate the exit status of the main process we fork off for the unit.
* core: expose bus client names currently reffing a unit as propertyLennart Poettering2018-11-091-0/+39
| | | | | | 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.
* unit: enqueue cgroup empty check event if the last ref on a unit is droppedLennart Poettering2018-11-091-0/+6
|
* core: reword polkit request a bit (#10524)Lennart Poettering2018-10-261-1/+1
| | | | | | | | | | "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.
* core: define "exit" and "exit-force" actions for user units and only accept thatZbigniew Jędrzejewski-Szmek2018-10-171-1/+36
| | | | | | | | | | We would accept e.g. FailureAction=reboot-force in user units and then do an exit in the user manager. Let's be stricter, and define "exit"/"exit-force" as the only supported actions in user units. v2: - rename 'exit' to 'exit-force' and add new 'exit' - add test for the parsing function
* pid1: drop now-unused path parameter to add_dependency_by_name()Zbigniew Jędrzejewski-Szmek2018-09-151-1/+1
|
* core: Fix grammar in error messageSven Joachim2018-07-111-1/+1
|
* core: tiny comment fixLennart Poettering2018-06-281-1/+1
|
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-3/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* core: introduce a new load state "bad-setting"Lennart Poettering2018-06-111-1/+4
| | | | | | | | | | | | | | | | | | Since bb28e68477a3a39796e4999a6cbc6ac6345a9159 parsing failures of certain unit file settings will result in load failures of units. This introduces a new load state "bad-setting" that is entered in precisely this case. With this addition error messages on bad settings should be a lot more explicit, as we don't have to show some generic "errno" error in that case, but can explicitly say that a bad setting is at fault. Internally this unit load state is entered as soon as any configuration loader call returns ENOEXEC. Hence: config parser calls should return ENOEXEC now for such essential unit file settings. Turns out, they generally already do. Fixes: #9107
* core: use bus_unit_validate_load_state() for generating LoadError unit bus ↵Lennart Poettering2018-06-111-6/+8
| | | | | | | | | | | | property The load_error is only valid in some load_state cases, lets generate prettier messages for other cases too, by reusing the bus_unit_validate_load_state() call which does jus that. Clients (such as systemctl) ignored LoadError unles LoadState was "error" before. With this change they could even show LoadError in other cases and it would show a useful name.
* core: rename (and modernize) bus_unit_check_load_state() → ↵Lennart Poettering2018-06-111-10/+18
| | | | | | | | | bus_unit_validate_load_state() Let's use a switch() statement, cover more cases with pretty messages. Also let's rename it to "validate", as that's more specific that "check", as it implies checking for a "valid"/"good" state, which is what this function does.
* pid: fix ENOENT error checkLennart Poettering2018-06-061-1/+1
|
* core/dbus-unit: do not pass whole Unit objectYu Watanabe2018-05-151-15/+15
|
* core/dbus-unit: introduce unit_can_{start,stop,isolate}_refuse_manual() ↵Yu Watanabe2018-05-151-54/+15
| | | | functions
* core: use BUS_DEFINE_PROPERTY_GET* macrosYu Watanabe2018-05-151-21/+7
|
* core: use _cleanup_set_free_ instread of _cleanup_(set_freep)Yu Watanabe2018-05-141-2/+2
|
* dbus-unit: check userdata before obtaining dataYu Watanabe2018-05-131-4/+6
|
* dbus-unit: use BUS_DEFINE_PROPERTY_GET* macrosYu Watanabe2018-05-131-108/+6
|
* path-util: introduce empty_to_root() and use it many placesYu Watanabe2018-05-111-1/+1
|
* core: send NULL instead of empty stringYu Watanabe2018-05-111-5/+3
|
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* core: add new new bus call for migrating foreign processes to scope/service ↵Lennart Poettering2018-02-121-0/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | units This adds a new bus call to service and scope units called AttachProcesses() that moves arbitrary processes into the cgroup of the unit. The primary user for this new API is systemd itself: the systemd --user instance uses this call of the systemd --system instance to migrate processes if itself gets the request to migrate processes and the kernel refuses this due to access restrictions. The primary use-case of this is to make "systemd-run --scope --user …" invoked from user session scopes work correctly on pure cgroupsv2 environments. There, the kernel refuses to migrate processes between two unprivileged-owned cgroups unless the requestor as well as the ownership of the closest parent cgroup all match. This however is not the case between the session-XYZ.scope unit of a login session and the user@ABC.service of the systemd --user instance. The new logic always tries to move the processes on its own, but if that doesn't work when being the user manager, then the system manager is asked to do it instead. The new operation is relatively restrictive: it will only allow to move the processes like this if the caller is root, or the UID of the target unit, caller and process all match. Note that this means that unprivileged users cannot attach processes to scope units, as those do not have "owning" users (i.e. they have now User= field). Fixes: #3388
* dbus-unit: support more options in transient unitsYu Watanabe2018-01-021-65/+196
|
* core: rename dbus property StartLimitIntervalSec= to StartLimitIntervalUSec=Yu Watanabe2018-01-021-1/+2
| | | | | | StartLimitIntervalSec= and DefaultStartLimitIntervalSec= are the last options whose suffix is 'Sec' instead of 'USec'. All the other option has suffix 'USec'. So, let's rename them.
* core: allow changing the description for units dynamically at runtimeLennart Poettering2017-11-291-2/+28
| | | | | | | This makes "systemctl set-property foobar.service Description=waldo" work. See: #7245
* core: add proper escaping to writing of drop-ins/transient unit filesLennart Poettering2017-11-291-18/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | This majorly refactors the transient unit file and drop-in writing logic, so that we properly C-escape and specifier-escape (% → %%) everything we write out, so that when we read it back again, specifiers are parsed that aren't supposed to be parsed. This renames unit_write_drop_in() and friends by unit_write_setting(). The name change is supposed to clarify that the functions are not only used to write drop-in files, but also transient unit files. The previous "mode" parameter to this function is replaced by a more generic "flags", which knows additional flags for implicit C-style and specifier escaping before writing things out. This can cover most properties where either form of escaping is defined. For the cases where this isn't sufficient, we add helpers unit_escape_setting() and unit_concat_strv() for escaping individual strings or strvs properly. While we are at it, we also prettify generation of transient unit files: we try to reduce the number of section headers written out: previously we'd write the right section header our for each setting. With this change we do so only if the setting lives in a different section than the one before. (This should also be considered preparation for when we add proper APIs to systemd to write normal, persistant unit files through the bus API)