Commit graph

172 commits

Author SHA1 Message Date
Lennart Poettering 525d3cc746 tree-wide: take benefit of the fact that hashmap_free() returns NULL
And set_free() too.

Another Coccinelle patch.
2015-09-09 23:12:07 +02:00
Lennart Poettering 6796073e33 tree-wide: make use of the fact that strv_free() returns NULL
Another Coccinelle patch.
2015-09-09 23:05:58 +02:00
Lennart Poettering ece174c543 tree-wide: drop {} from one-line if blocks
Patch via coccinelle.
2015-09-09 08:20:20 +02:00
Lennart Poettering a1e58e8ee1 tree-wide: use coccinelle to patch a lot of code to use mfree()
This replaces this:

        free(p);
        p = NULL;

by this:

        p = mfree(p);

Change generated using coccinelle. Semantic patch is added to the
sources.
2015-09-09 08:19:27 +02:00
Lennart Poettering f757855e81 nspawn: add new .nspawn files for container settings
.nspawn fiels are simple settings files that may accompany container
images and directories and contain settings otherwise passed on the
nspawn command line. This provides an efficient way to attach execution
data directly to containers.
2015-09-06 01:49:06 +02:00
Lennart Poettering 9ce56418b1 core: don't use uninitialized errno 2015-09-05 20:27:52 +02:00
Lennart Poettering d79200e26e unit: unify how we assing slices to units
This adds a new call unit_set_slice(), and simplifies
unit_add_default_slice(). THis should make our code a bit more robust
and simpler.
2015-08-31 13:20:43 +02:00
Lennart Poettering 3f5e811594 core: don't generate stub unit file for transient units
We store the properties for transient units in drop-ins anyway, and
units don't have to have fragment files, hence don't bother with them,
and don't create them.
2015-08-31 13:20:43 +02:00
Lennart Poettering 023a4f6701 core: optionally create LOGIN_PROCESS or USER_PROCESS utmp entries
When generating utmp/wtmp entries, optionally add both LOGIN_PROCESS and
INIT_PROCESS entries or even all three of LOGIN_PROCESS, INIT_PROCESS
and USER_PROCESS entries, instead of just a single INIT_PROCESS entry.

With this change systemd may be used to not only invoke a getty directly
in a SysV-compliant way but alternatively also a login(1) implementation
or even forego getty and login entirely, and invoke arbitrary shells in
a way that they appear in who(1) or w(1).

This is preparation for a later commit that adds a "machinectl shell"
operation to invoke a shell in a container, in a way that is compatible
with who(1) and w(1).
2015-08-24 22:46:45 +02:00
Richard Maw 12ba2c44dd util: Don't interpret quotes by default in extract_first_word
This adds an EXTRACT_QUOTES option to allow the previous behaviour, of
not interpreting any character inside ' or " quotes as separators.
2015-08-07 15:50:42 +00:00
Richard Maw 6868560773 util: change unquote_*_word to extract_*_word
It now takes a separators argument, which defaults to WHITESPACE if NULL
is passed.
2015-08-07 15:50:42 +00:00
Richard Maw 4b1c175351 Convert unquote_*_word users to expect isempty(p) after the last entry
This is so that, when called in a loop, unquote_first_word can
distinguish between reaching the end of a string because it has consumed
all the input before the end, and consuming all the input.

This is important because we later add a flag that allows

    char *in = "";
    char *out;
    unquote_first_word(&in, &out, flags);

To put "" in out, and set in = NULL, so the trailing empty string of the
input can be consumed, and mark that the input has been consumed.
2015-08-07 15:50:42 +00:00
Zbigniew Jędrzejewski-Szmek 67a3328fbd load-fragment: fix segv on parse error
https://bugzilla.redhat.com/show_bug.cgi?id=1251334
2015-08-07 00:07:39 -04:00
David Herrmann 97b11eedff tree-wide: introduce mfree()
Pretty trivial helper which wraps free() but returns NULL, so we can
simplify this:
        free(foobar);
        foobar = NULL;
to this:
        foobar = mfree(foobar);
2015-07-31 19:56:38 +02:00
Filipe Brandenburger c83f1f30b8 load-fragment: reset the list on an ExecStart= containing only whitespace
This is consistent with how an empty string works in an ExecStart=
statement.  We should not differentiate between an empty string and
whitespace only (since they look the same.)

Update the test case with whitespace only to reflect that the list is
reset.

Tested that `test-unit-file` passes and other test cases are not
affected.  Installed the patched systemd binaries on a machine, booted
it, looked for out of the usual behavior but did not find any.
2015-06-17 11:12:12 -07:00
Filipe Brandenburger 46a0d98ac0 load-fragment: use unquote_first_word in config_parse_exec
Convert config_parse_exec() from using FOREACH_WORD_QUOTED into a loop
of unquote_first_word.

Loop through the arguments only once (the FOREACH_WORD_QUOTED
implementation did it twice, once to count them and another time to
process and store them.)

