Commit graph

93 commits

Author SHA1 Message Date
Lukas Nykryn e94937df95 systemctl: add add-wants and add-requires verbs 2014-10-08 12:44:00 +02:00
Jan Synacek f7101b7368 core: don't allow enabling if unit is masked 2014-10-07 17:08:18 -04:00
Zbigniew Jędrzejewski-Szmek 4d5dec2389 Rename user_runtime to user_runtime_dir
This makes this function name similar to user_config_home() and makes
it match the name of the environment variable.
2014-10-02 11:10:35 -04:00
Steven Allen 718880ba0d add a transient user unit directory
This patch adds a transient user unit directory under
`$XDG_RUNTIME_DIR/systemd/user/` and stores transient user-instance
units (such as those created by `systemd-run --user`) under there
instead of putting them in $XDG_CONFIG_HOME/systemd/user/.

Fixes https://bugs.freedesktop.org/show_bug.cgi?id=67331
2014-10-02 10:37:30 -04: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
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
Lukas Nykryn 81fc054dc7 systemctl: fix broken list-unit-files with --root 2014-08-27 11:48:48 +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 59ccf93d97 install: simplify usage of _cleanup_ macros 2014-08-21 19:08:30 +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
Dave Reisner 8085f163c5 util: allow strappenda to take any number of args
This makes strappenda3 redundant, so we remove its usage and
definition. Add a few tests along the way for sanity.
2014-08-13 20:41:41 -04:00
Zbigniew Jędrzejewski-Szmek b2fadec604 Properly report invalid quoted strings
$ systemd-analyze verify trailing-g.service
[./trailing-g.service:2] Trailing garbage, ignoring.
trailing-g.service lacks ExecStart setting. Refusing.
Error: org.freedesktop.systemd1.LoadFailed: Unit trailing-g.service failed to load: Invalid argument.
Failed to create trailing-g.service/start: Invalid argument
2014-07-31 08:56:03 -04:00
Zbigniew Jędrzejewski-Szmek a2a5291b3f Reject invalid quoted strings
String which ended in an unfinished quote were accepted, potentially
with bad memory accesses.

Reject anything which ends in a unfished quote, or contains
non-whitespace characters right after the closing quote.

_FOREACH_WORD now returns the invalid character in *state. But this return
value is not checked anywhere yet.

Also, make 'word' and 'state' variables const pointers, and rename 'w'
to 'word' in various places. Things are easier to read if the same name
is used consistently.

mbiebl_> am I correct that something like this doesn't work
mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-passwd "Unlock EncFS"'
mbiebl_> systemd seems to strip of the quotes
mbiebl_> systemctl status shows
mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-password Unlock EncFS  $RootDir $MountPoint
mbiebl_> which is pretty weird
2014-07-31 04:00:31 -04:00
Zbigniew Jędrzejewski-Szmek 0c6ea3a4e2 Add utility function to append root to path 2014-07-26 15:08:42 -04:00
Karel Zak 7de80bfe2e Always check asprintf return code
There is a small number of the places in sources where we don't check
asprintf() return code and assume that after error the function
returns NULL pointer via the first argument. That's wrong, after
error the content of pointer is undefined.
2014-07-26 15:08:41 -04:00
Zbigniew Jędrzejewski-Szmek 86bbe5bfbc test-tables: add new entries
One missing string found.

A few things had to be moved around to make it possible to test them.
2014-07-16 19:00:03 -04:00
Zbigniew Jędrzejewski-Szmek 36f822c4bd Let config_parse open file where applicable
Special care is needed so that we get an error message if the
file failed to parse, but not when it is missing. To avoid duplicating
the same error check in every caller, add an additional 'warn' boolean
to tell config_parse whether a message should be issued.
This makes things both shorter and more robust wrt. to error reporting.
2014-07-16 18:47:20 -04:00
Zbigniew Jędrzejewski-Szmek e9f3d2d508 Constify ConfigTableItem tables 2014-07-15 22:34:40 -04:00
Michael Marineau cba2ef0272 conf-files: include root in returned file paths
This restores the original root handling logic that was present prior to
112cfb18 when path expansion moved to path_strv_canonicalize_absolute.
That behavior partially went away in 12ed81d9.

