summaryrefslogtreecommitdiffstats
path: root/src/shared/install.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* install: warn if WantedBy targets don't existJan Synacek2021-04-231-0/+1
| | | | | | | | | | Currently, if [Install] section contains WantedBy=target that doesn't exist, systemd creates the symlinks anyway. That is just user-unfriendly. Let's be nice and warn about installing non-existent targets. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1835351. Replaces: #15834
* install: include OS headers before our own definitionLennart Poettering2021-03-041-2/+2
| | | | | Doesn't matter much, but matches more our usual coding style where our definition are done after all headers provided by the OS are included.
* install: make UnitFileChangeType enum anonymousLennart Poettering2021-02-171-11/+11
| | | | | | | | | | We almost never use the named enum type, in almost all cases we use "int" instead, since we overload it with negative errnos. To simplify things, let's use "int" really everywhere. Moreover, let's rename the fields for this enum to "type_or_errno", to make the overloading clear. And let's ad some assertions that things are in the right range.
* shared: use -EINVAL for _UNIT_FILE_CHANGE_TYPE_INVALIDBenjamin Robin2021-02-161-1/+1
| | | | Follow-up of #11484
* tree-wide: use -EINVAL for enum invalid valuesZbigniew Jędrzejewski-Szmek2021-02-101-2/+2
| | | | | | | | | As suggested in https://github.com/systemd/systemd/pull/11484#issuecomment-775288617. This does not touch anything exposed in src/systemd. Changing the defines there would be a compatibility break. Note that tests are broken after this commit. They will be fixed in the next one.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* core: add [Enable|Disable]UnitFilesWithFlags DBUS methodsLuca Boccassi2020-09-041-3/+5
| | | | | | | | | | | | | | The new methods work as the unflavoured ones, but takes flags as a single uint64_t DBUS parameters instead of different booleans, so that it can be extended without breaking backward compatibility. Add new flag to allow adding/removing symlinks in [/etc|/run]/systemd/system.attached so that portable services configuration files can be self-contained in those directories, without affecting the system services directories. Use the new methods and flags from portablectl --enable. Useful in case /etc is read-only, with only the portable services directories being mounted read-write.
* install: fix wrong data typefangxiuning2020-07-101-1/+1
|
* shared/install: optionally cache the preset listZbigniew Jędrzejewski-Szmek2020-05-051-1/+10
| | | | | | | | | | When doing list-unit-files with --root, we would re-read the preset list for every unit. This uses a cache to only do it once. The time for list-unit-files goes down by about ~30%. unit_file_query_preset() is also called from src/core/. This patch does not touch that path, since the saving there are smaller, since preset status is only read on demand over dbus, and caching would be more complicated.
* shared/install: rework alias check and add testZbigniew Jędrzejewski-Szmek2020-01-101-1/+1
| | | | | | | | | | | | This mostly reuses existing checkers used by pid1, so handling of aliases should be consistent. Hopefully, with the test it'll be clearer what it happening. Support for .wants/.requires "aliases" is restored. Those are still used in the wild quite a bit, so we need to support them. See https://github.com/systemd/systemd/pull/13119 for a discussion of aliases with an instance that point to a different template: this is allowed.
* shared/install: split out alias verification functionZbigniew Jędrzejewski-Szmek2019-12-191-0/+2
| | | | No functional change.
* Create src/shared/unit-file.[ch] for unit-file related opsZbigniew Jędrzejewski-Szmek2019-07-191-30/+0
| | | | | 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: remove Lennart's copyright linesLennart Poettering2018-06-141-4/+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.
* install: export unit_file_lookup_state()Lennart Poettering2018-05-241-0/+6
|
* tree-wide: be more careful with the type of array sizesLennart Poettering2018-04-271-16/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* install: minor enum beautificationsLennart Poettering2018-04-121-4/+4
|
* 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.
* 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: move and rename to lowercase two functionsZbigniew Jędrzejewski-Szmek2017-09-211-14/+0
| | | | No reason to make them look like macros.
* shared, systemctl: teach is-enabled to show installation targetsJan Synacek2016-10-241-0/+1
| | | | | | | | | | | | | It may be desired by users to know what targets a particular service is installed into. Improve user friendliness by teaching the is-enabled command to show such information when used with --full. This patch makes use of the newly added UnitFileFlags and adds UNIT_FILE_DRY_RUN flag into it. Since the API had already been modified, it's now easy to add the new dry-run feature for other commands as well. As a next step, --dry-run could be added to systemctl, which in turn might pave the way for a long requested dry-run feature when running systemctl start.
* install: introduce UnitFileFlagsJan Synacek2016-10-241-17/+16
| | | | | Introduce a new enum to get rid of some boolean arguments of unit_file_* functions. It unifies the code, makes it a bit cleaner and extensible.
* shared/install: in install_context_mark_for_removal ignore not found unitsZbigniew Jędrzejewski-Szmek2016-10-191-2/+2
| | | | | | | | | | | | | | | | | | | | | With the following test case: [Install] WantedBy= default.target Also=foobar-unknown.service disabling would fail with: $ ./systemctl --root=/ disable testing.service Cannot find unit foobar-unknown.service. # this is level debug Failed to disable: No such file or directory. # this is the error After the change we proceed: $ ./systemctl --root=/ disable testing.service Cannot find unit foobar-unknown.service. Removed /etc/systemd/system/default.target.wants/testing.service. This does not affect specifying a missing unit directly: $ ./systemctl --root=/ disable nosuch.service Failed to disable: No such file or directory.
* shared/install: handle dangling aliases as an explicit case, report nicelyZbigniew Jędrzejewski-Szmek2016-05-091-0/+1
| | | | | | | | | 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.
* Move no_instances information to shared/Zbigniew Jędrzejewski-Szmek2016-05-021-0/+1
| | | | This way it can be used in install.c in subsequent commit.
* Move no_alias information to shared/Zbigniew Jędrzejewski-Szmek2016-05-021-0/+2
| | | | This way it can be used in install.c in subsequent commit.
* core: Filter by unit name behind the D-Bus, instead on the client side (#3142)kayrus2016-04-291-1/+1
| | | | This commit improves systemd performance on the systems which have thousands of units.
* shared/install: change value of _UNIT_FILE_CHANGE_TYPE_INVALIDZbigniew Jędrzejewski-Szmek2016-04-191-1/+2
| | | | | | -1 could be confused with -EPERM. But we still need a negative enum value to force gcc to use int for the enum type, even though it is unused. Otherwise we get warnings.
* shared/install,systemctl,core: report offending file on installation errorZbigniew Jędrzejewski-Szmek2016-04-191-1/+6
| | | | | | | | | | | | | | | | | | | | | 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.
* shared/install: add helper function unit_file_changes_have_modification()Zbigniew Jędrzejewski-Szmek2016-04-191-4/+8
| | | | As suggested in review of #3049.
* Various formatting and style fixesZbigniew Jędrzejewski-Szmek2016-04-191-12/+90
|
* systemctl/core: ignore masked units in preset-allZbigniew Jędrzejewski-Szmek2016-04-171-0/+5
| | | | | | | | | | | | | | | 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.
* core,systemctl: add new "systemctl revert" commandLennart Poettering2016-04-121-1/+2
| | | | | | 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.
* nstall: no need to export unit_file_lookup_state() anymoreLennart Poettering2016-04-121-1/+0
| | | | We only use it inside of install.c, hence let's make it static.
* systemctl: move check whether a service exists as native unit file to install.cLennart Poettering2016-04-121-0/+1
| | | | | | 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.
* install: introduce a new unit file state "transient"Lennart Poettering2016-04-121-0/+1
| | | | | | 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.
* install: add root directory to LookupPaths structureLennart Poettering2016-04-121-1/+1
| | | | | | | | | 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
* core: add a new unit file state "generated"Lennart Poettering2016-04-121-0/+1
| | | | | | | | 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
* 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.
* shared: include what we useThomas Hindoe Paaboel Andersen2015-12-061-0/+3
| | | | | The next step of a general cleanup of our includes. This one mostly adds missing includes but there are a few removals as well.
* core: simplify handling of %u, %U, %s and %h unit file specifiersLennart Poettering2015-11-121-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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").
* install: follow unit file symlinks in /usr, but not /etc when looking for ↵Lennart Poettering2015-11-121-6/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [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
* install: various simplificationsLennart Poettering2015-11-121-9/+2
|
* systemctl: introduce --now for enable, disable and maskJan Synacek2015-05-151-0/+1
| | | | https://bugs.freedesktop.org/show_bug.cgi?id=42940
* install: when exporting prefix InstallInfo to become UnitFileInstallInfoLennart Poettering2015-05-111-14/+22
| | | | | | | All other types exported from install.h should be namespaces like this, hence namespace InstallInfo the same way. Also, remove external forward definition of UnitFileScope type.
* sysv-generator: initialize LookupPaths just onceZbigniew Jędrzejewski-Szmek2015-03-151-1/+10
| | | | | | | | With debugging on, sysv-generator would print the full set of lookup paths for *every* sysv script. While at it, pass LookupPaths as a pointer in sysv-generator, and constify it everywhere.
* shared/install: when unit contains only Also=, report 'indirect'Jan Synacek2014-11-101-0/+2
| | | | | | | If a unit contains only Also=, with no Alias= or WantedBy=, it shouldn't be reported as static. New 'indirect' status shall be introduced. https://bugzilla.redhat.com/show_bug.cgi?id=864298
* systemctl: add add-wants and add-requires verbsLukas Nykryn2014-10-081-0/+2
|