Use newly introduced flag UNQUOTE_UNESCAPE_RELAX to preserve
unrecognized escape sequences such as regexps matches such as "\w",
"\d", etc. (Valid escape sequences such as "\s" or "\b" still need an
extra backslash if literals are desired for regexps.)

Differences in behavior:

- Handle ; (command separator) in special, so that only ; on its own is
  valid for that purpose, an quoted semicolon ";" or ';' will now behave
  as a literal semicolon.  This is probably what was initially intended.

- Handle \; (to introduce a literal semicolon) in special, so that only \;
  is turned into a semicolon but not \\; or "\\;" or "\;" which are kept
  as a literal \; in the output.  This is probably what was initially
  intended.

Known issues:

- Using an empty string (for example, ExecStartPre=<empty>) will empty
  the list and remove the existing commands, but using whitespace only
  (for example, ExecStartPre=<spaces>) will not.  This is a pre-existing
  issue and will be dealt with in a follow up commit.

Tested:

- Unit tests passing.  Also `make distcheck` still works as expected.

- Installed it on a local machine and booted with it, checked console
  output, systemctl and journalctl output, did not notice any issues
  running the patched systemd binaries.

Relevant bug: https://bugs.freedesktop.org/show_bug.cgi?id=90794
2015-06-17 11:12:12 -07:00
Daniel Mack 22874a348f load-fragment: use UNESCAPE_RELAX flag to parse exec directives
The cunescape() helper function used to handle unknown escaping sequences
gracefully by copying them over verbatim.

Commit 527b7a42 ("util: rework cunescape(), improve error handling") added
a flag to make that behavior optional, and changed to default to error out
with -EINVAL otherwise.

However, config_parse_exec(), which is used to parse the
Exec{Start,Stop}{Post,Pre,} directives of unit files, was not changed along
with that commit, which means that directives with improperly escaped
command line strings are no longer parsed.

Relevant bugreports include:

  https://bugs.freedesktop.org/show_bug.cgi?id=90794
  https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787256

Fix this by passing UNESCAPE_RELAX to config_parse_exec() in order to
restore the original behavior.
2015-06-01 18:08:44 +02:00
Lennart Poettering 24882e06c1 util: split out signal-util.[ch] from util.[ch]
No functional changes.
2015-05-29 20:14:11 +02:00
Lennart Poettering 050f727728 util: introduce PERSONALITY_INVALID as macro for 0xffffffffLU 2015-05-21 19:48:49 +02:00
Zbigniew Jędrzejewski-Szmek c18d201808 load-fragment: put quotes around iffy rvalue 2015-05-16 18:21:10 -04:00
Lennart Poettering 7693146dee socket-util: socket_address_parse() should not log errors on its own
Given that socket_address_parse() is mostly a "library" call it
shouldn't log on its own, but leave that to its caller.

This patch removes logging from the call in case IPv6 is not available
but and IPv6 address shall be parsed. Instead a new call
socket_address_parse_and_warn() is introduced which first invokes
socket_address_parse() and then logs if necessary.

This should fix "make check" on ipv6-less kernels:

http://lists.freedesktop.org/archives/systemd-devel/2015-April/031385.html
2015-05-15 20:15:59 +02:00
Martin Pitt 35b1078e1c core: Fix assertion with empty Exec*= paths
An Exec*= line with whitespace after modifiers, like

  ExecStart=- /bin/true

is considered to have an empty command path. This is as specified, but causes
systemd to crash with

  Assertion 'skip < l' failed at ../src/core/load-fragment.c:607, function config_parse_exec(). Aborting.
  Aborted (core dumped)

Fix this by logging an error instead and ignoring the invalid line.

Add corresponding test cases. Also add a test case for a completely empty value
which resets the command list.

https://launchpad.net/bugs/1454173
2015-05-15 20:02:44 +02:00
Lennart Poettering b2c23da8ce core: rename SystemdRunningAs to ManagerRunningAs
It's primarily just a property of the Manager object after all, and we
try to refer to PID 1 as "manager" instead of "systemd", hence let's to
stick to this here too.
2015-05-11 22:51:49 +02:00
Lennart Poettering 7410616cd9 core: rework unit name validation and manipulation logic
A variety of changes:

- Make sure all our calls distuingish OOM from other errors if OOM is
  not the only error possible.

- Be much stricter when parsing escaped paths, do not accept trailing or
  leading escaped slashes.

- Change unit validation to take a bit mask for allowing plain names,
  instance names or template names or an combination thereof.

- Refuse manipulating invalid unit name
2015-05-05 15:06:42 -07:00
Lennart Poettering 8d9803b83c core: fix parsing of mount flags
As reported my Maciej Wereski:

http://lists.freedesktop.org/archives/systemd-devel/2015-February/028320.html
2015-04-23 16:21:38 +02:00
Ronny Chevalier 756c09e672 core: set_put never returns -EEXIST
When the value is already there it returns 0.

Also add a test to ensure this
2015-04-10 17:13:15 +02:00
Zbigniew Jędrzejewski-Szmek a40e26f392 Indentation 2015-04-08 11:28:45 -04:00
Lennart Poettering 527b7a421f util: rework cunescape(), improve error handling
Change cunescape() to return a normal error code, so that we can
distuingish OOM errors from parse errors.

