Commit graph

17269 commits

Author SHA1 Message Date
Lennart Poettering ecc0eab247 Merge pull request #4670 from htejun/systemd-controller-on-unified-v2
Systemd controller on unified v2
2017-02-23 16:23:02 +01:00
Evgeny Vereshchagin c07afaa5e5 Merge pull request #5434 from poettering/udev-log-revert
Udev log revert
2017-02-23 15:06:03 +03:00
Namhyung Kim b4e7bdcb53 journal: avoid duplicated call to get cgroup path (#5404)
The cg_pid_get_path_shifted() is called twice during
server_dispatch_message().  We can get rid of the second by passing the
path to dispatch_message_real().
2017-02-23 13:04:57 +01:00
Lennart Poettering b90ef60fbc Revert "udev: Introduce UDEV_PROPAGATE_LOG macro (#5302)"
This reverts commit c22569eeea.

Let's revert this for now, since it apparently doesn't fix the problem
at hand.
2017-02-23 12:36:25 +01:00
Zbigniew Jędrzejewski-Szmek 0a05dcc09d test-cgroup-util: add a "test" to print out cg_is_*_wanted() values
This isn't terribly useful because /sys/fs/cgroup will usually be mounted.
But it at least allows checking if the values make sense in this case.
2017-02-22 19:58:06 -05:00
Zbigniew Jędrzejewski-Szmek c19739db9e cgroup-util: fix the case of default=unified, unified-cgroup-hierarchy=0
We should mount the hybrid hierarchy if the user disabled the unified
hierarchy on the kernel command line.
2017-02-22 19:58:06 -05:00
Zbigniew Jędrzejewski-Szmek 239a3d0954 cgroup-util: cache all cg_is_*_wanted answers, disable /sys/fs/cgroups/unified on unified
If we encounter an error in proc cmdline parsing, just treat that as permanent,
i.e. the same as if the option was not specified. Realistically, it is better
to use the same condition for all related mounts, then to have e.g.
/sys/fs/cgroup mounted and /sys/fs/cgroup/unified not. If we find something is
mounted and base our answer on that, cache that result too.

Fix the conditions so that if "unified" is used, make sure any "hybrid" mounts
are not mounted.
2017-02-22 12:57:43 -05:00
Zbigniew Jędrzejewski-Szmek 1b59cf04ae core/mount-setup: if unified hierarchy is not supported, fall back to legacy
We need this to gracefully support older or strangely configured kernels.

v2:
- do not install a callback handler, just embed the right conditions into
  cg_is_*_wanted()

v3:
- fix bug in cg_is_legacy_wanted()
2017-02-22 11:52:31 -05:00
Zbigniew Jędrzejewski-Szmek a4464b9522 Rename cg_is_unified_systemd_controller_wanted to cg_is_hybrid_wanted
Less typing and doesn't make the table so incredibly wide.
2017-02-22 11:52:31 -05:00
Susant Sahani f7fe70ea31 networkd: address config add error checking
We not looking for hashmap_put return error code.
2017-02-22 11:11:28 +05:30
Susant Sahani fcc48287eb networkd: Do not set config to NULL immediately.
fd45e52 sets
n to NULL which leads to crash.

fixes: #5418
2017-02-22 10:55:03 +05:30
Evgeny Vereshchagin b965427b59 Merge pull request #5409 from keszybz/test-env-util-memleak
test-env-util: fix typo leading to memleak
2017-02-22 04:02:57 +03:00
Susant Sahani c22569eeea udev: Introduce UDEV_PROPAGATE_LOG macro (#5302)
As per commit 25e773e "udev: switch to systemd logging functions"
Now log_set_max_level() in udev_new() overwites system wide log level.

Propagate the udev.conf setting to log_set_max_level()
only if udev_new() is called from within udevd or one of its helpers.

Introduce a UDEV_PROPAGATE_LOG macro that we set with -D on
the gcc command line for all udev binaries we build, but not
for any others. The log_set_max_level() call is guarded by an
ifdef check for that macro, so that it only effects the various
udev binaries.

closes: #4525
2017-02-22 00:16:13 +01:00
Thomas H. P. Andersen 0f5a443e8c coredump: fix assign in while loop (#5417)
From: #5393
2017-02-22 00:14:54 +01:00
Lennart Poettering bcab914f7f Revert "basic/strv: allow NULLs to be inserted into strv"
This reverts commit 18f71a3c81.

According to @keszybz we don't need this anymore, hence drop it:

18f71a3c81 (r102232368)
2017-02-21 21:55:44 +01:00
Lennart Poettering 48a601fe5d log: never log into foreign fd #2 in PID 1 or its pre-execve() children
Fixes: #5401
2017-02-21 21:55:43 +01:00
Lennart Poettering f5b84de2ab bootctl: create loader.conf only if it doesn't exist yet
If the snippet aleady exists, don't do anything, as the file was already
installed then.

(This also reworks the code to create the file atomically)

Fixes: #5396
2017-02-21 21:55:43 +01:00
Lennart Poettering 175d308cad bootctl: rework file copy routines to reuse copy_bytes() from copy.c
Also, make sure to reuse temporary file handling used elsewhere.
2017-02-21 21:55:43 +01:00
Lennart Poettering ce21ed5c61 copy: a plain unlink() works here too 2017-02-21 21:41:32 +01:00
Lennart Poettering 71994cff31 sd-netlink: don't give up on netlink on ENOBUFS
If our netlink input buffer overruns the kernel will send us ENOBUFS on
the next recvmsg(). Don't consider this a complete failure resulting in
closing of the netlink socket. Instead, simply continue (after debug
logging).

Of course, ideally we'd have a better strategy for this, and would have
a way to resync if this happens (as well as a scheme for cancelling all
ongoing asynchronous transactions), but for now let's at least not choke
fatally, and simply accept that we lost some messages and continue.

Note that if we lose messages when synchronously waiting for an
operation to complete, we'll still propagate the ENOBUFS up, to make the
individual transaction fail.

See: #5398

(This bug does not properly fix the issue, hence we should leave the bug
open.)
2017-02-21 21:41:32 +01:00
Lennart Poettering 94c4c62279 dissect: generate friendly error messages for more error conditions
Fixes: #5408
2017-02-21 21:41:32 +01:00
stuart-mclaren a3d8d68cc1 Fix check for signal in set (#5416)
IN_SET(SIGCONT, SIGKILL) will always evaluate to false.
The signal needs to be included as the first argument.

Fixup for 26f417d3e8.
2017-02-21 15:39:52 -05:00
Zbigniew Jędrzejewski-Szmek 1d046f5720 basic/env-util: drop leftover comment 2017-02-21 11:53:42 -05:00
Zbigniew Jędrzejewski-Szmek 371328dc74 basic/fileio: use IN_SET 2017-02-21 11:15:51 -05:00
Zbigniew Jędrzejewski-Szmek 2ea8081a55 basic/fileio: fix memleak when discarding an invalid variable
Fixes #5405.
2017-02-21 11:15:50 -05:00
Zbigniew Jędrzejewski-Szmek 6fd667e5c9 mount-tools: silence gcc warning about uninit var 2017-02-21 11:15:50 -05:00
Zbigniew Jędrzejewski-Szmek a93236aa64 test-env-util: fix typo leading to memleak
Partially fixes #5405.
2017-02-21 11:15:43 -05:00
Lennart Poettering 10ab1831de systemctl: suffix cmdline options that take arguments with =
Just to clarify, that these options expect arguments, following our
usual style.
2017-02-21 11:17:24 +01:00
Lennart Poettering a4dde27d73 Merge pull request #5131 from keszybz/environment-generators
Environment generators
2017-02-21 11:11:44 +01:00
Zbigniew Jędrzejewski-Szmek 012f2b7de7 coredumpctl: print a hint if any coredumps are in flight (#5393)
Fixes #4685.
2017-02-21 11:08:35 +01:00
Lennart Poettering 1ebfd03bd9 Merge pull request #5390 from keszybz/coverity
Clarifications to make coverity happy
2017-02-21 10:49:49 +01:00
Zbigniew Jędrzejewski-Szmek f50ce8fc4b test-env-util: add more tests for "extended syntax"
This is only the tip of the iceberg. It would be great to test all kinds of nesting, handling
of invalid syntax, etc., but I'm leaving that for later.
2017-02-20 23:35:19 -05:00
Ray Strode b82f58bfe3 basic: support default and alternate values for env expansion
Sometimes it's useful to provide a default value during an environment
expansion, if the environment variable isn't already set.

For instance $XDG_DATA_DIRS is suppose to default to:

/usr/local/share/:/usr/share/

if it's not yet set. That means callers wishing to augment
XDG_DATA_DIRS need to manually add those two values.

This commit changes replace_env to support the following shell
compatible default value syntax:

XDG_DATA_DIRS=/foo:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share}

Likewise, it's useful to provide an alternate value during an
environment expansion, if the environment variable isn't already set.

For instance, $LD_LIBRARY_PATH will inadvertently search the current
working directory if it starts or ends with a colon, so the following
is usually wrong:

LD_LIBRARY_PATH=/foo/lib:${LD_LIBRARY_PATH}

To address that, this changes replace_env to support the following
shell compatible alternate value syntax:

LD_LIBRARY_PATH=/foo/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

[zj: gate the new syntax under REPLACE_ENV_ALLOW_EXTENDED switch, so
existing callers are not modified.]
2017-02-20 23:32:53 -05:00
Ray Strode 4bed076c5f basic: add replace_env_n function
It's like replace_env, but lets you pass in a substring.
2017-02-20 23:32:53 -05:00
Zbigniew Jędrzejewski-Szmek 184d190473 Tighten checking for variable validity
In the future we might want to allow additional syntax (for example
"unset VAR". But let's check that the data we're getting does not contain
anything unexpected.
2017-02-20 23:32:53 -05:00
Zbigniew Jędrzejewski-Szmek ccad1fd07c Allow braceless variables to be expanded
(Only in environment.d files.)

We have only basic compatibility with shell syntax, but specifying variables
without using braces is probably more common, and I think a lot of people would
be surprised if this didn't work.
2017-02-20 23:30:50 -05:00
Zbigniew Jędrzejewski-Szmek cb4499d005 basic/env-util: use _cleanup_ in replace_env() 2017-02-20 18:49:14 -05:00
Zbigniew Jędrzejewski-Szmek f63c4aabb2 environment-generator: new generator to peruse environment.d
Why the strange name: the prefix is necessary to follow our own advice that
environment generators should have numerical prefixes. I also put -d- in the
name because otherwise the name was very easy to mistake with
systemd.environment-generator. This additional letter clarifies that this
on special generator that supports environment.d files.
2017-02-20 18:49:14 -05:00
Ray Strode 37f3ffca27 basic: add new merge_env_file function
merge_env_file is a new function, that's like load_env_file, but takes a
pre-existing environment as an input argument. New environment entries are
merged. Variable expansion is performed.

Falling back to the process environment is supported (when a flag is set).
Alternatively this could be implemented as passing an additional fallback
environment array, but later on we're adding another flag to allow braceless
expansion, and the two flags can be combined in one arg, so there's less
stuff to pass around.
2017-02-20 18:49:14 -05:00
Ray Strode d8ad241f54 basic: drop unnecessary strempty() call in replace_env
strempty() converts a NULL value to empty string, so
that it can be passed on to functions that don't support NULL.

replace_env calls strempty before passing its value on to strappend.

strappend supports NULL just fine, though, so this commit drops the
strempty call.
2017-02-20 18:49:14 -05:00
Ray Strode 6162512cde basic: fix strv_env_get_n for unclean arrays
If an environment array has duplicates, strv_env_get_n returns
the results for the first match. This is wrong, because later
entries in the environment are supposed to replace earlier
entries.
2017-02-20 18:49:14 -05:00
Zbigniew Jędrzejewski-Szmek 64691d2024 manager: run environment generators
Environment file generators are a lot like unit file generators, but not
exactly:

1. environment file generators are run for each manager instance, and their
   output is (or at least can be) individualized.

   The generators themselves are system-wide, the same for all users.

2. environment file generators are run sequentially, in priority order.

Thus, the lifetime of those files is tied to lifecycle of the manager
instance. Because generators are run sequentially, later generators can use or
modify the output of earlier generators.

Each generator is run with no arguments, and the whole state is stored in the
environment variables. The generator can echo a set of variable assignments to
standard output:

  VAR_A=something
  VAR_B=something else

This output is parsed, and the next and subsequent generators run with those
updated variables in the environment. After the last generator is done, the
environment that the manager itself exports is updated.

Each generator must return 0, otherwise the output is ignored.

The generators in */user-env-generator are for the user session managers,
including root, and the ones in */system-env-generator are for pid1.
2017-02-20 18:49:14 -05:00
Zbigniew Jędrzejewski-Szmek 3303d1b2dc exec-util: implement a set of callbacks to pass variables around
Only tests are added, otherwise the new code is unused.
2017-02-20 18:49:14 -05:00
Zbigniew Jędrzejewski-Szmek c8cebc36b0 basic/env-util: drop _pure_ from static function 2017-02-20 18:49:14 -05:00
Zbigniew Jędrzejewski-Szmek 99003e01b6 env-util,fileio: immediately replace variables in load_env_file_push()
strv_env_replace was calling env_match(), which in effect allowed multiple
values for the same key to be inserted into the environment block. That's
pointless, because APIs to access variables only return a single value (the
latest entry), so it's better to keep the block clean, i.e. with just a single
entry for each key.

Add a new helper function that simply tests if the part before '=' is equal in
two strings and use that in strv_env_replace.

In load_env_file_push, use strv_env_replace to immediately replace the previous
assignment with a matching name.

Afaict, none of the callers are materially affected by this change, but it
seems like some pointless work was being done, if the same value was set
multiple times. We'd go through parsing and assigning the value for each
entry. With this change, we handle just the last one.
2017-02-20 18:49:14 -05:00
Zbigniew Jędrzejewski-Szmek ac46681881 basic/fileio: add helper function for a set of two common checks 2017-02-20 18:49:14 -05:00
Zbigniew Jędrzejewski-Szmek fe902fa496 core/manager: move environment serialization out to basic/env-util.c
This protocol is generally useful, we might just as well reuse it for the
env. generators.

The implementation is changed a bit: instead of making a new strv and freeing
the old one, just mutate the original. This is much faster with larger arrays,
while in fact atomicity is preserved, since we only either insert the new
entry or not, without being in inconsistent state.

v2:
- fix confusion with return value
2017-02-20 18:49:14 -05:00
Zbigniew Jędrzejewski-Szmek 71cb7d306a core/manager: fix grammar in comment 2017-02-20 18:49:14 -05:00
Zbigniew Jędrzejewski-Szmek c6e47247a7 basic/exec-util: add support for synchronous (ordered) execution
The output of processes can be gathered, and passed back to the callee.
(This commit just implements the basic functionality and tests.)

After the preparation in previous commits, the change in functionality is
relatively simple. For coding convenience, alarm is prepared *before* any
children are executed, and not before. This shouldn't matter usually, since
just forking of the children should be pretty quick. One could also argue that
this is more correct, because we will also catch the case when (for whatever
reason), forking itself is slow.

Three callback functions and three levels of serialization are used:
- from individual generator processes to the generator forker
- from the forker back to the main process
- deserialization in the main process

v2:
- replace an structure with an indexed array of callbacks
2017-02-20 18:49:13 -05:00
Zbigniew Jędrzejewski-Szmek 504afd7c34 core/manager: split out creation of serialization fd out to a helper
There is a slight change in behaviour: the user manager for root will create a
temporary file in /run/systemd, not /tmp. I don't think this matters, but
simplifies implementation.
2017-02-20 18:49:09 -05:00