Alternatively all users of conf_files_list* could be updated to
concatenate the paths themselves as unit_file_query_preset did but since
no user needs the un-concatenated form that is pointless duplication.
2014-06-20 00:10:47 -04:00
Thomas Hindoe Paaboel Andersen de228aabc8 install: remove unused variable 2014-06-17 21:22:01 +02:00
Lennart Poettering ac78d81a35 install: improve paths we show the user when enabling/disabling 2014-06-17 02:43:44 +02:00
Lennart Poettering 278fa5758c install: simplify symlink --root= logic 2014-06-17 02:43:44 +02:00
Lennart Poettering 0a327d753f install: "systemctl enable" should be a nop for template units lacking a DefaultInstance= setting 2014-06-17 02:43:44 +02:00
Lennart Poettering 8f294b45cb install: make sure that --root= mode doesn't make us consider all units outside of search path 2014-06-17 02:43:43 +02:00
Lennart Poettering 559367add5 install: make sure "systemctl disable foobar@.service" actually removes all instances 2014-06-17 02:43:43 +02:00
Lennart Poettering d54c499369 install: introduce new DefaultInstance= field for [Install] sections
The DefaultInstance= name is used when enabling template units when only
specifying the template name, but no instance.

Add DefaultInstance=tty1 to getty@.service, so that when the template
itself is enabled an instance for tty1 is created.

This is useful so that we "systemctl preset-all" can work properly,
because we can operate on getty@.service after finding it, and the right
instance is created.
2014-06-17 02:43:43 +02:00
Lennart Poettering e50bd77516 install: when looking for a unit file for enabling, search for templates only after traversing all search directories
Let's always make sure to look in all search directories for the full
unit names first, before looking for templates for them.
2014-06-17 02:43:43 +02:00
Lennart Poettering 1f8c46040e install: use symlink_atomic() instead of unlink()+symlink() when force creating a symlink 2014-06-17 02:43:43 +02:00
Lennart Poettering 1dacfd2ad6 install: various modernizations 2014-06-17 02:43:43 +02:00
Lennart Poettering c2a8d7b05c install: teach preset query logic --root= support 2014-06-17 02:43:43 +02:00
Lennart Poettering d309c1c364 install: beef up preset logic to limit to only enable or only disable, and do all-unit preset operations
The new "systemctl preset-all" command may now be used to put all
installed units back into the enable/disable state the vendor/admin
encoded in preset files.

Also, introduce "systemctl --preset-mode=enable-only" and "systemctl
--preset-mode=disable-only" to only apply the enable or only the disable
operations of a "systemctl preset" or "systemctl preset-all" operation.

"systemctl preset-all" implements this RFE:

https://bugzilla.redhat.com/show_bug.cgi?id=630174
2014-06-17 02:43:17 +02:00
Lennart Poettering bcafe923a7 install: simplify and clarify disabling logic for instanced units 2014-06-17 01:24:04 +02:00
Lennart Poettering da39f6a63e install: various modernizations 2014-06-17 01:24:04 +02:00
Andreas Henriksson 223217749e install: fix invalid free() in unit_file_mask()
int unit_file_mask(...) in ./src/shared/install.c calls
get_config_path(...) which can in 4 error cases return without setting
"ret", and thus "prefix" can be uninitialized when unit_file_mask(...)
finishes (which it does directly after the error is returned from
get_config_path(...)).
2014-06-13 19:01:07 +02:00
Zbigniew Jędrzejewski-Szmek 12ed81d9c8 Make systemctl --root look for files in the proper places
Running systemctl enable/disable/set-default/... with the --root
option under strace reveals that it accessed various files and
directories in the main fs, and not underneath the specified root.
This can lead to correct results only when the layout and
configuration in the container are identical, which often is not the
case. Fix this by adding the specified root to all file access
operations.

This patch does not handle some corner cases: symlinks which point
outside of the specified root might be interpreted differently than
they would be by the kernel if the specified root was the real root.
But systemctl does not create such symlinks by itself, and I think
this is enough of a corner case not to be worth the additional
complexity of reimplementing link chasing in systemd.