This also adds a flags parameter to control whether "relaxed" or normal
parsing shall be done. If set no parse failures are generated, and the
only reason why cunescape() can fail is OOM.
2015-04-07 15:42:25 +02:00
Zbigniew Jędrzejewski-Szmek bdb26d423a core: remove left-over debug message 2015-03-14 17:42:10 -04:00
David Herrmann 15411c0cb1 tree-wide: there is no ENOTSUP on linux
Replace ENOTSUP by EOPNOTSUPP as this is what linux actually uses.
2015-03-13 14:10:39 +01:00
Zbigniew Jędrzejewski-Szmek d4ad27a104 core/load-fragment: safe_close() protects errno 2015-03-07 14:36:14 -05:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Michael Olbrich 615938651d config_parse_set_status: put signals in the correct set
This was broken when the code was rearranged in "1e2fd62d70ff
core/load-fragment.c: correct argument sign and split up long lines"
2015-02-01 17:22:31 -05:00
Torstein Husebø cc98b3025e treewide: fix multiple typos 2015-01-26 10:39:47 -05:00
Lennart Poettering a2e0337875 util: make http url validity checks more generic, and move them to util.c 2015-01-20 15:06:58 +01:00
Zbigniew Jędrzejewski-Szmek e01ff42899 core/load-fragment: avoid allocating 0 bytes when given an invalid command
With a command line like "@/something" we would allocate an array with
0 elements. Avoid that, and add a test too.
2015-01-11 23:41:42 -05:00
Lennart Poettering b02cb41c78 conf-parse: don't accept invalid bus names as BusName= arguments in service units 2015-01-07 23:44:08 +01:00
Zbigniew Jędrzejewski-Szmek c853953658 load-fragment: allow quoting in command name and document allowed escapes
The handling of the command name and other arguments is unified. This
simplifies things and should make them more predictable for users.
Incidentally, this makes ExecStart handling match the .desktop file
specification, apart for the requirment for an absolute path.

https://bugs.freedesktop.org/show_bug.cgi?id=86171
2014-12-18 19:26:21 -05:00
Zbigniew Jędrzejewski-Szmek 447021aafd tree-wide: make condition_free_list return NULL 2014-12-18 19:26:21 -05:00
Zbigniew Jędrzejewski-Szmek f1acf85a36 core: make exec_command_free_list return NULL 2014-12-18 19:26:21 -05:00
tomsod-m ya ru 3851c51ad1 load-fragment: properly unescape \;
https://bugs.freedesktop.org/show_bug.cgi?id=87393
2014-12-17 23:01:38 -05:00
Thomas Hindoe Paaboel Andersen abc08d4d08 wrap a few *_FOREACH macros in curly braces
cppcheck would give up with "syntax error" without them. This led
to reports of syntax errors in unrelated locations and potentially
hid other errors
2014-12-12 21:57:44 +01:00
Lennart Poettering ae6c3cc009 util: when using basename() for creating temporary files, verify the 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-12 13:35:32 +01:00
Lennart Poettering 2822da4fb7 util: introduce our own gperf based capability list
This way, we can ensure we have a more complete, up-to-date list of
capabilities around, always.
2014-12-10 03:21:07 +01:00
Zbigniew Jędrzejewski-Szmek 4e7dff9b09 load-fragment: remove wrong ifdef guard
config_parse_warn_compat is now always used for removed options.

https://bugs.freedesktop.org/show_bug.cgi?id=87125
2014-12-08 17:27:46 -05:00
Zbigniew Jędrzejewski-Szmek 9e37c9544b core: warn and ignore SysVStartPriority=
Option was being parsed but not used for anything.
2014-11-30 19:10:40 -05:00
Zbigniew Jędrzejewski-Szmek a2c0e528b8 When warning about unsupported options, be more detailed 2014-11-30 18:49:08 -05:00
Ronny Chevalier 4e2744fcb5 core: remove unused variables 2014-11-30 02:35:56 +01:00
WaLyong Cho 2ca620c4ed smack: introduce new SmackProcessLabel option
In service file, if the file has some of special SMACK label in
ExecStart= and systemd has no permission for the special SMACK label
then permission error will occurred. To resolve this, systemd should
be able to set its SMACK label to something accessible of ExecStart=.
So introduce new SmackProcessLabel. If label is specified with
SmackProcessLabel= then the child systemd will set its label to
that. To successfully execute the ExecStart=, accessible label should
be specified with SmackProcessLabel=.
Additionally, by SMACK policy, if the file in ExecStart= has no
SMACK64EXEC then the executed process will have given label by
SmackProcessLabel=. But if the file has SMACK64EXEC then the
SMACK64EXEC label will be overridden.

[zj: reword man page]
2014-11-24 10:20:53 -05:00
Lennart Poettering 59fccdc587 core: introduce the concept of AssertXYZ= similar to ConditionXYZ=, but fatal for a start job if not met 2014-11-06 14:21:11 +01:00