summaryrefslogtreecommitdiff
path: root/src/shared
AgeCommit message (Collapse)Author
2014-09-17shared: conf-parserTom Gundersen
Check memory allocation. Found by Coverity. Fixes CID #1237644.
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-16shared: fix resource leak in config_parse_default_instanceAndreas Henriksson
The recently allocated "printed" is not freed on error path. Found by coverity. Fixes: CID#1237745
2014-09-16missing: memfd_create takes unsigned int flags in final versionCristian Rodríguez
2014-09-15hashmap: minor hashmap_replace optimizationMichal Schmidt
When hashmap_replace detects no such key exists yet, it calls hashmap_put that performs the same check again. Avoid that by splitting the core of hashmap_put into a separate function.
2014-09-15hashmap, set: remove unused functionsMichal Schmidt
The following hashmap_* and set_* functions/macros have never had any users in systemd's history: *_iterate_backwards *_iterate_skip *_last *_FOREACH_BACKWARDS Remove this dead code.
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-08exit-status: add new exit code for custom endpoint errorsDaniel Mack
2014-09-05exit-status: fix URL in commentDaniel Mack
The LSB sites have moved, so update the URL.
2014-09-03localed: remove free_and_copyZbigniew Jędrzejewski-Szmek
It was mostly a duplicate of free_and_strdup().
2014-09-03base-file-system: always generate error messages locallyLennart Poettering
Functions either should generate error messages for everything they do themselves, or for nothing and let the caller do it. But they certainly shouldn't generate errors for some messages but not for others. Since the function in this case is one that generates messages on its own, it really should do that for everything, not just for some things, hence.
2014-09-03base_filesystem_create: do not try to create "/root" if it existsHarald Hoyer
The check, if the directory/file already exists is only executed, if there is a symlink target specified. In case of "/root", there is none, so it is unconditionally tried to create the directory. In case of a readonly filesystem, errno != EEXIST, but errno == EROFS, so base_filesystem_create() and switch_root does not succeed. This patch checks for existance not only in the symlink case.
2014-08-31config-parser: fix mem leakThomas Hindoe Paaboel Andersen
2014-08-31missing: add IFF_MULTI_QUEUETom Gundersen
This was added in 3.8, but we should building with 3.7 headers. Reported by Samuli Suominen <ssuominen@gentoo.org>.
2014-08-30cgroup-util: shorten cg_path_get_sessionZbigniew Jędrzejewski-Szmek
2014-08-30Fix a few more typosRuben Kerkhof
2014-08-28use the switch_root function in shutdownHarald Hoyer
removes code duplication also move switch-root to shared
2014-08-28macro: use unique variable names for math-macrosDavid Herrmann
Similar to container_of(), we now use unique variable names for the bascic math macros MAX, MIN, CLAMP, LESS_BY. Furthermore, unit tests are added to verify they work as expected. For a rationale, see: commit fb835651aff79a1e7fc5795086c9b26e59a8e6ca Author: David Herrmann <dh.herrmann@gmail.com> Date: Fri Aug 22 14:41:37 2014 +0200 shared: make container_of() use unique variable names
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-27shared: make container_of() use unique variable namesDavid Herrmann
If you stack container_of() macros, you will get warnings due to shadowing variables of the parent context. To avoid this, use unique names for variables. Two new helpers are added: UNIQ: This evaluates to a truly unique value never returned by any evaluation of this macro. It's a shortcut for __COUNTER__. UNIQ_T: Takes two arguments and concatenates them. It is a shortcut for CONCATENATE, but meant to defined typed local variables. As you usually want to use variables that you just defined, you need to reference the same unique value at least two times. However, UNIQ returns a new value on each evaluation, therefore, you have to pass the unique values into the macro like this: #define my_macro(a, b) __max_macro(UNIQ, UNIQ, (a), (b)) #define __my_macro(uniqa, uniqb, a, b) ({ typeof(a) UNIQ_T(A, uniqa) = (a); typeof(b) UNIQ_T(B, uniqb) = (b); MY_UNSAFE_MACRO(UNIQ_T(A, uniqa), UNIQ_T(B, uniqb)); }) This way, MY_UNSAFE_MACRO() can safely evaluate it's arguments multiple times as they are local variables. But you can also stack invocations to the macro my_macro() without clashing names. This is the same as if you did: #define my_macro(a, b) __max_macro(__COUNTER__, __COUNTER__, (a), (b)) #define __my_macro(prefixa, prefixb, a, b) ({ typeof(a) CONCATENATE(A, prefixa) = (a); typeof(b) CONCATENATE(B, prefixb) = (b); MY_UNSAFE_MACRO(CONCATENATE(A, prefixa), CONCATENATE(B, prefixb)); }) ...but in my opinion, the first macro is easier to write and read. This patch starts by converting container_of() to use this new helper. Other macros may follow (like MIN, MAX, CLAMP, ...).
2014-08-27shared: drop UNIQUE()David Herrmann
The UNIQUE() macro works fine if used in un-stacked macros. However, once you stack them like: MAX(MIN(a, b), CLAMP(MAX(c, d), e, f)) you will get warnings due to shadowing other variables. gcc uses the last line of a macro expansion as value for __LINE__, therefore, we cannot even avoid this by splitting the expressions across lines. Remove the only user of UNIQUE() so we introduce a new helper in follow-ups.
2014-08-27systemctl: fix broken list-unit-files with --rootLukas Nykryn
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...
2014-08-26missing: add BPF_XORMichael Olbrich
BPF_XOR was introduced in kernel 3.7
2014-08-26Revert "systemctl: fix broken list-unit-files with --root"Lennart Poettering
This reverts commit 41a451cc2901a5deb985aea4cc8de204a22e5612. This breaks checks for masking of units file, since we invoke null_or_empty_path() on the resulting path.
2014-08-25systemctl: fix broken list-unit-files with --rootLukas Nykryn
This patch modifies unit_file_get_list which will now return hashmap of structures where f->path is *without* root_dir prefix. This change should be ok, because current code either does not use root_dir at all or calls basename() on the f->path.
2014-08-22core: add support for a configurable system-wide start-up timeoutLennart Poettering
When this system-wide start-up timeout is hit we execute one of the failure actions already implemented for services that fail. This should not only be useful on embedded devices, but also on laptops which have the power-button reachable when the lid is closed. This devices, when in a backpack might get powered on by accident due to the easily reachable power button. We want to make sure that the system turns itself off if it starts up due this after a while. When the system manages to fully start-up logind will suspend the machine by default if the lid is closed. However, in some cases we don't even get as far as logind, and the boot hangs much earlier, for example because we ask for a LUKS password that nobody ever enters. Yeah, this is a real-life problem on my Yoga 13, which has one of those easily accessible power buttons, even if the device is closed.
2014-08-22missing.h: add a cpp warning for __NR_memfd_create on MIPSDaniel Mack
2014-08-22missing.h: add fake __NR_memfd_create for MIPSDaniel Mack
We don't have the correct __NR_memfd_create syscall number yet, so set it to 0xffffffff for now to prevent compile time errors.
2014-08-22shared: add MAXSIZE() and use it in resolvedDavid Herrmann
The MAXSIZE() macro takes two types and returns the size of the larger one. It is much simpler to use than MAX(sizeof(A), sizeof(B)) and also avoids any compiler-extensions, unlike CONST_MAX() and MAX() (which are needed to avoid evaluating arguments more than once). This was suggested by Daniele Nicolodi <daniele@grinta.net>. Also make resolved use this macro instead of CONST_MAX(). This enhances readability quite a bit.
2014-08-21install: simplify usage of _cleanup_ macrosLennart Poettering
2014-08-21service,strv: introduce strv_find_startswith() and make use of itLennart Poettering
Unlike strv_find_prefix() the new call will return a pointer to the suffix of the item we found, instead of the whole item. This is more closer inline with what startswith() does, and allows us to simplify a couple of invocations.
2014-08-21util: make asynchronous_close() really work like an asynchronous version of ↵Lennart Poettering
safe_close() Save/restore errno, like we do in safe_close(). And don't fork a thread if the parameter is already negative.
2014-08-21util: simplify close_nointr() a bitLennart Poettering
2014-08-21util: change return value of startswith() to non-constLennart Poettering
This way we can use it on non-const strings, and don't end up with a const'ified result. This is similar to libc's strstr() which also takes a const string but returns a non-const one.
2014-08-20util: return after freeing all members of arrayLukas Nykryn
2014-08-20systemctl: fail in the case that no unit files were foundLukas Nykryn
Previously systemctl died with message -bash-4.2# systemctl --root /rawhi list-unit-files (src/systemctl/systemctl.c:868) Out of memory. in the case that no unit files were found in the --root or the directory did not exist. So lets return ENOENT in the case that --root does not exist and empty list in the case that there are no unit files.
2014-08-20indentation/spurious whitespace fixesLennart Poettering
2014-08-19memfd: escape the comm field we get from PR_GET_NAME, but assume everything ↵Lennart Poettering
else is proper UTF8
2014-08-19memfd: skip utf-8 escaping if we use a name that was passed inDaniel Mack
If a name was passed in as function argument, trust it, and don't do utf-8 encoding for them. Callers are obliged to check the names themselves, and escape them in case they use anything they got from the outside world.
2014-08-19memfd: reduce name escaping logic to utf-8 checksDaniel Mack
As memfds are now created by proper kernel API, and not by our functions, we can't rely on names being escaped/unescaped according to our current logic. Thus, the only safe way is to remove the escaping and when reading names, just escape names that are not properly encoded in UTF-8. Also, remove assert(name) lines from the memfd creation functions, as we explictly allow name to be NULL.
2014-08-19memfd: simplify APILennart Poettering
Now, that the memfd stuff is not exported anymore, we can simplify a few things: Use assert() instead of assert_return(), since this is used internally only, and we should be less permissive then. No need to pass an allocated fd back by call-by-reference, we can just directly return it.
2014-08-19Revert "socket: introduce SELinuxLabelViaNet option"Lennart Poettering
This reverts commit cf8bd44339b00330fdbc91041d6731ba8aba9fec. Needs more discussion on the mailing list.
2014-08-19tmpfiles: add new 'r' line type to add UIDs/GIDs to the pool to allocate ↵Lennart Poettering
UIDs/GIDs from This way we can guarantee a limited amount of compatibility with login.defs, by generate an appopriate "r" line out of it, on package installation.
2014-08-19socket: introduce SELinuxLabelViaNet optionMichal Sekletar
This makes possible to spawn service instances triggered by socket with MLS/MCS SELinux labels which are created based on information provided by connected peer. Implementation of label_get_child_label derived from xinetd. Reviewed-by: Paul Moore <pmoore@redhat.com>
2014-08-19util: remove unused FOREACH_WORD_SEPARATOR_QUOTEDLennart Poettering
2014-08-19sysusers: add another column to sysusers files for the home directoryLennart Poettering