summaryrefslogtreecommitdiff
path: root/src/core/load-dropin.c
Commit message (Collapse)AuthorAgeFilesLines
* unit-file: support UpheldBy= in [Install] settings (adding Upholds= depsMike Yuan2023-05-151-1/+5
| | | | | | from .upholds/) Closes #26896
* strv: make iterator in STRV_FOREACH() declaread in the loopYu Watanabe2022-03-191-2/+0
| | | | This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
* conf-parse: make config_parse_many() optionally save 'struct stat' for each fileYu Watanabe2021-10-271-8/+10
| | | | Fixes #21113.
* core: fix mtime calculation of dropin filesZbigniew Jędrzejewski-Szmek2021-03-041-0/+1
| | | | | | | | | | | | | | | | | Nominally, the bug was in unit_load_dropin(), which just took the last mtime instead of calculating the maximum. But instead of adding code to wrap the loop, this patch goes in the other direction. All (correct) callers of config_parse() followed a very similar pattern to calculate the maximum mtime. So let's simplify things by making config_parse() assume that mtime is initialized and update it to the maximum. This makes all the callers that care about mtime simpler and also fixes the issue in unit_load_dropin(). config_parse_many_nulstr() and config_parse_many() are different, because it makes sense to call them just once, and current ret_mtime behaviour make sense. Fixes #17730, https://bugzilla.redhat.com/show_bug.cgi?id=1933137.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* Merge pull request #15940 from keszybz/names-set-optimizationLennart Poettering2020-06-101-3/+2
|\ | | | | Try to optimize away Unit.names set
| * core: store unit aliases in a separate setZbigniew Jędrzejewski-Szmek2020-06-101-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We allocated the names set for each unit, but in the majority of cases, we'd put only one name in the set: $ systemctl show --value -p Names '*'|grep .|grep -v ' '|wc -l 564 $ systemctl show --value -p Names '*'|grep .|grep ' '|wc -l 16 So let's add a separate .id field, and only store aliases in the set, and only create the set if there's at least one alias. This requires a bit of gymnastics in the code, but I think this optimization is worth the trouble, because we save one object for many loaded units. In particular set_complete_move() wasn't very useful because the target unit would always have at least one name defined, i.e. the optimization to move the whole set over would never fire.
* | conf-parser: return mtime in config_parse() and friendsLennart Poettering2020-06-021-6/+7
|/ | | | | | | | | | | | | This is a follow-up for 9f83091e3cceb646a66fa9df89de6d9a77c21d86. Instead of reading the mtime off the configuration files after reading, let's do so before reading, but with the fd we read the data from. This is not only cleaner (as it allows us to save one stat()), but also has the benefit that we'll detect changes that happen while we read the files. This also reworks unit file drop-ins to use the common code for determining drop-in mtime, instead of reading system clock for that.
* core,install: allow one more case of "instance propagation"Zbigniew Jędrzejewski-Szmek2020-01-101-1/+1
| | | | | | | | | | | | If we have a template unit template@.service, it should be allowed to specify a dependency on a unit without an instance, bar@.service. When the unit is created, the instance will be propagated into the target, so template@inst.service will depend on bar@inst.service. This commit changes unit_dependency_name_compatible(), which makes the manager accept links like that, and unit_file_verify_alias(), so that the installation function will agree to create a symlink like that, and finally the tests are adjusted to pass.
* shared/unit-file: expose function to check .wants/.requires symlink validityZbigniew Jędrzejewski-Szmek2020-01-101-20/+3
| | | | No functional change.
* pid1: drop now-unused path parameter to add_dependency_by_name()Zbigniew Jędrzejewski-Szmek2018-09-151-1/+1
|
* systemd: do not pass .wants fragment path to manager_load_unitZbigniew Jędrzejewski-Szmek2018-09-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When loading units, sometimes we'd first encounter a unit from .wants or .requires directory. A typical case would be when multi-user.target.wants/ contains a symlink to some unit. We would prepare to load this unit using /etc/systemd/system/multi-user.target.wants/foo.service as the fragment path. This is always wrong. Instead, let's use NULL as the path and let manager_load_unit() figure out the path on its own. Fixes #9921. path=0x5625ed9b01a0 "/usr/lib/systemd/system/local-fs.target.wants/systemd-remount-fs.service", e=0x0, _ret=0x7ffe64645000) at ../src/core/manager.c:1887 name=0x5625ed9b01ce "systemd-remount-fs.service", path=0x5625ed9b01a0 "/usr/lib/systemd/system/local-fs.target.wants/systemd-remount-fs.service", e=0x0, _ret=0x7ffe64645000) at ../src/core/manager.c:1961 name=0x5625ed9b01ce "systemd-remount-fs.service", path=0x5625ed9b01a0 "/usr/lib/systemd/system/local-fs.target.wants/systemd-remount-fs.service", add_reference=true, mask=UNIT_DEPENDENCY_FILE) at ../src/core/unit.c:2946 dir_suffix=0x5625ebb179ed ".wants") at ../src/core/load-dropin.c:95 path=0x0, e=0x0, _ret=0x7ffe646452c0) at ../src/core/manager.c:1965 name=0x5625ebb186f8 "local-fs.target", path=0x0, add_reference=true, mask=UNIT_DEPENDENCY_MOUNTINFO_IMPLICIT) at ../src/core/unit.c:2946 where=0x5625ed9b3cc0 "/tmp", options=0x5625ed947110 "rw,nosuid,nodev,seclabel", fstype=0x5625ed95be90 "tmpfs", flags=0x7ffe64645395) at ../src/core/mount.c:1439 where=0x5625ed9b3cc0 "/tmp", options=0x5625ed947110 "rw,nosuid,nodev,seclabel", fstype=0x5625ed95be90 "tmpfs", set_flags=false) at ../src/core/mount.c:1567 at ../src/core/mount.c:1635 ret_retval=0x7ffe64645660, ret_shutdown_verb=0x7ffe646456c0, ret_fds=0x7ffe646456d8, ret_switch_root_dir=0x7ffe646456b0, ret_switch_root_init=0x7ffe646456b8, ret_error_message=0x7ffe646456c8) at ../src/core/main.c:1669
* 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: drop spurious newlines (#8764)Lennart Poettering2018-04-191-1/+0
| | | | | | | | Double newlines (i.e. one empty lines) are great to structure code. But let's avoid triple newlines (i.e. two empty lines), quadruple newlines, quintuple newlines, …, that's just spurious whitespace. It's an easy way to drop 121 lines of code, and keeps the coding style of our sources a bit tigther.
* core: minor coding style changesLennart Poettering2018-04-131-1/+1
|
* load-dropin: rename variableLennart Poettering2018-04-131-12/+7
| | | | | We are converting the unit name into its template, hence name the variable that way, instead of the misleading 'prefix'.
* 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/+3
|
* 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.
* core: downgrade a log message from error to warningLennart Poettering2017-11-131-2/+2
| | | | | Messages that do not indicate a failing operation, but where we continue operation should be at LOG_WARN, not at LOG_ERR.
* conf-parser: turn three bool function params into a flags fieldsLennart Poettering2017-11-131-6/+5
| | | | | This makes things more readable and fixes some issues with incorrect flag propagation between the various flavours of config_parse().
* core: track why unit dependencies came to beLennart Poettering2017-11-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This replaces the dependencies Set* objects by Hashmap* objects, where the key is the depending Unit, and the value is a bitmask encoding why the specific dependency was created. The bitmask contains a number of different, defined bits, that indicate why dependencies exist, for example whether they are created due to explicitly configured deps in files, by udev rules or implicitly. Note that memory usage is not increased by this change, even though we store more information, as we manage to encode the bit mask inside the value pointer each Hashmap entry contains. Why this all? When we know how a dependency came to be, we can update dependencies correctly when a configuration source changes but others are left unaltered. Specifically: 1. We can fix UDEV_WANTS dependency generation: so far we kept adding dependencies configured that way, but if a device lost such a dependency we couldn't them again as there was no scheme for removing of dependencies in place. 2. We can implement "pin-pointed" reload of unit files. If we know what dependencies were created as result of configuration in a unit file, then we know what to flush out when we want to reload it. 3. It's useful for debugging: "systemd-analyze dump" now shows this information, helping substantially with understanding how systemd's dependency tree came to be the way it came to be.
* load-dropin: propagate errors properly from unit_name_compatible() (#6002)Lennart Poettering2017-05-221-7/+12
| | | | | | Let's log about this in the caller. Doesn't really matter, but let's do something about my OCD, and propagate errors properly, so that the caller can log about them.
* core/load-droping: avoid oom warning when the unit symlink is not a templateZbigniew Jędrzejewski-Szmek2017-05-201-3/+5
| | | | | | | | | unit_name_template returns -EINVAL if the unit name is not a template, but the code assumed that OOM is the only failure mode. Fix that to emit the warning if a non-template unit is encountered (because in this case we expect the name to match exactly), and just skip the warning on other errors (presumably oom). Fixes #5543.
* core/load-dropin: add more sanity checks on .wants/.requires symlinksZbigniew Jędrzejewski-Szmek2017-02-071-1/+41
| | | | | Feb 04 22:35:42 systemd[1462]: foo.service: Wants dependency dropin /home/zbyszek/.config/systemd/user/foo.service.wants/diffname.service target ../barbar.service has different name Feb 04 22:35:42 systemd[1462]: foo.service: Wants dependency dropin /home/zbyszek/.config/systemd/user/foo.service.wants/wrongname is not a valid unit name, ignoring
* core: implement masking of .wants/.requires symlinksZbigniew Jędrzejewski-Szmek2017-02-071-0/+7
| | | | | | | | | Fixes #1169. Fixes #4830. Example log errors: Feb 04 22:13:28 systemd[1462]: foo.service: Wants dependency on empty_file.service is masked by /home/zbyszek/.config/systemd/user/foo.service.wants/empty_file.service, ignoring Feb 04 22:13:28 systemd[1462]: foo.service: Wants dependency on masked.service is masked by /home/zbyszek/.config/systemd/user/foo.service.wants/masked.service, ignoring
* core: when loading .wants and .requires, follow the same logic as .d conf ↵Zbigniew Jędrzejewski-Szmek2017-02-071-25/+46
| | | | | | | | | | | | | | | dropins Essentially, instead of sequentially adding deps based on all symlinks encountered in .wants and .requires dirs for each name and each unit file load path, iteratate over the load paths and unit names gathering symlinks, then order them based on priority, and then iterate over the final list, adding dependencies. This patch doesn't change the logic too much, except that the order in which dependencies are applied might be different. It wasn't defined before, so that not really a change. Adding filtering on the symlinks is left for later patches.
* systemctl: also use chase_symlinks for dropinsZbigniew Jędrzejewski-Szmek2017-02-021-2/+4
| | | | | | | | | | | | The general rule is: - code in shared/ should take an "original_root" argument (possibly NULL) and pass it along down to chase_symlinks - code in core/ should always use specify original_root==NULL, since we don't support running the manager from non-root directory - code in systemctl and other tools should pass arg_root. For any code that is called from tools which support --root, chase_symlinks must be used to look up paths.
* core: don't drop transient drop-ins when loading the restLennart Poettering2016-04-121-2/+11
| | | | | | | | Previously, when creating a transient unit, we'd first add the transient drop-ins to the unit, and then normally load any other drop-ins later on top of this, replacing the already loaded drop-ins. Let's not do this, after all the transient drop-ins area already in effect, let's just add what we find on disk, but not replace it.
* core: rework generator dir logic, move the dirs into LookupPaths structureLennart Poettering2016-04-121-1/+1
| | | | | | | | | | 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.
* tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* core: fix memory leak in transient unitsEvgeny Vereshchagin2016-01-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes: ==1== HEAP SUMMARY: ==1== in use at exit: 67,182 bytes in 91 blocks ==1== total heap usage: 70,485 allocs, 70,394 frees, 42,184,635 bytes allocated ==1== ==1== 5,742 (696 direct, 5,046 indirect) bytes in 29 blocks are definitely lost in loss record 4 of 7 ==1== at 0x4C2DD9F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==1== by 0x21ADDD: realloc_multiply (alloc-util.h:67) ==1== by 0x21BFB0: strv_push (strv.c:448) ==1== by 0x21C245: strv_consume (strv.c:520) ==1== by 0x21C33C: strv_extend (strv.c:559) ==1== by 0x278AD7: unit_write_drop_in (unit.c:3352) ==1== by 0x278EEB: unit_write_drop_in_private (unit.c:3403) ==1== by 0x190C21: bus_service_set_transient_property (dbus-service.c:254) ==1== by 0x190DBC: bus_service_set_property (dbus-service.c:284) ==1== by 0x18F00E: bus_unit_set_properties (dbus-unit.c:1226) ==1== by 0x186F6A: transient_unit_from_message (dbus-manager.c:683) ==1== by 0x1872B7: method_start_transient_unit (dbus-manager.c:763) ==1== ==1== LEAK SUMMARY: ==1== definitely lost: 696 bytes in 29 blocks ==1== indirectly lost: 5,046 bytes in 58 blocks ==1== possibly lost: 0 bytes in 0 blocks ==1== still reachable: 61,440 bytes in 4 blocks ==1== suppressed: 0 bytes in 0 blocks
* tree-wide: sort includesThomas Hindoe Paaboel Andersen2015-11-161-3/+3
| | | | Sort the includes accoding to the new coding style.
* remove unused includesThomas Hindoe Paaboel Andersen2015-02-231-3/+0
| | | | | | This patch removes includes that are not used. The removals were found with include-what-you-use which checks if any of the symbols from a header is in use.
* Move dropin listing to sharedZbigniew Jędrzejewski-Szmek2014-12-161-123/+15
| | | | | No functional change. This is in preparation for using this in systemctl in the future.
* treewide: use log_*_errno whenever %m is in the format stringMichal Schmidt2014-11-281-1/+1
| | | | | | | | | | | If the format string contains %m, clearly errno must have a meaningful value, so we might as well use log_*_errno to have ERRNO= logged. Using: find . -name '*.[ch]' | xargs sed -r -i -e \ 's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/' Plus some whitespace, linewrap, and indent adjustments.
* treewide: more log_*_errno + return simplificationsMichal Schmidt2014-11-281-6/+2
|
* treewide: more log_*_errno() conversionsMichal Schmidt2014-11-281-1/+1
|
* treewide: no need to negate errno for log_*_errno()Michal Schmidt2014-11-281-2/+2
| | | | It corrrectly handles both positive and negative errno values.
* treewide: auto-convert the simple cases to log_*_errno()Michal Schmidt2014-11-281-2/+2
| | | | | | | | | | | | | As a followup to 086891e5c1 "log: add an "error" parameter to all low-level logging calls and intrdouce log_error_errno() as log calls that take error numbers", use sed to convert the simple cases to use the new macros: find . -name '*.[ch]' | xargs sed -r -i -e \ 's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/' Multi-line log_*() invocations are not covered. And we also should add log_unit_*_errno().
* core: do not add dependencies to selfZbigniew Jędrzejewski-Szmek2014-08-071-1/+1
| | | | | | | Adds a pair of files which cause a segfault (also with systemd-analyze verify). https://bugzilla.redhat.com/show_bug.cgi?id=1124843
* Let config_parse open file where applicableZbigniew Jędrzejewski-Szmek2014-07-161-2/+3
| | | | | | | | Special care is needed so that we get an error message if the file failed to parse, but not when it is missing. To avoid duplicating the same error check in every caller, add an additional 'warn' boolean to tell config_parse whether a message should be issued. This makes things both shorter and more robust wrt. to error reporting.
* Constify ConfigTableItem tablesZbigniew Jędrzejewski-Szmek2014-07-151-1/+1
|
* core: remove unused varsLennart Poettering2014-05-221-2/+0
|
* core: never consider failure when reading drop-ins fatalLennart Poettering2014-05-221-29/+13
| | | | | drop-ins don't carry the main configuration of a unit, hence read them if we can't, complain if we cannot, but don't fail.
* conf-parser: warn when we open configuration files with weird access bitsLennart Poettering2014-02-031-23/+13
|
* core: replace readdir_r with readdirFlorian Weimer2013-12-211-3/+4
|
* id128: when taking user input for a 128bit ID, validate syntaxLennart Poettering2013-04-301-14/+26
| | | | Also, always accept both our simple hexdump syntax and UUID syntax.
* conf-parser: restrict .include usageLennart Poettering2013-04-251-1/+1
| | | | | Disallow recursive .include, and make it unavailable in anything but unit files.