summaryrefslogtreecommitdiff
path: root/src/shared/install.c
AgeCommit message (Collapse)Author
2016-10-10install: let's always refer to the actual setting in errorsLennart Poettering
2016-09-10shared/install: fix set-default with empty root (#4118)Zbigniew Jędrzejewski-Szmek
https://bugzilla.redhat.com/show_bug.cgi?id=1374371 When root was empty or equal to "/", chroot_symlinks_same was called with root==NULL, and strjoina returned "", so the code thought both paths are equal even if they were not. Fix that by always providing a non-null first argument to strjoina.
2016-08-30install: fix disable when /etc/systemd/system is a symlinkLukas Nykryn
2016-08-21shared/install: do not enable masked instances (#4005)Zbigniew Jędrzejewski-Szmek
When told to enable a template unit, and the DefaultInstance specified in that unit was masked, we would do this. Such a unit cannot be started or loaded, so reporting successful enabling is misleading and unexpected. $ systemctl mask getty@tty1 Created symlink /etc/systemd/system/getty@tty1.service → /dev/null. $ systemctl --root=/ enable getty@tty1 (unchanged) Failed to enable unit, unit /etc/systemd/system/getty@tty1.service is masked. $ systemctl --root=/ enable getty@ (before) Created symlink /etc/systemd/system/getty.target.wants/getty@tty1.service → /usr/lib/systemd/system/getty@.service. (now) Failed to enable unit, unit /etc/systemd/system/getty@tty1.service is masked. The same error is emitted for enable and preset. And an error is emmited, not a warning, so the failure to enable DefaultInstance is treated the same as if the instance was specified on the command line. I think that this makes most sense, for most template units. Fixes #2513.
2016-08-19shared/install: properly report masked units listed in Also=Zbigniew Jędrzejewski-Szmek
A masked unit is listed in Also=: $ systemctl cat test1 test2 →# /etc/systemd/system/test1.service [Unit] Description=test service 1 [Service] Type=oneshot ExecStart=/usr/bin/true [Install] WantedBy=multi-user.target Also=test2.service Alias=alias1.service →# /dev/null $ systemctl --root=/ enable test1 (before) Created symlink /etc/systemd/system/alias1.service → /etc/systemd/system/test1.service. Created symlink /etc/systemd/system/multi-user.target.wants/test1.service → /etc/systemd/system/test1.service. The unit files have no installation config (WantedBy, RequiredBy, Also, Alias settings in the [Install] section, and DefaultInstance for template units). This means they are not meant to be enabled using systemctl. Possible reasons for having this kind of units are: 1) A unit may be statically enabled by being symlinked from another unit's .wants/ or .requires/ directory. 2) A unit's purpose may be to act as a helper for some other unit which has a requirement dependency on it. 3) A unit may be started when needed via activation (socket, path, timer, D-Bus, udev, scripted systemctl call, ...). 4) In case of template units, the unit is meant to be enabled with some instance name specified. (after) Created symlink /etc/systemd/system/alias1.service → /etc/systemd/system/test1.service. Created symlink /etc/systemd/system/multi-user.target.wants/test1.service → /etc/systemd/system/test1.service. Unit /etc/systemd/system/test2.service is masked, ignoring.
2016-08-19shared/install: when creating symlinks, keep existing relative symlinksZbigniew Jędrzejewski-Szmek
Running preset-all on a system installed from rpms or even created using make install would remove and recreate a lot of symlinks, changing relative to absolute symlinks. In general relative symlinks are nicer, so there is no reason to change them, and those spurious changes were obscuring more interesting stuff. $ make install DESTDIR=/var/tmp/inst1 $ systemctl preset-all --root=/var/tmp/inst1 (before) Removed /var/tmp/inst1/etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service. Created symlink /var/tmp/inst1/etc/systemd/system/ctrl-alt-del.target → /usr/lib/systemd/system/exit.target. Removed /var/tmp/inst1/etc/systemd/system/multi-user.target.wants/remote-fs.target. Created symlink /var/tmp/inst1/etc/systemd/system/multi-user.target.wants/remote-fs.target → /usr/lib/systemd/system/remote-fs.target. Created symlink /var/tmp/inst1/etc/systemd/system/multi-user.target.wants/machines.target → /usr/lib/systemd/system/machines.target. Created symlink /var/tmp/inst1/etc/systemd/system/sockets.target.wants/systemd-journal-remote.socket → /usr/lib/systemd/system/systemd-journal-remote.socket. Removed /var/tmp/inst1/etc/systemd/system/sockets.target.wants/systemd-networkd.socket. Created symlink /var/tmp/inst1/etc/systemd/system/sockets.target.wants/systemd-networkd.socket → /usr/lib/systemd/system/systemd-networkd.socket. Removed /var/tmp/inst1/etc/systemd/system/getty.target.wants/getty@tty1.service. Created symlink /var/tmp/inst1/etc/systemd/system/getty.target.wants/getty@tty1.service → /usr/lib/systemd/system/getty@.service. Created symlink /var/tmp/inst1/etc/systemd/system/multi-user.target.wants/systemd-journal-upload.service → /usr/lib/systemd/system/systemd-journal-upload.service. Removed /var/tmp/inst1/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service. Created symlink /var/tmp/inst1/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service → /usr/lib/systemd/system/systemd-timesyncd.service. Removed /var/tmp/inst1/etc/systemd/system/multi-user.target.wants/systemd-resolved.service. Created symlink /var/tmp/inst1/etc/systemd/system/multi-user.target.wants/systemd-resolved.service → /usr/lib/systemd/system/systemd-resolved.service. Removed /var/tmp/inst1/etc/systemd/system/multi-user.target.wants/systemd-networkd.service. Created symlink /var/tmp/inst1/etc/systemd/system/multi-user.target.wants/systemd-networkd.service → /usr/lib/systemd/system/systemd-networkd.service. (after) Removed /var/tmp/inst1/etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service. Created symlink /var/tmp/inst1/etc/systemd/system/ctrl-alt-del.target → /usr/lib/systemd/system/exit.target. Created symlink /var/tmp/inst1/etc/systemd/system/multi-user.target.wants/machines.target → /usr/lib/systemd/system/machines.target. Created symlink /var/tmp/inst1/etc/systemd/system/sockets.target.wants/systemd-journal-remote.socket → /usr/lib/systemd/system/systemd-journal-remote.socket. Created symlink /var/tmp/inst1/etc/systemd/system/multi-user.target.wants/systemd-journal-upload.service → /usr/lib/systemd/system/systemd-journal-upload.service.
2016-08-19shared/install: move root skipping into create_symlink()Zbigniew Jędrzejewski-Szmek
No functional change intended.
2016-08-19shared/install: ignore unit symlinks when doing preset-allZbigniew Jędrzejewski-Szmek
Before, when interating over unit files during preset-all, behaviour was the following: - if we hit the real unit name first, presets were queried for that name, and that unit was enabled or disabled accordingly, - if we hit an alias first (one of the symlinks chaining to the real unit), we checked the presets using the symlink name, and then proceeded to enable or disable the real unit. E.g. for systemd-networkd.service we have the alias dbus-org.freedesktop.network1.service (/usr/lib/systemd/system/dbus-org.freedesktop.network1.service), but the preset is only for the systemd-networkd.service name. The service would be enabled or disabled pseudorandomly depending on the order of iteration. For "preset", behaviour was analogous: preset on the alias name disabled the service (following the default disable policy), preset on the "real" name applied the presets. With the patch, for "preset" and "preset-all" we silently skip symlinks. This gives mostly the right behaviour, with the limitation that presets on aliases are ignored. I think that presets on aliases are not that common (at least my preset files on Fedora don't exhibit any such usage), and should not be necessary, since whoever installs the preset can just refer to the real unit file. It would be possible to overcome this limitation by gathering a list of names of a unit first, and then checking whether *any* of the names matches the presets list. That would require a significant redesign of the code, and be a lot slower (since we would have to fully read all unit directories to preset one unit) to so I'm not doing that for now. With this patch, two properties are satisfied: - preset-all and preset are idempotent, and the second and subsequent invocations do not produce any changes, - preset-all and preset for a specific name produce the same state for that unit. Fixes #3616.
2016-08-19shared/install: remove unused paramater and add more commentsZbigniew Jędrzejewski-Szmek
2016-08-19systemctl: fix preset-all with missing /etc/systemd/systemZbigniew Jędrzejewski-Szmek
If the directory is missing, we can assume that those pesky symlinks are gone too.
2016-08-09install: follow config_path symlink (#3362)Rhys
Under NixOS, the config_path /etc/systemd/system is a symlink to /etc/static/systemd/system. Commands such as `systemctl list-unit-files` and `systemctl is-enabled` did not work as the symlink was not followed. This does not affect how symlinks are treated within the config_path directory.
2016-07-25shared/install: allow "enable" on linked unit files (#3790)Zbigniew Jędrzejewski-Szmek
User expectations are broken when "systemctl enable /some/path/service.service" behaves differently to "systemctl link ..." followed by "systemctl enable". From user's POV, "enable" with the full path just combines the two steps into one. Fixes #3010.
2016-06-15load-fragment: ignore ENOTDIR/EACCES errors (#3510)Zbigniew Jędrzejewski-Szmek
If for whatever reason the file system is "corrupted", we want to be resilient and ignore the error, as long as we can load the units from a different place. Arch bug https://bugs.archlinux.org/task/49547. A user had an ntfs symlink (essentially a file) instead of a directory after restoring from backup. We should just ignore that like we would treat a missing directory, for general resiliency. We should treat permission errors similarly. For example an unreadable /usr/local/lib directory would prevent (user) instances of systemd from loading any units. It seems better to continue.
2016-05-09tree-wide: rename draw_special_char to special_glyphZbigniew Jędrzejewski-Szmek
That function doesn't draw anything on it's own, just returns a string, which sometimes is more than one character. Also remove "DRAW_" prefix from character names, TREE_* and ARROW and BLACK_CIRCLE are unambigous on their own, don't draw anything, and are always used as an argument to special_glyph(). Rename "DASH" to "MDASH", as there's more than one type of dash.
2016-05-09shared/install: use "→" instead of "pointing to" for a symlinkZbigniew Jędrzejewski-Szmek
It's quite a bit shorter and just as readable. (The full sentence with "pointing to" was added to replace a text that used "ln -s %s %s". Using the "ln" syntax is indeed unclear, because it's not obvious which is the source and which is the target, and because symlink(2) uses the opposite order to ln(1). But with the unicode arrow there should be no ambiguity.)
2016-05-09shared/install: do not print warning when a unit is already enabledZbigniew Jędrzejewski-Szmek
Executing 'systemctl enable' on the same unit twice would cause a warning about a missing [Install] section to be printed. To avoid this, count all symlinks that "would" be created, and return 1 no matter if we actually created a symlink or skipped creation because it already exists.
2016-05-09shared/install: handle dangling aliases as an explicit case, report nicelyZbigniew Jędrzejewski-Szmek
This fixes 'preset-all' with a unit that is a dangling symlink. $ systemctl --root=/ preset-all Unit syslog.service is an alias to a unit that is not present, ignoring. Unit auditd.service is masked, ignoring. Unit NetworkManager.service is masked, ignoring.
2016-05-09shared/install: add some more debug messages and commentsZbigniew Jędrzejewski-Szmek
$ systemctl --root=/ preset foobar.service Cannot find unit foobar.service. Failed to preset: No such file or directory. $ systemctl --root=/ preset foobar@.service Cannot find unit foobar@.service. Failed to preset: No such file or directory. $ systemctl --root=/ preset foobar@blah.service Cannot find unit foobar@blah.service or foobar@.service. Failed to preset: No such file or directory.
2016-05-07shared/install: simplify error handling conditionals in a few placesZbigniew Jędrzejewski-Szmek
2016-05-03Merge pull request #3183 from crawford/preset-arrayZbigniew Jędrzejewski-Szmek
install: cache the presets before evaluating
2016-05-03install: cache the presets before evaluatingAlex Crawford
The previous implementation traversed the various config directories, walking the preset files and parsing each line to determine if a service should be enabled or disabled. It did this for every service which resulted in many more file operations than neccessary. This approach parses each of the preset entries into an array which is then used to check if each service should be enabled or disabled.
2016-05-01shared/install: refuse template files for non-templateable unitsZbigniew Jędrzejewski-Szmek
$ systemctl --root=/ enable templated@bar.mount Unit type mount cannot be templated. Failed to enable: Invalid argument.
2016-05-01shared/install: warn about DefaultInstance in non-template unitsZbigniew Jędrzejewski-Szmek
[/etc/systemd/system/mnt-test.mount:6] DefaultInstance only makes sense for template units, ignoring.
2016-05-01Move no_instances information to shared/Zbigniew Jędrzejewski-Szmek
This way it can be used in install.c in subsequent commit.
2016-05-01shared/install: ignore Alias in [Install] of units which don't allow aliasesZbigniew Jędrzejewski-Szmek
A downside is that a warning about missing [Install] is printed: $ systemctl --root=/ enable mnt-test.mount [/etc/systemd/system/mnt-test.mount:5] Aliases are not allowed for mount units, ignoring. The unit files have no installation config (WantedBy, RequiredBy, Also, Alias settings in the [Install] section, and DefaultInstance for template units). This means they are not meant to be enabled using systemctl. Possible reasons for having this kind of units are: 1) A unit may be statically enabled by being symlinked from another unit's .wants/ or .requires/ directory. 2) A unit's purpose may be to act as a helper for some other unit which has a requirement dependency on it. 3) A unit may be started when needed via activation (socket, path, timer, D-Bus, udev, scripted systemctl call, ...). 4) In case of template units, the unit is meant to be enabled with some instance name specified. That's a bit misleading, but I don't see an easy way to fix this. But the situation is similar for many other parsing errors, so maybe that's OK.
2016-05-01Move no_alias information to shared/Zbigniew Jędrzejewski-Szmek
This way it can be used in install.c in subsequent commit.
2016-04-29core: Filter by unit name behind the D-Bus, instead on the client side (#3142)kayrus
This commit improves systemd performance on the systems which have thousands of units.
2016-04-28install: upgrade message to a warningAlex Crawford
2016-04-22treewide: fix typos (#3092)Torstein Husebø
2016-04-21shared/install: always overwrite symlinks in .wants and .requiresZbigniew Jędrzejewski-Szmek
Before: $ systemctl preset getty@.service Failed to preset unit, file /etc/systemd/system/getty.target.wants/getty@tty1.service already exists and is a symlink to ../../../../usr/lib/systemd/system/getty@.service. After: $ systemctl preset getty@.service Created symlink /etc/systemd/system/getty.target.wants/getty@tty1.service, pointing to /usr/lib/systemd/system/getty@.service. We don't really care where the symlink points to. For example, it might point to /usr/lib or /etc, and systemd will always load the unit from /etc in preference to /usr/lib. In fact, if we make a symlink like /etc/systemd/system/multi-user.target.wants/b.service -> ../a.service, pid1 will still start b.service. The name of the symlink is the only thing that matters, as far as systemd is concerned. For humans it's confusing when the symlinks points to anything else than the actual unit file. At the very least, the symlink is supposed to point to a file with the same name in some other directory. Since we don't care where the symlink points, we can always replace an existing symlink. Another option I considered would be to simply leave an existing symlink in place. That would work too, but replacing the symlink with the expected value seems more intuitive. Of course those considerations only apply to .wants and .requires. Symlinks created with "link" and "alias" are a separate matter. Fixes #3056.
2016-04-21shared/install: rewrite unit_file_changes_add()Zbigniew Jędrzejewski-Szmek
path_kill_slashes was applied to the wrong arg...
2016-04-21shared/install: nicer error message is symlinking chokes on an existing fileZbigniew Jędrzejewski-Szmek
Fixes #1892. Previously: Failed to enable unit: Invalid argument Now: Failed to enable unit, file /etc/systemd/system/ssh.service already exists. It would be nice to include the unit name in the message too. I looked into this, but it would require major surgery on the whole installation logic, because we first create a list of things to change, and then try to apply them in a loop. To transfer the knowledge which unit was the source of each change, the data structures would have to be extended to carry the unit name over into the second loop. So I'm skipping this for now.
2016-04-19systemctl: warning about missing install info for template unitsZbigniew Jędrzejewski-Szmek
The advice string didn't talk about template units at all. Extend it and print when trying to enable a template unit without install info. Fixes #2345.
2016-04-19shared/install,systemctl,core: report offending file on installation errorZbigniew Jędrzejewski-Szmek
Fixes #2191: $ systemctl --root=/ enable sddm Created symlink /etc/systemd/system/display-manager.service, pointing to /usr/lib/systemd/system/sddm.service. $ sudo build/systemctl --root=/ enable gdm Failed to enable unit, file /etc/systemd/system/display-manager.service already exists and is a symlink to /usr/lib/systemd/system/sddm.service. $ sudo build/systemctl --root= enable sddm $ sudo build/systemctl --root= enable gdm Failed to enable unit: File /etc/systemd/system/display-manager.service already exists and is a symlink to /usr/lib/systemd/system/sddm.service. (I tried a few different approaches to pass the error information back to the caller. Adding a new parameter to hold the error results in a gigantic patch and a lot of hassle to pass the args arounds. Adding this information to the changes array is straightforward and can be more easily extended in the future.) In case local installation is performed, the full set of errors can be reported and we do that. When running over dbus, only the first error is reported.
2016-04-18Various formatting and style fixesZbigniew Jędrzejewski-Szmek
2016-04-16install: allow paths like LookupPath.generator to be NULLZbigniew Jędrzejewski-Szmek
Fixes #3047.
2016-04-16systemctl/core: ignore masked units in preset-allZbigniew Jędrzejewski-Szmek
With any masked unit that would that would be enabled by presets, we'd get: test@rawhide $ sudo systemctl preset-all Failed to execute operation: Unit file is masked. test@rawhide $ sudo systemctl --root=/ preset-all Operation failed: Cannot send after transport endpoint shutdown Simply ignore those units: test@rawhide $ sudo systemctl preset-all Unit xxx.service is masked, ignoring.
2016-04-16tree-wide: use ERFKILL instead of ESHUTDOWN for "unit masked"Zbigniew Jędrzejewski-Szmek
If the error code ever leaks (we print the strerror error instead of providing our own), the message for ESHUTDOWN is "Cannot send after transport endpoint shutdown", which can be misleading. In particular it suggest that some mishandling of the dbus connection occured. Let's change that to ERFKILL which has the advantage that a) it sounds implausible as actual error, b) has the connotation of disabling something manually.
2016-04-12core,systemctl: add new "systemctl revert" commandLennart Poettering
This allows dropping all user configuration and reverting back to the vendor default of a unit file. It basically undoes what "systemctl edit", "systemctl set-property" and "systemctl mask" do.
2016-04-12install: fix errno handlingLennart Poettering
2016-04-12install: simplify skip_root() a bitLennart Poettering
Exit early, so that we can get rid of the large if block.
2016-04-12nstall: no need to export unit_file_lookup_state() anymoreLennart Poettering
We only use it inside of install.c, hence let's make it static.
2016-04-12systemctl: don't confuse sysv code with generated unitsLennart Poettering
The SysV compat code checks whether there's a native unit file before looking for a SysV init script. Since the newest rework generated units will show up in the unit path, and hence the checks ended up assuming that there always was a native unit file for each init script: the generated one. With this change the generated unit file directory is suppressed from the search path when this check is done, to avoid the confusion.
2016-04-12systemctl: move check whether a service exists as native unit file to install.cLennart Poettering
Move the search path check from the SysV service compat support into install.c so that we can reuse the usual algorithm instead of rolling a private loop for this.
2016-04-12install: unify checking whether operations may be applied to a unit file in ↵Lennart Poettering
a new function Let's replace repeated code by a single implementation in a single function.
2016-04-12install: introduce a new unit file state "transient"Lennart Poettering
Now, that the search path logic knows the unit path for transient units we also can introduce an explicit unit file state "transient" that clarifies to the user what kind of unit file he is encountering.
2016-04-12install: fix root prefix handlingLennart Poettering
Previously, we'd execute some operations with the root prefix applied, while others without (which was a bug). Clean this up: all paths are now prefixed properly with the root path, and we strip it off when necessary. (Of course, an alternative option would be to strictly pass around paths without the prefix prepended and only prepend it right before hitting the disk, however, I am came to the conclusion this would result in more code.)
2016-04-12install: add root directory to LookupPaths structureLennart Poettering
We use the root directory parameter while putting together the LookupPaths structure, hence let's also store it in the structure as-is. That way we can drop a parameter from half of the functions in install.c Also, let's move the validation of the root paths into lookup_paths_init() so that we can drop even more code from install.c
2016-04-12install: change in_search_path() to take a LookupPaths structureLennart Poettering
Similar to the other calls that operate on the collected path data.
2016-04-12install: rename unit_file_is_generated() → path_is_generator()Lennart Poettering
This way the funciton name matches nicely our other calls path_is_config() and path_is_runtime().