Also, simplify the code in a few places and remove an hypothetical
memory leak on error.
2014-05-15 15:29:58 +02:00
Zbigniew Jędrzejewski-Szmek 62b0023377 shared/install: do not prefix created symlink with root path
Before: /var/tmp/inst1//etc/systemd/system/default.target -> /var/tmp/inst1//usr/lib/systemd/system/graphical.target
After: /var/tmp/inst1/etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target
2014-05-15 15:29:57 +02:00
Lennart Poettering ead349509e replace more dup() by F_DUPFD_CLOEXEC 2014-05-13 16:40:53 +02:00
Lennart Poettering b91a3b02f3 install: simplification 2014-04-23 19:06:38 +02:00
Djalal Harouni af7fce1cdb install: create_symlink() check unlink() return value
create_symlink() do not check the return value of unlink(), this may
confuse the user.

Before the unlink() call we check the 'force' argument. If it is not set
we fail with -EEXIST, otherwise we unlink() the file, therefore the next
symlink() should not fail with -EEXIST (do not count races...).

However since callers may not have appropriate privileges to unlink()
the file we lose the -EPERM or any other errno code of unlink(), and
return the -EEXIST of the next symlink(). Fix this by checking unlink()
results.

Before:
$ systemctl --force --root=~/container-03 set-default multi-user.target
Failed to set default target: File exists

After:
$ systemctl --force --root=~/container-03 set-default multi-user.target
Failed to set default target: Permission denied
2014-04-16 23:13:22 -04:00
Lennart Poettering 03e334a1c7 util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed,
and returns -1 unconditionally. This makes it easy to write lines like
this:

        fd = safe_close(fd);

Which will close an fd if it is open, and reset the fd variable
correctly.

By making use of this new scheme we can drop a > 200 lines of code that
was required to test for non-negative fds or to reset the closed fd
variable afterwards.
2014-03-18 19:31:34 +01:00
Zbigniew Jędrzejewski-Szmek bdd13f6be4 Remove dead lines in various places
As pointed-out by clang -Wunreachable-code.

No behaviour changes.
2014-02-24 19:24:14 -05:00
Zbigniew Jędrzejewski-Szmek 7195aa42e3 shared/install: use char** convention for strvs 2014-01-05 09:16:15 -05:00
Zbigniew Jędrzejewski-Szmek f78e6385dc Use enums to make it obvious what boolean params mean
Suggested-by: Russ Allbery <rra@debian.org>
2013-12-26 15:49:54 -05:00
Lennart Poettering 693eb9a2d4 bus: rename message "serial" to "cookie"
Even if the lower-leveld dbus1 protocol calls it "serial", let's expose
the word "cookie" for this instead, as this is what kdbus uses and since
it doesn't imply monotonicity the same way "serial" does.
2013-12-25 18:04:04 +01:00
Florian Weimer 4d993c8cb7 install: replace readdir_r with readdir
The old code incorrectly assumed that readdir_r updates errno.
2013-12-21 18:35:55 -05:00
Zbigniew Jędrzejewski-Szmek 2b6bf07dd2 Get rid of our reimplementation of basename
The only problem is that libgen.h #defines basename to point to it's
own broken implementation instead of the GNU one. This can be fixed
by #undefining basename.
2013-12-06 21:29:55 -05:00
Tom Gundersen 71a6151083 conf-parser: distinguish between multiple sections with the same name
Pass on the line on which a section was decleared to the parsers, so they
can distinguish between multiple sections (if they chose to). Currently
no parsers take advantage of this, but a follow-up patch will do that
to distinguish

[Address]
Address=192.168.0.1/24
Label=one

[Address]
Address=192.168.0.2/24
Label=two

from

[Address]
Address=192.168.0.1/24
Label=one
Address=192.168.0.2/24
Label=two
2013-11-25 19:35:44 +01:00
Lennart Poettering 718db96199 core: convert PID 1 to libsystemd-bus
This patch converts PID 1 to libsystemd-bus and thus drops the
dependency on libdbus. The only remaining code using libdbus is a test
case that validates our bus marshalling against libdbus' marshalling,
and this dependency can be turned off.

This patch also adds a couple of things to libsystem-bus, that are
necessary to make the port work:

- Synthesizing of "Disconnected" messages when bus connections are
  severed.

- Support for attaching multiple vtables for the same interface on the
  same path.

This patch also fixes the SetDefaultTarget() and GetDefaultTarget() bus
calls which used an inappropriate signature.

As a side effect we will now generate PropertiesChanged messages which
carry property contents, rather than just invalidation information.
2013-11-20 20:52:36 +01:00
Lennart Poettering e8372f7e3e install: when determining where default.target points to, accept a file instead of a symlink, too 2013-11-20 19:37:02 +01:00