summaryrefslogtreecommitdiff
path: root/src/shared/generator.c
Commit message (Collapse)AuthorAgeFilesLines
...
* 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 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.
* generator: add helper function for writing unit filesZbigniew Jędrzejewski-Szmek2017-12-151-0/+34
| | | | | It doesn't save too much, but it's a common pattern so I think it's worth to factor this out.
* Add x-systemd.growfs option for fstabZbigniew Jędrzejewski-Szmek2017-11-301-0/+55
|
* Add x-systemd.makefs option for fstabZbigniew Jędrzejewski-Szmek2017-11-301-3/+153
| | | | | | | | | | I opted to completely generate a unit for both mount points and swaps. For swaps, it would be possible to use fixed template unit like systemd-mkswap@.service, because there's no information passed except the device name. For mount points, that's not possible because both the device name and file system type need to be passed. Nevertheless, I expect that options will need to passed to both mkfs and mkswap, in which case it'll be necessary to create units of both types anyway.
* generators: be more careful when writing unit settings that support ↵Lennart Poettering2017-11-291-4/+9
| | | | | | | | specifier expansion Let's always escape strings we receive from the user before writing them out to unit file settings that suppor specifier expansion, so that user strings are transported as-is.
* 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.
* generator: when we insert a '\n', actually place a proper newline, tooLennart Poettering2017-10-051-4/+10
|
* fstab-generator: ignore x-systemd.device-timeout for non-devices (#6368)NeilBrown2017-07-171-0/+4
| | | | | | | If you specify "x-systemd.device-timeout" for an NFS mount point, you get no warning and a meaningless device unit dependency created. Better to have a warning and no dependency.
* sysv-generator: use generator_add_symlink()Zbigniew Jędrzejewski-Szmek2017-07-131-1/+2
| | | | | | | | | | | | | | generator_add_symlink() is extended to ignore EEXIST. This should be fine for all existing callers. There's a small difference in behaviour when adding symlinks in sysv-generator: the message is more generic and does not include ", ignored". But creation of symlinks shouldn't ever fail except if things are very wrong, so in practice this shouldn't matter. Test needed updating: os.path.exists(os.readlink(link)) only works if the link is absolute (or if we are in the right directory). Let's just use os.path.exists(link), which properly tests that the symlink target exists.
* cryptsetup-generator: add a helper utility to create symlinksZbigniew Jędrzejewski-Szmek2017-07-101-0/+15
| | | | | | | | It seems that there's a common pattern among the various generators. Let's add a helper function for it and make use of it in cryptsetup-generator. This fixes a bunch of theoretical memleaks in error paths, since *to wasn't generally freed properly. Not thath it matters.
* Parse "timeout=0" as infinity in various generators (#6264)Zbigniew Jędrzejewski-Szmek2017-07-031-2/+3
| | | | | | | | | | | | This extends 2d79a0bbb9f651656384a0a86ed814e6306fb5dd to the kernel command line parsing. The parsing is changed a bit to only understand "0" as infinity. If units are specified, parse normally, e.g. "0s" is just 0. This makes it possible to provide a zero timeout if necessary. Simple test is added. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1462378.
* core/device: Use JobRunningTimeoutSec= for device unitsMichal Koutný2017-04-251-1/+1
| | | | | Device job timeouts should respect possible device job dependencies so we set JobRunningTimeoutSec= by default.
* fstab-generator: Apply _netdev option also to device unitsMichal Koutný2017-04-251-0/+39
| | | | | | | | | | | | | | | | | | | In case the device field of fstab record is an actual device (not an address) apply same dependencies to the device unit as to the mount unit, i.e. > After=network-online.target network.target > Wants=network-online.targe It makes sense to start the device expecting job only when network is actually ready (consider e.g. iSCSI devices) since it is device's implicit dependency. The eventual implementation should better obtain network flag from udev database and would also take into account device hierarchy (see [1]). This patch approximates that by taking the `_netdev` option as a hint from the user both about the filesystem and underlying device. (For local devices with network filesystems (e.g. ocfs2), this hint leads to unused dependencies.) [1] https://lists.freedesktop.org/archives/systemd-devel/2014-October/024718.html
* generator: order fsck service After= the deviceLennart Poettering2016-12-141-1/+1
| | | | Otherwise we might get started too early.
* Create initrd-root-device.target synchronization point (#3239)Daniel Drake2016-05-121-1/+15
| | | | | | | | | Add a synchronization point so that custom initramfs units can run after the root device becomes available, before it is fsck'd and mounted. This is useful for custom initramfs units that may modify the root disk partition table, where the root device is not known in advance (it's dynamically selected by the generators).
* 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.
* fstab-gen: don't convert device timeout into seconds when initializing ↵Franck Bui2015-12-111-3/+2
| | | | | | | | JobTimeoutSec There was no need for such conversion and it was actually wrong since any device timeout less than a second was converted into 0 which means waits forever.
* shared: include what we useThomas Hindoe Paaboel Andersen2015-12-061-1/+4
| | | | | The next step of a general cleanup of our includes. This one mostly adds missing includes but there are a few removals as well.
* Merge pull request #1869 from poettering/kill-overridableMichal Schmidt2015-11-131-1/+1
|\ | | | | Remove support for RequiresOverridable= and RequisiteOverridable=
| * core: remove support for RequiresOverridable= and RequisiteOverridable=Lennart Poettering2015-11-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As discussed at systemd.conf 2015 and on also raised on the ML: http://lists.freedesktop.org/archives/systemd-devel/2015-November/034880.html This removes the two XyzOverridable= unit dependencies, that were basically never used, and do not enhance user experience in any way. Most folks looking for the functionality this provides probably opt for the "ignore-dependencies" job mode, and that's probably a good idea. Hence, let's simplify systemd's dependency engine and remove these two dependency types (and their inverses). The unit file parser and the dbus property parser will now redirect the settings/properties to result in an equivalent non-overridable dependency. In the case of the unit file parser we generate a warning, to inform the user. The dbus properties for this unit type stay available on the unit objects, but they are now hidden from usual introspection and will always return the empty list when queried. This should provide enough compatibility for the few unit files that actually ever made use of this.
* | generator: order initrd fsck-root after local-fs-preMichael Marineau2015-11-121-1/+1
|/ | | | | | | | | | | | | The initrd version of systemd-fsck-root.service must wait for local-fs-pre.target just like systemd-fsck@.service to prevent modifications to the filesystem prior to resuming from hibernation. As-is my laptop routinely fails to resume due to fsck errors. The rest of the time it is probably silently corrupting the filesystem. Unlike normal boot, in the initrd systemd-fsck-root.service has no special significance so it needs to be kept in sync with systemd-fsck@.service. The name systemd-fsck-root.service is only used to preserve state across switch-root.
* util-lib: split out allocation calls into alloc-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: move mount related utility calls to mount-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: split out fd-related operations into fd-util.[ch]Lennart Poettering2015-10-251-1/+2
| | | | | There are more than enough to deserve their own .c file, hence move them over.
* util-lib: split our string related calls from util.[ch] into its own file ↵Lennart Poettering2015-10-241-0/+1
| | | | | | | | | | | | | | 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.
* util: split out escaping code into escape.[ch]Lennart Poettering2015-10-241-6/+7
| | | | This really deserves its own file, given how much code this is now.
* path-util: rework find_binary(), fsck_exists() and mkfs_exists()Lennart Poettering2015-10-241-8/+8
| | | | | | | | | | | | | | | | | | | | | Modernize the code a bit: - Get rid of FOREACH_WORD_SEPARATOR() loop in favour of a extract_first_word() loop. - Remove find_binary()'s "local" flag. It's not reasonably possible to look for binaries on remote systems, we hence should not pretend we could. - When we cannot find a suitable binary, return the last error returned from access() rather than ENOENT unconditionally. - Rework fsck_exists() and mkfs_exists() to return 1 on success, 0 if the implementation is missing and negative on real errors. This is more like we do it in other functions. - Make sure we also detect direct fsck symlinks to "true", rather than just absolute ones to /bin/true.
* fstab-generator: cescape device name in root-fsck serviceAndrei Borzenkov2015-06-031-2/+8
| | | | | | | We unescape ExecStart line when parsing it, so escape device name before adding it to unit file. fixes #50
* shared: generator - correct path to systemd-fsckMike Gilbert2015-05-241-1/+1
| | | | | | | In generated systemd-fsck-root.service. This would break if rootprefix is not /usr/lib/systemd. [tomegun: flesh out commit message]
* generator: use fflush_and_check() where appropriateLennart Poettering2015-05-151-3/+3
|
* Generate systemd-fsck-root.service in the initramfsZbigniew Jędrzejewski-Szmek2015-05-101-5/+60
| | | | | | | | | | | | | | In the initrafms, generate a systemd-fsck-root.service to replace systemd-fsck@<sysroot-device>.service. This way, after we transition to the real root, systemd-fsck-root.service is marked as already done. This introduces an unnecessary synchronization point, because systemd-fsck@* is ordered after systemd-fsck-root also in the initramfs. In practice this shouldn't be a problem. https://bugzilla.redhat.com/show_bug.cgi?id=1201979 C.f. 956eaf2b8d6c9999024705ddadc7393bc707de02.
* core: rework unit name validation and manipulation logicLennart Poettering2015-05-051-9/+9
| | | | | | | | | | | | | | | A variety of changes: - Make sure all our calls distuingish OOM from other errors if OOM is not the only error possible. - Be much stricter when parsing escaped paths, do not accept trailing or leading escaped slashes. - Change unit validation to take a bit mask for allowing plain names, instance names or template names or an combination thereof. - Refuse manipulating invalid unit name
* generators: rename add_{root,usr}_mount to add_{sysroot,sysroot_usr}_mountZbigniew Jędrzejewski-Szmek2015-05-041-9/+12
| | | | | | | | | | | | This makes it obvious that those functions are only usable in the initramfs. Also, add a warning when noauto, nofail, or automount is used for the root fs, instead of silently ignoring. Using those options would be a sign of significant misconfiguration, and if we bother to check for them, than let's go all the way and complain. Other various small cleanups and reformattings elsewhere.
* fstab-generator: don't accept missing root=, but accept root=noneTobias Hunger2015-03-251-5/+0
| | | | | | | | | | | | | | | | | | | | | | | And other non-device entries (like fstab does). Mount whatever the user asked to be mounted on / on the kernel command line. Do less sanity check and do *not* bail out when the mount device looks strange or does not exist. This basically makes the changes for deviceless filesystems from yesterday unnecessary and is in line with what we do for filesystems set up in fstab. Remove some code that is now dead (reverting fb02a2775a65 and b0438462). [tomegun: - change patch title/description a bit. - don't touch the /usr logic, that would be a separate change and we don't currently have a convincing use-case for that. - don't bail out on /sys ro. This only makes sense in containers, where we would not be doing this anyway. If there is a use-case we could consider that as a separate patch.]
* fstab-generator: Do not check deviceless filesystemsTobias Hunger2015-03-241-0/+5
| | | | There is no need to check those.
* remove unused includesThomas Hindoe Paaboel Andersen2015-02-231-1/+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.
* util: rework strappenda(), and rename it strjoina()Lennart Poettering2015-02-031-1/+1
| | | | | | After all it is now much more like strjoin() than strappend(). At the same time, add support for NULL sentinels, even if they are normally not necessary.
* Add new function to filter fstab optionsZbigniew Jędrzejewski-Szmek2015-01-111-33/+8
| | | | | | | | | | | | | | | | | | | | This fixes parsing of options in shared/generator.c. Existing code had some issues: - it would treate whitespace and semicolons as seperators. fstab(5) is pretty clear that only commas matter. And the syntax does not allow for spaces to be inserted in the field in fstab. Whitespace might be escaped, but then it should not seperate options. Treat whitespace and semicolons as any other character. - it assumed that x-systemd.device-timeout would always be followed by "=". But this is not guaranteed, hasmntopt will return this option even if there's no value. Uninitialized memory could be read. - some error paths would log, and inconsistently, some would just return an error code. Filtering is split out to a separate function and tests are added. Similar code paths in other places are adjusted to use the new function.
* treewide: another round of simplificationsMichal Schmidt2014-11-281-4/+2
| | | | | Using the same scripts as in f647962d64e "treewide: yet more log_*_errno + return simplifications".
* 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: yet more log_*_errno + return simplificationsMichal Schmidt2014-11-281-4/+2
| | | | | | | | | | | | | Using: find . -name '*.[ch]' | while read f; do perl -i.mmm -e \ 'local $/; local $_=<>; s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg; print;' $f done And a couple of manual whitespace fixups.
* 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().
* shared: fix format string for usec_t typeLennart Poettering2014-07-071-1/+1
|
* dropin: add format attribute and fix a wrong callerThomas Hindoe Paaboel Andersen2014-07-071-1/+1
|
* fstab-generator: add comma when removed option is in the middleZbigniew Jędrzejewski-Szmek2014-07-071-1/+1
| | | | | xxx,x-systemd.default-timeout=y,zzz was filtered to xxxzzz, but should be xxx,zzz, of course.
* cryptsetup: allow x-systemd.device-timeoutZbigniew Jędrzejewski-Szmek2014-06-301-3/+6
| | | | https://bugs.freedesktop.org/show_bug.cgi?id=54210
* fstab-generator: allow x-systemd.device-timeout for swap unitsZbigniew Jędrzejewski-Szmek2014-06-301-9/+15
|
* Move x-systemd-device.timeout handling from core to fstab-generatorZbigniew Jędrzejewski-Szmek2014-06-301-0/+57
| | | | | | | | | | | | | Instead of adjusting job timeouts in the core, let fstab-generator write out a dropin snippet with the appropriate JobTimeout. x-systemd-device.timeout option is removed from Options= line in the generated unit. The functions to write dropins are moved from core/unit.c to shared/dropin.c, to make them available outside of core. generator.c is moved to libsystemd-label, because it now uses functions defined in dropin.c, which are in libsystemd-label.