summaryrefslogtreecommitdiff
path: root/src/shared/install.c
Commit message (Collapse)AuthorAgeFilesLines
* shared/install: fix error codes returned by install_context_apply()Franck Bui2019-09-241-1/+1
|
* shared/install: typoZbigniew Jędrzejewski-Szmek2019-07-291-1/+1
|
* Create src/shared/unit-file.[ch] for unit-file related opsZbigniew Jędrzejewski-Szmek2019-07-191-20/+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.
* tree-wide: get rid of strappend()Lennart Poettering2019-07-121-1/+1
| | | | | It's a special case of strjoin(), so no need to keep both. In particular as typing strjoin() is even shoert than strappend().
* Merge pull request #12836 from yuwata/tree-wide-replace-strjoinLennart Poettering2019-06-221-4/+4
|\ | | | | tree-wide: replace strjoin() with path_join()
| * tree-wide: replace strjoin() with path_join()Yu Watanabe2019-06-211-4/+4
| |
* | path-util: get rid of prefix_root()Lennart Poettering2019-06-211-3/+3
|/ | | | | | | | | | | | | | | | | | | prefix_root() is equivalent to path_join() in almost all ways, hence let's remove it. There are subtle differences though: prefix_root() will try shorten multiple "/" before and after the prefix. path_join() doesn't do that. This means prefix_root() might return a string shorter than both its inputs combined, while path_join() never does that. I like the path_join() semantics better, hence I think dropping prefix_root() is totally OK. In the end the strings generated by both functon should always be identical in terms of path_equal() if not streq(). This leaves prefix_roota() in place. Ideally we'd have path_joina(), but I don't think we can reasonably implement that as a macro. or maybe we can? (if so, sounds like something for a later PR) Also add in a few missing OOM checks
* codespell: fix spelling errorsBen Boeckel2019-04-291-2/+2
|
* shared/install: try even harder to make sure variable is initalizedZbigniew Jędrzejewski-Szmek2019-03-261-4/+4
| | | | | Apparently the fix in a05294ff05923563087b53c1db64816130be3b34 was not sufficient. Let's declare the two arrays as static variables.
* tree-wide: constify a few static string tablesLennart Poettering2019-03-251-1/+1
|
* shared/install: Preserve escape characters for escaped unit namesDavid Michael2019-03-201-1/+1
| | | | | | | | | Since switching to extract_first_word with no flags for parsing unit names in 4c9565eea534cd233a913c8c21f7920dba229743, escape characters will be stripped from escaped unit names such as "mnt-persistent\x2dvolume.mount" resulting in the unit not being configured as defined. Preserve escape characters again for compatibility with existing preset definitions.
* shared/install: do not use a temporary variable outside of its scopeZbigniew Jędrzejewski-Szmek2019-02-281-8/+3
| | | | | | | | | Coverity says: > Pointer to local outside scope (RETURN_LOCAL)9. > use_invalid: Using dirs, which points to an out-of-scope temporary variable of type char const *[5]. And indeed, the switch statement forms a scope. Let's use an if to avoid creating a scope.
* Introduce CONF_PATHS_USR_STRV to mirror CONF_PATHS_STRVZbigniew Jędrzejewski-Szmek2019-02-181-18/+5
|
* shared/install: generate list of files in separate functionZbigniew Jędrzejewski-Szmek2019-02-181-8/+19
| | | | No functional change.
* Remove 'inline' attributes from static functions in .c files (#11426)Topi Miettinen2019-01-151-3/+3
| | | Let the compiler perform inlining (see #11397).
* Merge pull request #11143 from keszybz/enable-symlinkLennart Poettering2018-12-161-26/+41
|\ | | | | Runtime mask symlink confusion fix
| * shared/install: ignore symlinks which have lower priority than the unit fileZbigniew Jędrzejewski-Szmek2018-12-131-6/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In #10583, a unit file lives in ~/.config/systemd/user, and 'systemctl --runtime --user mask' is used to create a symlink in /run. This symlink has lower priority than the config file, so 'systemctl --user' will happily load the unit file, and does't care about the symlink at all. But when asked if the unit is enabled, we'd look for all symlinks, find the symlink in the runtime directory, and report that the unit is runtime-enabled. In this particular case the fact that the symlink points at /dev/null, creates additional confusion, but it doesn't really matter: *any* symlink (or regular file) that is lower in the priority order is "covered" by the unit fragment, and should be ignored. Fixes #10583.
| * shared/install: add some more debugging infoZbigniew Jędrzejewski-Szmek2018-12-131-2/+8
| | | | | | | | Just to make it easier to understand what is going on.
| * shared/install: remove two conditionals which are always falseZbigniew Jędrzejewski-Szmek2018-12-131-14/+6
| | | | | | | | | | | | | | | | | | | | | | The name argument in UnitFileInstallInfo (i->name) should always be a unit file name, so the conditional always takes the 'else' branch. The only call chain that links to find_symlinks_fd() is unit_file_lookup_state → find_symlinks_in_scope → find_symlinks → find_symlinks_fd. But unit_file_lookup_state calls unit_name_is_valid(name), and then name is used to construct the UnitFileInstallInfo object in install_info_discover, which just uses the name it was given.
| * shared/install: mark UnitFileInstallInfo* as const where appropriateZbigniew Jędrzejewski-Szmek2018-12-121-6/+6
| |
* | locale-util: prefix special glyph enum values with SPECIAL_GLYPH_Lennart Poettering2018-12-141-1/+1
| | | | | | | | | | | | | | This has been irritating me for quite a while: let's prefix these enum values with a common prefix, like we do for almost all other enums. No change in behaviour, just some renaming.
* | tree-wide: Remove O_CLOEXEC from fdopenChris Down2018-12-121-1/+1
|/ | | | | | | | | | | | fdopen doesn't accept "e", it's ignored. Let's not mislead people into believing that it actually sets O_CLOEXEC. From `man 3 fdopen`: > e (since glibc 2.7): > Open the file with the O_CLOEXEC flag. See open(2) for more information. This flag is ignored for fdopen() As mentioned by @jlebon in #11131.
* Merge pull request #10892 from mbiebl/revert-systemctl-runtime-unmask-breakageZbigniew Jędrzejewski-Szmek2018-12-121-75/+87
|\ | | | | | | Revert "systemctl: when removing enablement or mask symlinks, cover both /run and /etc
| * Revert "systemctl: when removing enablement or mask symlinks, cover both ↵Michael Biebl2018-11-271-75/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | /run and /etc" Having systemctl disable/unmask remove all symlinks in /etc and /run is unintuitive and breaks existing use cases. systemctl should behave symmetrically. A "systemctl --runtime unmask" should undo a "systemctl --runtime mask" action. Say you have a service, which was masked by the admin in /etc. If you temporarily want to mask the execution of the service (say in a script), you'd create a runtime mask via "systemctl --runtime mask". It is is now no longer possible to undo this temporary mask without nuking the admin changes, unless you start rm'ing files manually. While it is useful to be able to remove all enablement/mask symlinks in one go, this should be done via a separate command line switch, like "systemctl --all unmask". This reverts commit 4910b35078ad24dcbc63f372b2fee087640201d0. Fixes: #9393
* | tree-wide: rename path_join_many() to path_join()Zbigniew Jędrzejewski-Szmek2018-11-301-2/+2
| | | | | | | | | | | | $ git grep -e path_join_many -l|xargs sed -r -i 's/path_join_many/path_join/g' The two test functions are merged into one.
* | tree-wide: replace path_join with path_join_manyZbigniew Jędrzejewski-Szmek2018-11-301-2/+2
| |
* | install: when enabling a template unit without DefaultInstance= nor ↵Lennart Poettering2018-11-281-1/+5
| | | | | | | | | | | | | | | | | | | | | | specified instance don't do anything Previously, we'd link the unit file into /etc in this case, but that should only be done if the unit file is not in the search path anyway, and this is already done implicitly anyway for all enabled unit files, hence no reason to duplicate this here. Fixes: #10253
* | install: use structured initializersLennart Poettering2018-11-281-3/+6
|/
* coccinelle: make use of SYNTHETIC_ERRNOZbigniew Jędrzejewski-Szmek2018-11-221-8/+7
| | | | | | | | | | | Ideally, coccinelle would strip unnecessary braces too. But I do not see any option in coccinelle for this, so instead, I edited the patch text using search&replace to remove the braces. Unfortunately this is not fully automatic, in particular it didn't deal well with if-else-if-else blocks and ifdefs, so there is an increased likelikehood be some bugs in such spots. I also removed part of the patch that coccinelle generated for udev, where we returns -1 for failure. This should be fixed independently.
* Move LONG_LINE_MAX definition to fileio.hZbigniew Jędrzejewski-Szmek2018-11-141-1/+0
| | | | | | | | | | | All users of the macro (except for one, in serialize.c), use the macro in connection with read_line(), so they must include fileio.h. Let's not play libc games and require multiple header file to be included for the most common use of a function. The removal of def.h includes is not exact. I mostly went over the commits that switch over to use read_line() and add def.h at the same time and reverted the addition of def.h in those files.
* strv: wrap strv_new() in a macro so that NULL sentinel is implicitLennart Poettering2018-10-311-1/+1
|
* install: pass encountered error number to log_syntax()Lennart Poettering2018-10-181-1/+1
|
* install: FOREACH_LINE excorcismLennart Poettering2018-10-181-2/+9
|
* shared/install: avoid overwriting 'r' counter with a partial resultZbigniew Jędrzejewski-Szmek2018-10-021-3/+3
| | | | | | | | | We want to store either the first error or the total number of changes in 'r'. Instead, we were overwriting this with the return value from install_info_traverse(). LGTM complained later in the loop that: > Comparison is always true because r >= 0.
* install: small refactor to combine two function calls into one functionRuixin Bao2018-08-271-31/+30
| | | | | Combine consecutive function calls of install_info_discover and install_info_may_process into one short helper function.
* install: allow instantiated units to be enabled via presetsRuixin Bao2018-08-271-19/+136
| | | | | | | | | | | | | | | This patch implements https://github.com/systemd/systemd/issues/9421. The .preset file now is able to take a rule in the format of:(e.g) enable foo@.service bar0 bar1 bar2 In the above example, when preset-all is called, all three instances of foo@bar0.service, foo@bar1.service and foo@bar2.service will be enabled. When preset is called on a single service(e.g: foo@bar1.service), only the mentioned one(foo@bar1.service) will be enabled. Tests are added for future regression.
* install: fix error handling in is_symlink_with_known_name()Yu Watanabe2018-06-251-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.
* tree-wide: unify how we define bit mak enumsLennart Poettering2018-06-121-3/+3
| | | | | | Let's always write "1 << 0", "1 << 1" and so on, except where we need more than 31 flag bits, where we write "UINT64(1) << 0", and so on to force 64bit values.
* Merge pull request #9147 from keszybz/runtime-enablementLennart Poettering2018-06-041-97/+78
|\ | | | | Runtime enablement
| * systemctl: when removing enablement or mask symlinks, cover both /run and /etcZbigniew Jędrzejewski-Szmek2018-06-011-87/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 'systemctl disable --runtime' would disable a unit, but only if it was enabled with '--runtime', and silently do nothing if the unit was enabled persistently. And similarly 'systemctl disable' would do nothing if the unit was enabled in /run. This just doesn't seem useful. This pathch changes enable/disable and mask/unmask to be asymmetrical. enable and mask create symlinks in /etc or /run, depending on whether --runtime was specified. disable and unmask remove symlinks from both locations. --runtime cannot be specified for the disable and unmask verbs. The advantage is that 'disable' now means that the unit is disabled, period. And similarly for 'unmask', all masks are removed. Similarly for preset and preset-all, they now cannot be called with --runtime, and are asymmetrical: when they enable a unit, symlinks are created in /etc. When they disable a unit, all symlinks are nuked. $ systemctl --root=/ enable bluetooth Created symlink /etc/systemd/system/dbus-org.bluez.service → /usr/lib/systemd/system/bluetooth.service. Created symlink /etc/systemd/system/bluetooth.target.wants/bluetooth.service → /usr/lib/systemd/system/bluetooth.service. $ systemctl --root=/ --runtime enable bluetooth Created symlink /run/systemd/system/dbus-org.bluez.service → /usr/lib/systemd/system/bluetooth.service. Created symlink /run/systemd/system/bluetooth.target.wants/bluetooth.service → /usr/lib/systemd/system/bluetooth.service. $ systemctl --root=/ disable bluetooth Removed /run/systemd/system/bluetooth.target.wants/bluetooth.service. Removed /run/systemd/system/dbus-org.bluez.service. Removed /etc/systemd/system/bluetooth.target.wants/bluetooth.service. Removed /etc/systemd/system/dbus-org.bluez.service. $ systemctl --root=/ disable --runtime bluetooth --runtime cannot be used with disable $ systemctl --root=/ mask --runtime bluetooth Created symlink /run/systemd/system/bluetooth.service → /dev/null. $ systemctl --root=/ mask bluetooth Created symlink /etc/systemd/system/bluetooth.service → /dev/null. $ systemctl --root=/ unmask bluetooth Removed /run/systemd/system/bluetooth.service. Removed /etc/systemd/system/bluetooth.service. $ systemctl --root=/ unmask --runtime bluetooth --runtime cannot be used with unmask $ systemctl --root=/ --runtime enable bluetooth Created symlink /run/systemd/system/dbus-org.bluez.service → /usr/lib/systemd/system/bluetooth.service. Created symlink /run/systemd/system/bluetooth.target.wants/bluetooth.service → /usr/lib/systemd/system/bluetooth.service. $ systemctl --root=/ enable bluetooth Created symlink /etc/systemd/system/dbus-org.bluez.service → /usr/lib/systemd/system/bluetooth.service. Created symlink /etc/systemd/system/bluetooth.target.wants/bluetooth.service → /usr/lib/systemd/system/bluetooth.service. $ systemctl --root=/ preset bluetooth Removed /run/systemd/system/bluetooth.target.wants/bluetooth.service. Removed /run/systemd/system/dbus-org.bluez.service. Removed /etc/systemd/system/bluetooth.target.wants/bluetooth.service. Removed /etc/systemd/system/dbus-org.bluez.service. $ systemctl --root=/ preset --runtime bluetooth --runtime cannot be used with preset $ systemctl preset-all --runtime --runtime cannot be used with preset-all
| * Fix reporting of enabled-runtime unitsZbigniew Jędrzejewski-Szmek2018-05-311-10/+3
| | | | | | | | | | | | | | We would always report them as "enabled", because path_is_config() includes /run, despite the name. Fixes #9122.
* | path-util: introduce path_simplify()Yu Watanabe2018-06-031-4/+4
|/ | | | | | | | The function is similar to path_kill_slashes() but also removes initial './', trailing '/.', and '/./' in the path. When the second argument of path_simplify() is false, then it behaves as the same as path_kill_slashes(). Hence, this also replaces path_kill_slashes() with path_simplify().
* install: export unit_file_lookup_state()Lennart Poettering2018-05-241-3/+1
|
* install: "user" and "global" scopes are equivalent for user presetsFranck Bui2018-05-231-5/+9
| | | | | | Otherwise querying the preset status of a unit to the user instance gives incorrect results since in this case the scope used by the manager is UNIT_FILE_USER.
* tree-wide: be more careful with the type of array sizesLennart Poettering2018-04-271-29/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we were a bit sloppy with the index and size types of arrays, we'd regularly use unsigned. While I don't think this ever resulted in real issues I think we should be more careful there and follow a stricter regime: unless there's a strong reason not to use size_t for array sizes and indexes, size_t it should be. Any allocations we do ultimately will use size_t anyway, and converting forth and back between unsigned and size_t will always be a source of problems. Note that on 32bit machines "unsigned" and "size_t" are equivalent, and on 64bit machines our arrays shouldn't grow that large anyway, and if they do we have a problem, however that kind of overly large allocation we have protections for usually, but for overflows we do not have that so much, hence let's add it. So yeah, it's a story of the current code being already "good enough", but I think some extra type hygiene is better. This patch tries to be comprehensive, but it probably isn't and I missed a few cases. But I guess we can cover that later as we notice it. Among smaller fixes, this changes: 1. strv_length()' return type becomes size_t 2. the unit file changes array size becomes size_t 3. DNS answer and query array sizes become size_t Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
* tree-wide: drop redundant _cleanup_ macros (#8810)Lennart Poettering2018-04-251-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | This drops a good number of type-specific _cleanup_ macros, and patches all users to just use the generic ones. In most recent code we abstained from defining type-specific macros, and this basically removes all those added already, with the exception of the really low-level ones. Having explicit macros for this is not too useful, as the expression without the extra macro is generally just 2ch wider. We should generally emphesize generic code, unless there are really good reasons for specific code, hence let's follow this in this case too. Note that _cleanup_free_ and similar really low-level, libc'ish, Linux API'ish macros continue to be defined, only the really high-level OO ones are dropped. From now on this should really be the rule: for really low-level stuff, such as memory allocation, fd handling and so one, go ahead and define explicit per-type macros, but for high-level, specific program code, just use the generic _cleanup_() macro directly, in order to keep things simple and as readable as possible for the uninitiated. Note that before this patch some of the APIs (notable libudev ones) were already used with the high-level macros at some places and with the generic _cleanup_ macro at others. With this patch we hence unify on the latter.
* 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.
* tree-wide: use TAKE_PTR() and TAKE_FD() macrosYu Watanabe2018-04-051-4/+2
|