summaryrefslogtreecommitdiff
path: root/src/shared/util.c
AgeCommit message (Collapse)Author
2014-12-19util: make sure rm_rf() can be called on symlinks (with the effect of ↵Lennart Poettering
deleting it)
2014-12-18Treat a trailing backslash as an errorZbigniew Jędrzejewski-Szmek
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
2014-12-18util: in make_stdio() use dup2() rather than dup3()Lennart Poettering
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.
2014-12-12nspawn: allow spawning ephemeral nspawn containers based on the root file ↵Lennart Poettering
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!
2014-12-12util: minor simplification for loop_write() and loop_read()Lennart Poettering
2014-12-12util: when using basename() for creating temporary files, verify the ↵Lennart Poettering
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.
2014-12-11shared: correct spacing near eol in code commentsTorstein Husebø
2014-12-09treewide: sanitize loop_writeZbigniew Jędrzejewski-Szmek
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.
2014-12-10core: unify how we iterate over inotify eventsLennart Poettering
Let's add some syntactic sugar for iterating through inotify events, and use it everywhere.
2014-12-09sd-bus: get rid of PID starttime conceptLennart Poettering
As kdbus no longer exports this, remove all traces from sd-bus too
2014-12-03util: don't shadow variableThomas Hindoe Paaboel Andersen
environ is already defined in unistd.h
2014-12-03machine-id-setup: add a machine_id_commit call to commit on disk a transient ↵Didier Roche
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.
2014-11-29delta: diff returns 1 when files differ, ignore thisZbigniew Jędrzejewski-Szmek
https://bugs.debian/org/771397
2014-11-28treewide: introduce UID_INVALID (and friends) as macro for (uid_t) -1Lennart Poettering
2014-11-28treewide: use log_*_errno whenever %m is in the format stringMichal Schmidt
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.
2014-11-28treewide: yet more log_*_errno + return simplificationsMichal Schmidt
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.
2014-11-28treewide: no need to negate errno for log_*_errno()Michal Schmidt
It corrrectly handles both positive and negative errno values.
2014-11-28treewide: auto-convert the simple cases to log_*_errno()Michal Schmidt
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().
2014-11-27kdbus: set kernel attach mask before creating the first busLennart Poettering
2014-11-27util: add function getting proc environJakub Filak
On the contrary of env, the added function returns all characters cescaped, because it improves reproducibility.
2014-11-25util: skip incomplete ucred information in getpeersec()Lennart Poettering
2014-11-21util: add functions getting proc cwd and rootJakub Filak
/proc/[pid]/cwd and /proc/[pid]/root are symliks to corresponding directories The added functions returns values of that symlinks.
2014-11-14busctl: add new "call" command to invoke methods on a serviceLennart Poettering
2014-11-10strv: rework strv_split_quoted() to use unquote_first_word()Lennart Poettering
This should make the unquoting scheme a bit less naive.
2014-11-07shared: add readlink_valueTom Gundersen
Reads the basename of the target of a symlink.
2014-11-07util: simplify normalize_env_assignment() a bitLennart Poettering
2014-11-07util: file_is_priv_sticky() is used internally in util.c only nowadays, make ↵Lennart Poettering
it static
2014-11-07util: rework /proc/cmdline parser to use unquote_first_word()Lennart Poettering
2014-11-07util: simplify proc_cmdline() to reuse get_process_cmdline()Lennart Poettering
Also, make all parsing of the kernel cmdline non-fatal.
2014-11-07util: make use of isempty() where appropriateLennart Poettering
2014-11-06condition: unify condition logic in one fileLennart Poettering
2014-11-05util: minor modernisationsLennart Poettering
2014-10-30util: unify how we see srand()Lennart Poettering
2014-10-30util: don't block on getrandom()Lennart Poettering
2014-10-29util: make use of the new getrandom() syscall if it is available when ↵Lennart Poettering
needing entropy Doesn't require an fd, and could be a bit faster, so let's make use of it, if it is available.
2014-10-27util: fix copy-paste error and actually set the new hostnameMichal Sekletar
Reported-by: sztanpet on irc
2014-10-27util: introduce sethostname_idempotentMichal Sekletar
Function queries system hostname and applies changes only when necessary. Also, migrate all client of sethostname to sethostname_idempotent while at it.
2014-10-23label: move is_dir() to util.cLennart Poettering
2014-10-09util: avoid double close of fdThomas Hindoe Paaboel Andersen
We could end with a double close if we close the fd loop and flush_fd fails. That would make us goto fail and there we close the fd once again. This patch sets the fd to the return value for safe_close: -1 A fd with negative value will be ignored by the next call to safe_close. CID#996223
2014-10-01shared: util - use nicer idiom to silence CoverityZbigniew Jędrzejewski-Szmek
Change the other spot too.
2014-09-30shared: util - use nicer idiom to silence CoverityTom Gundersen
Suggested by Zbigniew.
2014-09-29util: silence coverityTom Gundersen
Make it clear in the code that ignoring a failed safe_ato?() is intentional.
2014-09-16util: remove a unnecessary checkThomas Hindoe Paaboel Andersen
We only break out of the previous loop if fd >= 0 so there is no use in checking it again. Found by coverity. Fixes: CID#1237577
2014-09-15hashmap: introduce hash_ops to make struct Hashmap smallerMichal Schmidt
It is redundant to store 'hash' and 'compare' function pointers in struct Hashmap separately. The functions always comprise a pair. Store a single pointer to struct hash_ops instead. systemd keeps hundreds of hashmaps, so this saves a little bit of memory.
2014-09-03localed: remove free_and_copyZbigniew Jędrzejewski-Szmek
It was mostly a duplicate of free_and_strdup().
2014-08-27util: fix minimal race where we might miss SIGTERMs when forking off an agentLennart Poettering
Before forking, block all signals, and unblock them afterwards. This way the child will have them blocked, and we won't lose them.
2014-08-27util: make lookup_uid() globalDavid Herrmann
This is a useful helper, make it global. It will be required for libsystemd-terminal, at minimum.
2014-08-26util: make use of newly added reset_signal_mask() call wherever appropriateLennart Poettering
2014-08-26util: reset signals when we fork off agentsLennart Poettering
If we invoke agents, we should make sure we actually can kill them again. I mean, it's probably not our job to cleanup the signals if our tools are invoked in weird contexts, but at least we should make sure, that the subprocesses we invoke and intend to control work as intended. Also see: http://lists.freedesktop.org/archives/systemd-devel/2014-August/022460.html
2014-08-26util: make sure reset_all_signal_handlers() continues with all other signal ↵Lennart Poettering
handlers when one sigaction() fails After all, we usually don't check for failures here, and it is better to do as much as we can...