summaryrefslogtreecommitdiffstats
path: root/src/shared/install.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* 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-281-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-281-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
|
* install: don't enforce that .d/ dropin files (and their symlink chain ↵Lennart Poettering2018-03-291-40/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | elements) for units must have names that qualify as unit names The names of drop-in files can be anything as long as they are suffixed in ".conf", hence don't be stricter than necessary when validating the names used in symlink chains of such drop-in files. Also, drop-in files should not be ale to change the type of unit file itself, i.e. not affect whether it is considered masked or an alias as a whole. This adds a flag SEARCH_DROPIN that is passed whenever we load a drop-in rather the main unit file, and in that case loosen checks and behaviour we otherwise enforce for the unit file itself. Specifically: 1. If SEARCH_DROPIN is passed we won't change the unit's info->type field anymore, as that field (which can be REGULAR, MASKED, SYMLINK) should not be affected by drop-ins, but only by the unit file itself. 2. If SEARCH_DROPIN is passed we will shortcut following of symlink chains, and not validate the naming of each element in the chain, since that's irrelevant for drop-ins, and only matters for the unit file itself. Or in other words, without this: 1. A symlink /etc/systemd/system/foobar.service.d/20-quux.conf → /dev/null might have caused the whole of foobar.service to be considered "masked". 2. A symlink /etc/systemd/system/foobar.service.d/20-quux.conf → /tmp/miepf might have caused the whole loading of foobar.service to fail as EINVAL, as "miepf" is not a valid unit name.
* macro: introduce TAKE_PTR() macroLennart Poettering2018-03-221-6/+3
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* coccinelle: add reallocarray() coccinelle scriptLennart Poettering2018-03-021-1/+1
| | | | | Let's systematically make use of reallocarray() whereever we invoke realloc() with a product of two values.
* install: detect masked unit with drop-insFilipe Brandenburger2018-03-021-0/+3
| | | | | Before this fix, a unit with drop-ins will not be reported as masked by `systemctl is-enabled` or `systemctl list-unit-files`.
* stat-util: unify code that checks whether something is a regular fileLennart Poettering2018-02-201-10/+7
| | | | | | Let's add a common implementation for regular file checks, that are careful to return the right error code (EISDIR/EISLNK/EBADFD) when we are encountering a wrong file node.
* tree-wide: use path_hash_ops instead of string_hash_ops whenever we key by a ↵Lennart Poettering2018-02-121-1/+1
| | | | | | path Let's make use of our new hash_ops!
* install: search preset files in /run (#7715)John Lin2018-01-051-0/+2
| | | | | According to systemd.preset(5), presets files in /run should take effect. However, before this patch, preset files in /run were ignored.
* Add set/hashmap helpers for non-trivial freeing and use where straighforwardZbigniew Jędrzejewski-Szmek2017-11-281-20/+3
| | | | | | A macro is needed because otherwise we couldn't ensure type safety. Some simple tests are included. No functional change intended.
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* install: when we encounter a transient/generated unit while presetting all, ↵Lennart Poettering2017-11-171-0/+2
| | | | | | skip over it silently Fixes: #7100
* Merge pull request #7284 from poettering/cgroup-delegate-maskLennart Poettering2017-11-131-1/+1
|\ | | | | add a concept of delegating cgroups per unit while enabling specific controllers
| * conf-parser: turn three bool function params into a flags fieldsLennart Poettering2017-11-131-1/+1
| | | | | | | | | | This makes things more readable and fixes some issues with incorrect flag propagation between the various flavours of config_parse().
* | install: drop redundant printing of unit name (#7296)Lennart Poettering2017-11-131-2/+2
|/ | | | | | | We already print it as part of log_syntax() internal logic, don't print it again, and in particular, don't print it at the end of log line, such a strange place. Follow-up for: 142468d89508c63262dd59335ea6d4fe82267564
* systemctl: fix memory leak (#7289)John Lin2017-11-101-1/+1
| | | Fixes: #7283
* systemctl: respect [Install] section in drop-ins (#7158)John Lin2017-11-081-22/+80
| | | Fixes: #7114
* build-sys: use #if Y instead of #ifdef Y everywhereZbigniew Jędrzejewski-Szmek2017-10-041-2/+2
| | | | | | | | | | | | | | | The advantage is that is the name is mispellt, cpp will warn us. $ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/" $ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;' $ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g' $ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g' + manual changes to meson.build squash! build-sys: use #if Y instead of #ifdef Y everywhere v2: - fix incorrect setting of HAVE_LIBIDN2
* install: drop left-over debug message (#6913)Zbigniew Jędrzejewski-Szmek2017-09-251-1/+0
|
* install: consider globally enabled units as "enabled" for the userZbigniew Jędrzejewski-Szmek2017-09-221-2/+9
| | | | | | | | | | | We would not consider symlinks in /etc/systemd/user/*.{wants,requires}/ towards the user unit being "enabled", because the symlinks were not located in "config" paths. But this is confusing to users, since those units are clearly enabled and will be started. So let's muddle the definition of enablement a bit to include the paths only accessible to root when looking for enabled user units. Fixes #4432.
* install: consider non-Alias=/non-DefaultInstance= symlinks as "indirect" ↵Zbigniew Jędrzejewski-Szmek2017-09-221-5/+21
| | | | | | | | | | | | | | | | | enablement I think this matches the spirit of "indirect" well: the unit *might* be active, even though it is not "installed" in the sense of symlinks created based on the [Install] section. The changes to test-install-root touch the same lines as in the previous commit; the change in each case is from assert_se(unit_file_get_state(...) >= 0 && state == UNIT_FILE_ENABLED) to assert_se(unit_file_get_state(...) >= 0 && state == UNIT_FILE_DISABLED) to assert_se(unit_file_get_state(...) >= 0 && state == UNIT_FILE_INDIRECT) in the last two commits.
* install: only consider names in Alias= as "enabling"Zbigniew Jędrzejewski-Szmek2017-09-221-20/+57
| | | | | | | | | | | | | | | | | | | | | When a unit has a symlink that makes an alias in the filesystem, but that name is not specified in [Install], it is confusing is the unit is shown as "enabled". Look only for names specified in Alias=. Fixes #6338. v2: - Fix indentation. - Fix checking for normal enablement, when the symlink name is the same as the unit name. This case wasn't handled properly in v1. v3: - Rework the patch to also handle templates properly: A template templ@.service with DefaultInstance=foo will be considered enabled only when templ@foo.service symlink is found. Symlinks with other instance names do not count, which matches the logic for aliases to normal units. Tests are updated.
* install: move and rename to lowercase two functionsZbigniew Jędrzejewski-Szmek2017-09-211-2/+16
| | | | No reason to make them look like macros.
* exec-util,conf-files: skip non-executable files in execute_directories()Lennart Poettering2017-09-131-2/+2
| | | | Fixes: #6787
* basic/path-util: allow flags for path_equal_or_files_sameZbigniew Jędrzejewski-Szmek2017-06-171-1/+1
| | | | | No functional change, just a new parameters and the tests that AT_SYMLINK_NOFOLLOW works as expected.
* tree-wide: when %m is used in log_*, always specify errno explicitlyZbigniew Jędrzejewski-Szmek2017-05-191-1/+1
| | | | | | | | All those uses were correct, but I think it's better to be explicit. Using implicit errno is too error prone, and with this change we can require (in the sense of a style guideline) that the code is always specified. Helpful query: git grep -n -P 'log_[^s][a-z]+\(.*%m'
* install: never hit assert() when we can't figure out where to write ↵Lennart Poettering2017-02-101-0/+17
| | | | | | | | | | | | configuration symlinks Under specific circumstances it might happen that we can't figure out where to place our symlinks, for example because we are supposed to create them in the runtime directory but $XDG_RUNTIME_DIR is not set. In this case, return -ENXIO instead of hitting an assert(). (Yeah, the error isn't very descriptive, but for now this should at least be good enough to remove the assert() being hit.)
* install: when disabling units, do so even if the unit is missingLennart Poettering2017-02-101-15/+30
| | | | | | | | | | | | | | In some cases there might be unit symlinks in .wants/ or .requires/ directories even though the unit is otherwise fully removed. In this case, don't fail removal, but still remove the symlinks. This reworks the symlink marking logic to always add unit files that we are missing to the changes list, but proceed with any symlink removal for them. This way we'll still generate useful hints that a unit is missing if you invoke "systemctl disable idontexist.service", but also still remove any link to it. Fixes: #4995
* install: remove some unused parameters from various functions in install.cLennart Poettering2017-02-071-10/+4
| | | | No need to pass what we don't use.
* install: when a template unit is instantiated via a /usr symlink, consider ↵Lennart Poettering2017-02-071-35/+84
| | | | | | | | | | | | | | | it enabled If a unit foobar@.service stored below /usr is instantiated via a symlink foobar@quux.service also below /usr, then we should consider the instance statically enabled, while the template itself should continue to be considered enabled/disabled/static depending on its [Install] section. In order to implement this we'll now look for enablement symlinks in all unit search paths, not just in the config and runtime dirs. Fixes: #5136