summaryrefslogtreecommitdiff
path: root/src/shared/util.c
Commit message (Collapse)AuthorAge
* import: introduce new mini-daemon systemd-importd, and make machinectl a ↵Lennart Poettering2015-01-22
| | | | | | | | | | | | | | client to it The old "systemd-import" binary is now an internal tool. We still use it as asynchronous backend for systemd-importd. Since the import tool might require some IO and CPU resources (due to qcow2 explosion, and decompression), and because we might want to run it with more minimal priviliges we still keep it around as the worker binary to execute as child process of importd. machinectl now has verbs for pulling down images, cancelling them and listing them.
* util: Add some missing hidden_file() suffixesMartin Pitt2015-01-21
| | | | | dpkg itself also uses *.dpkg-dist, while .dpkg-{bak,backup,remove} are being used by dpkg-maintscript-helper.
* import: add image verification using gpgLennart Poettering2015-01-21
| | | | | | This also adds an initial keyring for the verification, that contains Ubuntu's and Fedora's key. We should probably add more entries sooner or later.
* util: make http url validity checks more generic, and move them to util.cLennart Poettering2015-01-20
|
* import-raw: when downloading raw images, generate sparse files if we canLennart Poettering2015-01-19
|
* util: replace RUN_WITH_LOCALE with extended locale functionsCristian Rodríguez2015-01-18
| | | | | | There were two callers, one can use strtod_l() and the other strptime_l(). (David: fix up commit-msg and coding-style)
* nspawn: add file system locks for controlling access to container imagesLennart Poettering2015-01-14
| | | | | | | | | | | | | | | | | | | | | | | | | | This adds three kinds of file system locks for container images: a) a file system lock next to the actual image, in a .lck file in the same directory the image is located. This lock has the benefit of usually being located on the same NFS share as the image itself, and thus allows locking container images across NFS shares. b) a file system lock in /run, named after st_dev and st_ino of the root of the image. This lock has the advantage that it is unique even if the same image is bind mounted to two different places at the same time, as the ino/dev stays constant for them. c) a file system lock that is only taken when a new disk image is about to be created, that ensures that checking whether the name is already used across the search path, and actually placing the image is not interrupted by other code taking the name. a + b are read-write locks. When a container is booted in read-only mode a read lock is taken, otherwise a write lock. Lock b is always taken after a, to avoid ABBA problems. Lock c is mostly relevant when renaming or cloning images.
* machined: use the FS_IMMUTABLE_FL file flag, if available, to implement a ↵Lennart Poettering2015-01-14
| | | | "read-only" concept for raw disk images, too
* util: the chattr flags field is actually unsigned, judging by kernel sourcesLennart Poettering2015-01-14
| | | | Unlike some client code suggests...
* shared/util: respect buffer boundary on incomplete escape sequencesZbigniew Jędrzejewski-Szmek2015-01-11
| | | | | | | | | | cunescape_length_with_prefix() is called with the length as an argument, so it cannot rely on the buffer being NUL terminated. Move the length check before accessing the memory. When an incomplete escape sequence was given at the end of the buffer, c_l_w_p() would read past the end of the buffer. Fix this and add a test.
* Add new function to filter fstab optionsZbigniew Jędrzejewski-Szmek2015-01-11
| | | | | | | | | | | | | | | | | | | | 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.
* Implement masking and overriding of generatorsZbigniew Jędrzejewski-Szmek2015-01-11
| | | | | | | | | | | | | | | | | | | | | | Sometimes it is necessary to stop a generator from running. Either because of a bug, or for testing, or some other reason. The only way to do that would be to rename or chmod the generator binary, which is inconvenient and does not survive upgrades. Allow masking and overriding generators similarly to units and other configuration files. For the systemd instance, masking would be more common, rather than overriding generators. For the user instances, it may also be useful for users to have generators in $XDG_CONFIG_HOME to augment or override system-wide generators. Directories are searched according to the usual scheme (/usr/lib, /usr/local/lib, /run, /etc), and files with the same name in higher priority directories override files with the same name in lower priority directories. Empty files and links to /dev/null mask a given name. https://bugs.freedesktop.org/show_bug.cgi?id=87230
* Simplify execute_directory()Zbigniew Jędrzejewski-Szmek2015-01-11
| | | | | | | | | Remove the optional sepearate opening of the directory, it would be just too complicated with the change to multiple directories. Move the middle of execute_directory() to a seperate function to make it easier to grok.
* util: make it easy to initialize the crtime from the current time in ↵Lennart Poettering2015-01-08
| | | | fd_setcrtime()
* journald: turn off COW for journal files on btrfsLennart Poettering2015-01-08
| | | | | | | | | | | | | | btrfs' COW logic results in heavily fragment journal files, which is detrimental for perfomance. Hence, turn off COW for journal files as we create them. Turning off COW comes at the cost of data integrity guarantees, but this should be acceptable, given that we do our own checksumming, and generally have a pretty conservative write pattern. Also see discussion on linux-btrfs: http://www.spinics.net/lists/linux-btrfs/msg41001.html
* util: upgrade default $TERM from vt102 to vt220 if we have no idea about the ↵Lennart Poettering2015-01-07
| | | | | | | | | | | | | | | | | connected terminal So far, if we had no knowledge about the correct $TERM we defaulted to v102, as a safe, conservative choice. However, the terminfo data for vt102 is not aware of pageup/pagedown, which makes "less" much harder work with than necessary. Setting vt220 allows them to work correctly. "vt220" should be a sufficiently safe choice too, given that xterm, gnome-terminal and the linux console all strive to implement vt220 as baseline, already to pass pageup/pagedown correctly to apps. Effectively, with this change "journalctl -e" run inside a "systemd-nspawn" terminal will now run a pager where pageup/pagedown works, which is quite an improvement of usability for containers.
* util: make use of kcmp() to compare fds, if it is availableLennart Poettering2015-01-07
|
* util: don't fail recursive bind mounting if we cannot read the mount flags ↵Lennart Poettering2015-01-07
| | | | from an obstructed mounted
* core: add new logic for services to store file descriptors in PID 1Lennart Poettering2015-01-06
| | | | | | | | | | | | | | With this change it is possible to send file descriptors to PID 1, via sd_pid_notify_with_fds() which PID 1 will store individually for each service, and pass via the usual fd passing logic on next invocation. This is useful for enable daemon reload schemes where daemons serialize their state to /run, push their fds into PID 1 and terminate, restoring their state on next start from the data in /run and passed in from PID 1. The fds are kept by PID 1 as long as no POLLHUP or POLLERR is seen on them, and the service they belong to are either not dead or failed, or have a job queued.
* util: Do not clear parent mount flags when setting up namespacesTopi Miettinen2015-01-05
| | | | | | | | | When setting up a namespace, mount flags like noexec, nosuid and nodev are cleared, so the mounts always have exec, suid and dev flags enabled. Copy source directory mount flags to target mount when remounting the bind mounts.
* util: Fix signedness error in lines(), match implementationsColin Walters2015-01-05
| | | | | | | | | | Regression introduced by ed757c0cb03eef50e8d9aeb4682401c3e9486f0b Mirror the implementation of columns(), since the fd_columns() functions returns a negative integer for errors. Also fix columns() to return the unsigned variable instead of the signed intermediary (they're the same, but better to be explicit).
* util: treat -1 as special size in format_bytes()Lennart Poettering2014-12-28
|
* machinectl/machined: implement "rename", "clone", "read-only" verbs for ↵Lennart Poettering2014-12-28
| | | | machine images
* util: always override crtime xattrLennart Poettering2014-12-26
|
* machined: beef up machined image listing with creation/modification times of ↵Lennart Poettering2014-12-25
| | | | | | | subvolumes We make use of the btrfs subvol crtime for this, and for gpt images of a manually managed xattr, if we can.
* util: make creation time xattr logic more genericLennart Poettering2014-12-24
|
* util: fix strict aliasing violations in use of struct inotify_event v5Shawn Paul Landden2014-12-24
| | | | | There is alot of cleanup that will have to happen to turn on -fstrict-aliasing, but I think our code should be "correct" to the rule.
* machined: add new call OpenMachineLogin() that starts a getty in a container ↵Lennart Poettering2014-12-23
| | | | | | | on a pty and returns the pty master fd to the client This is a one-stop solution for "machinectl login", and should simplify getting logins in containers.
* util: add allocation loop to gettyname_malloc()Lennart Poettering2014-12-23
|
* systemd-run: support -t mode when combined with -MLennart Poettering2014-12-23
| | | | For that, ask machined for a container PTY and use that.
* machined: add new GetImage() bus call for retrieving the bus path for an imageLennart Poettering2014-12-19
|
* util: rename ignore_file() to hidden_file()Lennart Poettering2014-12-19
| | | | | hidden_file() is a bit more precise, since dot files usually shouldn't be ignored, but certainly be considered hidden.
* util: when creating temporary filename for atomic creation of files, add an ↵Lennart Poettering2014-12-19
| | | | | | | extra "#" to the name That way, we have a simple, somewhat reliable way to detect such temporary files, by simply checking if they start with ".#".
* util: make sure rm_rf() can be called on symlinks (with the effect of ↵Lennart Poettering2014-12-19
| | | | deleting it)
* Treat a trailing backslash as an errorZbigniew Jędrzejewski-Szmek2014-12-18
| | | | | | | | | | | | | | | | | | Commit a2a5291b3f5 changed the parser to reject unfinished quoted strings. Unfortunately it introduced an error where a trailing backslash would case an infinite loop. Of course this must fixed, but the question is what to to instead. Allowing trailing backslashes and treating them as normal characters would be one option, but this seems suboptimal. First, there would be inconsistency between handling of quoting and of backslashes. Second, a trailing backslash is most likely an error, at it seems better to point it out to the user than to try to continue. Updated rules: ExecStart=/bin/echo \\ → OK, prints a backslash ExecStart=/bin/echo \ → error ExecStart=/bin/echo "x → error ExecStart=/bin/echo "x"y → error
* util: in make_stdio() use dup2() rather than dup3()Lennart Poettering2014-12-18
| | | | | | | | | dup3() allows setting O_CLOEXEC which we are not interested in. However, it also fails if called with the same fd as input and output, which is something we don't want. Hence use dup2(). Also, we need to explicitly turn off O_CLOEXEC for the fds, in case the input fd was O_CLOEXEC and < 3.
* nspawn: allow spawning ephemeral nspawn containers based on the root file ↵Lennart Poettering2014-12-12
| | | | | | | | | | | | | | system of the OS This works now: # systemd-nspawn -xb -D / -M foobar Which boots up an ephemeral container, based on the host's root file system. Or in other words: you can now run the very same host OS you booted your system with also in a container, on top of it, without having it interfere. Great for testing whether the init system you are hacking on still boots without reboot the system!
* util: minor simplification for loop_write() and loop_read()Lennart Poettering2014-12-12
|
* util: when using basename() for creating temporary files, verify the ↵Lennart Poettering2014-12-12
| | | | | | | | resulting name is actually valid Also, rename filename_is_safe() to filename_is_valid(), since it actually does a full validation for what the kernel will accept as file name, it's not just a heuristic.
* shared: correct spacing near eol in code commentsTorstein Husebø2014-12-11
|
* treewide: sanitize loop_writeZbigniew Jędrzejewski-Szmek2014-12-09
| | | | | | | loop_write() didn't follow the usual systemd rules and returned status partially in errno and required extensive checks from callers. Some of the callers dealt with this properly, but many did not, treating partial writes as successful. Simplify things by conforming to usual rules.
* core: unify how we iterate over inotify eventsLennart Poettering2014-12-10
| | | | | Let's add some syntactic sugar for iterating through inotify events, and use it everywhere.
* sd-bus: get rid of PID starttime conceptLennart Poettering2014-12-09
| | | | As kdbus no longer exports this, remove all traces from sd-bus too
* util: don't shadow variableThomas Hindoe Paaboel Andersen2014-12-03
| | | | environ is already defined in unistd.h
* machine-id-setup: add a machine_id_commit call to commit on disk a transient ↵Didier Roche2014-12-03
| | | | | | | | | machine-id If /etc was read only at boot time with an empty /etc/machine-id, the latter will be mounted as a tmpfs and get reset at each boot. If the system becomes rw later, this functionality enables to commit in a race-free manner the transient machine-id to disk.
* delta: diff returns 1 when files differ, ignore thisZbigniew Jędrzejewski-Szmek2014-11-29
| | | | https://bugs.debian/org/771397
* treewide: introduce UID_INVALID (and friends) as macro for (uid_t) -1Lennart Poettering2014-11-28
|
* treewide: use log_*_errno whenever %m is in the format stringMichal Schmidt2014-11-28
| | | | | | | | | | | 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-28
| | | | | | | | | | | | | 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-28
| | | | It corrrectly handles both positive and negative errno values.