summaryrefslogtreecommitdiff
path: root/src/shared/install.c
AgeCommit message (Collapse)Author
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().
2016-04-12install: be more accurate when checking whether something is runtime ↵Lennart Poettering
configuration Let's actually check the runtime config dir, instead of just /run.
2016-04-12core: remove ManagerRunningAs enumLennart Poettering
Previously, we had two enums ManagerRunningAs and UnitFileScope, that were mostly identical and converted from one to the other all the time. The latter had one more value UNIT_FILE_GLOBAL however. Let's simplify things, and remove ManagerRunningAs and replace it by UnitFileScope everywhere, thus making the translation unnecessary. Introduce two new macros MANAGER_IS_SYSTEM() and MANAGER_IS_USER() to simplify checking if we are running in one or the user context.
2016-04-12install: make use of configuration directory paths in LookupPathsLennart Poettering
Now that the LookupPaths structure contains the directory paths, let's make use of that everywhere instead of duplicating the logic.
2016-04-12core: when enabling a generated unit file, return a clean errorLennart Poettering
Let's be precise when the user tries to invoke an "enable" operation on a generated unit file.
2016-04-12core: add a new unit file state "generated"Lennart Poettering
Now that we store the generator directories in LookupPaths we can use this to intrdouce a new unit file state called "generated", for units in these directories. Fixes: #2348
2016-04-12core: rework generator dir logic, move the dirs into LookupPaths structureLennart Poettering
A long time ago – when generators where first introduced – the directories for them were randomly created via mkdtemp(). This was changed later so that they use fixed name directories now. Let's make use of this, and add the genrator dirs to the LookupPaths structure and into the unit file search path maintained in it. This has the benefit that the generator dirs are now normal part of the search path for all tools, and thus are shown in "systemctl list-unit-files" too.
2016-04-11Install: correctly report symlink creationsMartin Pitt
All callers of create_symlink(), such as install_info_symlink_wants(), expect that to return > 0 if it actually did something, and then return that number. unit_file_enable() uses that to determine if any action was done (carries_install_info != 0) and if not, show a "The unit files have no [Install] section" warning. Return 1 instead of 0 in the two code paths of create_symlink() when the link was created or replaced with a new value. This fixes getting a bogus "No [Install] section" warning when enabling a unit with full path, like "systemctl enable /some/path/myunit.service".
2016-02-10tree-wide: remove Emacs lines from all filesDaniel Mack
This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
2015-12-06shared: include what we useThomas Hindoe Paaboel Andersen
The next step of a general cleanup of our includes. This one mostly adds missing includes but there are a few removals as well.
2015-11-15install: don't mix state and type enumsThomas Hindoe Paaboel Andersen
from 0ec0deaa
2015-11-12core: simplify handling of %u, %U, %s and %h unit file specifiersLennart Poettering
Previously, the %u, %U, %s and %h specifiers would resolve to the user name, numeric user ID, shell and home directory of the user configured in the User= setting of a unit file, or the user of the manager instance if no User= setting was configured. That at least was the theory. In real-life this was not ever actually useful: - For the systemd --user instance it made no sense to ever set User=, since the instance runs in user context after all, and hence the privileges to change user IDs don't even exist. The four specifiers were actually not useful at all in this case. - For the systemd --system instance we did not allow any resolving that would require NSS. Hence, %s and %h were not supported, unless User=root was set, in which case they would be hardcoded to /bin/sh and /root, to avoid NSS. Then, %u would actually resolve to whatever was set with User=, but %U would only resolve to the numeric UID of that setting if the User= was specified in numeric form, or happened to be root (in which case 0 was hardcoded as mapping). Two of the specifiers are entirely useless in this case, one is realistically also useless, and one is pretty pointless. - Resolving of these settings would only happen if User= was actually set *before* the specifiers where resolved. This behaviour was undocumented and is really ugly, as specifiers should actually be considered something that applies to the whole file equally, independently of order... With this change, %u, %U, %s and %h are drastically simplified: they now always refer to the user that is running the service instance, and the user configured in the unit file is irrelevant. For the system instance of systemd this means they always resolve to "root", "0", "/bin/sh" and "/root", thus avoiding NSS. For the user instance, to the data for the specific user. The new behaviour is identical to the old behaviour in all --user cases and for all units that have no User= set (or set to "0" or "root").
2015-11-12install: follow unit file symlinks in /usr, but not /etc when looking for ↵Lennart Poettering
[Install] data Some distributions use alias unit files via symlinks in /usr to cover for legacy service names. With this change we'll allow "systemctl enable" on such aliases. Previously, our rule was that symlinks are user configuration that "systemctl enable" + "systemctl disable" creates and removes, while unit files is where the instructions to do so are store. As a result of the rule we'd never read install information through symlinks, since that would mix enablement state with installation instructions. Now, the new rule is that only symlinks inside of /etc are configuration. Unit files, and symlinks in /usr are now valid for installation instructions. This patch is quite a rework of the whole install logic, and makes the following addional changes: - Adds a complete test "test-instal-root" that tests the install logic pretty comprehensively. - Never uses canonicalize_file_name(), because that's incompatible with operation relative to a specific root directory. - unit_file_get_state() is reworked to return a proper error, and returns the state in a call-by-ref parameter. This cleans up confusion between the enum type and errno-like errors. - The new logic puts a limit on how long to follow unit file symlinks: it will do so only for 64 steps at max. - The InstallContext object's fields are renamed to will_process and has_processed (will_install and has_installed) since they are also used for deinstallation and all kinds of other operations. - The root directory is always verified before use. - install.c is reordered to place the exported functions together. - Stricter rules are followed when traversing symlinks: the unit suffix must say identical, and it's not allowed to link between regular units and templated units. - Various modernizations - The "invalid" unit file state has been renamed to "bad", in order to avoid confusion between UNIT_FILE_INVALID and _UNIT_FILE_STATE_INVALID. Given that the state should normally not be seen and is not documented this should not be a problematic change. The new name is now documented however. Fixes #1375, #1718, #1706
2015-11-12install: never log from install functionsLennart Poettering
Instead, let the caller do that. Fix this by moving masked unit messages into the caller, by returning a clear error code (ESHUTDOWN) by which this may be detected.
2015-11-12install: various simplificationsLennart Poettering
2015-10-28install: port to extract_first_wordSusant Sahani
2015-10-27util-lib: split out allocation calls into alloc-util.[ch]Lennart Poettering
2015-10-27util-lib: move string table stuff into its own string-table.[ch]Lennart Poettering
2015-10-27util-lib: split stat()/statfs()/stavfs() related calls into stat-util.[ch]Lennart Poettering
2015-10-27util-lib: move a number of fs operations into fs-util.[ch]Lennart Poettering
2015-10-27util-lib: introduce dirent-util.[ch] for directory entry callsLennart Poettering
Also, move a couple of more path-related functions to path-util.c.
2015-10-27util: remove path_get_parent(), in favour of dirname_malloc()Lennart Poettering
We don't need two functions that do essentialy the same, hence drop path_get_parent(), and stick to dirname_malloc(), but move it to path-util.[ch].
2015-10-25util-lib: split out fd-related operations into fd-util.[ch]Lennart Poettering
There are more than enough to deserve their own .c file, hence move them over.
2015-10-24util-lib: split our string related calls from util.[ch] into its own file ↵Lennart Poettering
string-util.[ch] There are more than enough calls doing string manipulations to deserve its own files, hence do something about it. This patch also sorts the #include blocks of all files that needed to be updated, according to the sorting suggestions from CODING_STYLE. Since pretty much every file needs our string manipulation functions this effectively means that most files have sorted #include blocks now. Also touches a few unrelated include files.
2015-09-30tree-wide: clean up log_syntax() usageLennart Poettering
- Rely everywhere that we use abs() on the error code passed in anyway, thus don't need to explicitly negate what we pass in - Never attach synthetic error number information to log messages. Only log about errors we *receive* with the error number we got there, don't log any synthetic error, that don#t even propagate, but just eat up. - Be more careful with attaching exactly the error we get, instead of errno or unrelated errors randomly. - Fix one occasion where the error number and line number got swapped. - Make sure we never tape over OOM issues, or inability to resolve specifiers
2015-06-25install: make unit_file_get_list aware of UNIT_FILE_INDIRECTMichal Sekletar
Commit aedd401 introduced new unit file state, UNIT_FILE_INDIRECT. Unit file is said to have indirect state if it contains [Install] section which has only Also= directive. Thus, if enable of such unit file is requested then some other unit file gets enabled. Whether or not unit file is in indirect state can be determined by calling unit_file_can_install. Function unit_file_get_list populates list of unit files present in given lookup location. So far it did call unit_file_can_install in a way that would prevent finding out about unit files in indirect state. Such unit file would be incorrectly marked as static. Fixes following assertion in test-install, Assertion 'p->state == s' failed at src/test/test-install.c:59, function main(). Aborting. [1] 26868 abort (core dumped) ./test-install
2015-06-25install: explicitly return 0 on successMichal Sekletar
Maybe there is some left-over value stored in r from previous function call. Let's make sure we always return consistent error code when we reach end of the function body. Fixes following crash of test-install, Assertion 'r == 0' failed at src/test/test-install.c:52, function main(). Aborting. [1] 11703 abort (core dumped) ./test-install
2015-06-23install: fix bad memory accessLennart Poettering
2015-05-15systemctl: introduce --now for enable, disable and maskJan Synacek
https://bugs.freedesktop.org/show_bug.cgi?id=42940