Commit graph

1288 commits

Author SHA1 Message Date
Tom Gundersen 83e341a637 shared: conf-parser
Check memory allocation. Found by Coverity.

Fixes CID #1237644.
2014-09-17 22:19:53 +02:00
Thomas Hindoe Paaboel Andersen 42646a8bf2 util: remove a unnecessary check
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-16 23:03:50 +02:00
Andreas Henriksson d9ab174bd7 shared: fix resource leak in config_parse_default_instance
The recently allocated "printed" is not freed on error path.

Found by coverity. Fixes: CID#1237745
2014-09-16 21:49:56 +02:00
Cristian Rodríguez 06b7f7bd7f missing: memfd_create takes unsigned int flags in final version 2014-09-16 21:46:14 +02:00
Michal Schmidt 923041cb0a hashmap: minor hashmap_replace optimization
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-15 16:08:50 +02:00
Michal Schmidt 631b9deefb hashmap, set: remove unused functions
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-15 16:08:50 +02:00
Michal Schmidt d5099efc47 hashmap: introduce hash_ops to make struct Hashmap smaller
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-15 16:08:50 +02:00
Daniel Mack 060e088e94 exit-status: add new exit code for custom endpoint errors 2014-09-08 14:12:56 +02:00
Daniel Mack 5b89f67f03 exit-status: fix URL in comment
The LSB sites have moved, so update the URL.
2014-09-05 13:48:05 +02:00
Zbigniew Jędrzejewski-Szmek af76d302c1 localed: remove free_and_copy
It was mostly a duplicate of free_and_strdup().
2014-09-03 22:53:23 -04:00
Lennart Poettering 6dc2852c64 base-file-system: always generate error messages locally
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-03 19:00:24 +02:00
Harald Hoyer 6f4f8056d3 base_filesystem_create: do not try to create "/root" if it exists
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-09-03 13:26:27 +02:00
Thomas Hindoe Paaboel Andersen 9e60277835 config-parser: fix mem leak 2014-08-31 23:25:34 +02:00
Tom Gundersen 04d180c8a8 missing: add IFF_MULTI_QUEUE
This was added in 3.8, but we should building with 3.7 headers.

Reported by Samuli Suominen <ssuominen@gentoo.org>.
2014-08-31 18:50:23 +02:00
Zbigniew Jędrzejewski-Szmek a13ee4c792 cgroup-util: shorten cg_path_get_session 2014-08-30 17:41:32 -04:00
Ruben Kerkhof 06b643e7f5 Fix a few more typos 2014-08-30 13:46:07 -04:00
Harald Hoyer 5a4bf02ff5 use the switch_root function in shutdown
removes code duplication

also move switch-root to shared
2014-08-28 15:25:15 +02:00
David Herrmann 667a0377fb macro: use unique variable names for math-macros
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 fb835651af
    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-28 14:45:38 +02:00
Lennart Poettering 8a7c93d858 util: fix minimal race where we might miss SIGTERMs when forking off an agent
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-27 21:43:46 +02:00
David Herrmann f1566e63da util: make lookup_uid() global
This is a useful helper, make it global. It will be required for
libsystemd-terminal, at minimum.
2014-08-27 18:42:28 +02:00
David Herrmann fb835651af shared: make container_of() use unique variable names
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-27 18:42:28 +02:00
David Herrmann 418bcb0ce3 shared: drop UNIQUE()
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-27 18:42:28 +02:00
Lukas Nykryn 81fc054dc7 systemctl: fix broken list-unit-files with --root 2014-08-27 11:48:48 +02:00
Lennart Poettering 1b6d7fa742 util: make use of newly added reset_signal_mask() call wherever appropriate 2014-08-26 21:12:54 +02:00
Lennart Poettering 1dedb74a2e util: reset signals when we fork off agents
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-26 21:12:47 +02:00
Lennart Poettering 24a5d6b04e util: make sure reset_all_signal_handlers() continues with all other signal 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-26 21:03:23 +02:00
Michael Olbrich 7965435e58 missing: add BPF_XOR
BPF_XOR was introduced in kernel 3.7
2014-08-26 20:27:17 +02:00
Lennart Poettering 4fc13f521a Revert "systemctl: fix broken list-unit-files with --root"
This reverts commit 41a451cc29.

This breaks checks for masking of units file, since we invoke
null_or_empty_path() on the resulting path.
2014-08-26 04:09:22 +02:00
Lukas Nykryn 41a451cc29 systemctl: fix broken list-unit-files with --root
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-25 15:51:55 +02:00
Lennart Poettering 2928b0a863 core: add support for a configurable system-wide start-up timeout
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-22 18:10:31 +02:00
Daniel Mack 2de1851fe3 missing.h: add a cpp warning for __NR_memfd_create on MIPS 2014-08-22 16:10:02 +02:00
Daniel Mack a7d611f280 missing.h: add fake __NR_memfd_create for MIPS
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-22 15:41:18 +02:00
David Herrmann 40a1eebde6 shared: add MAXSIZE() and use it in resolved
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-22 14:01:05 +02:00
Lennart Poettering 59ccf93d97 install: simplify usage of _cleanup_ macros 2014-08-21 19:08:30 +02:00
Lennart Poettering 28849dbadb service,strv: introduce strv_find_startswith() and make use of it
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-21 17:24:21 +02:00
Lennart Poettering 5ed1227238 util: make asynchronous_close() really work like an asynchronous version of 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-21 17:24:21 +02:00
Lennart Poettering a9f85faf43 util: simplify close_nointr() a bit 2014-08-21 17:24:21 +02:00
Lennart Poettering 11adc1aef7 util: change return value of startswith() to non-const
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-21 17:24:21 +02:00
Lukas Nykryn 081e009bef util: return after freeing all members of array 2014-08-20 15:02:09 +02:00
Lukas Nykryn fdbdf6ec29 systemctl: fail in the case that no unit files were found
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-20 10:45:18 +02:00
Lennart Poettering 5364f729ba indentation/spurious whitespace fixes 2014-08-20 00:18:14 +02:00
Lennart Poettering 5755381f53 memfd: escape the comm field we get from PR_GET_NAME, but assume everything else is proper UTF8 2014-08-19 22:35:04 +02:00
Daniel Mack ea47ff6697 memfd: skip utf-8 escaping if we use a name that was passed in
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-19 22:08:54 +02:00
Daniel Mack 8f2807bab5 memfd: reduce name escaping logic to utf-8 checks
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-19 21:49:05 +02:00
Lennart Poettering 4531a9bc20 memfd: simplify API
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-19 19:39:16 +02:00
Lennart Poettering 3bb07b7680 Revert "socket: introduce SELinuxLabelViaNet option"
This reverts commit cf8bd44339.

Needs more discussion on the mailing list.
2014-08-19 19:16:08 +02:00
Lennart Poettering 8530dc4467 tmpfiles: add new 'r' line type to add UIDs/GIDs to the pool to allocate 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-19 19:06:39 +02:00
Michal Sekletar cf8bd44339 socket: introduce SELinuxLabelViaNet option
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-19 18:57:12 +02:00
Lennart Poettering 60e6abf16b util: remove unused FOREACH_WORD_SEPARATOR_QUOTED 2014-08-19 16:47:52 +02:00
Lennart Poettering 7629889c86 sysusers: add another column to sysusers files for the home directory 2014-08-19 16:47:52 +02:00