Commit graph

75 commits

Author SHA1 Message Date
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
Lennart Poettering 16ed0233a5 install: use const where we can 2013-11-20 19:36:13 +01:00
Lennart Poettering 97137ecce6 install: don't override caller's parameter 2013-11-08 14:07:27 +01:00
Daniel Buch fb15be8395 path_lookup: moved _cleanup_lookup_paths_free_ from install.c to path-lookup.h 2013-10-27 11:51:22 -04:00
Zbigniew Jędrzejewski-Szmek 1ca208fb4f Introduce udev object cleanup functions 2013-10-13 17:56:55 -04:00
Zbigniew Jędrzejewski-Szmek b47d419c25 Modernization
Fixes minor leak in error path in device.c.
2013-10-13 17:56:54 -04:00
Lennart Poettering 19f6d71077 specifier: rework specifier calls to return proper error message
Previously the specifier calls could only indicate OOM by returning
NULL. With this change they will return negative errno-style error codes
like everything else.
2013-09-17 10:06:50 -05:00
Zbigniew Jędrzejewski-Szmek 6c5a28255b systemd: fix NULL dereference when disabling a nonexistent instance
Assertion 'p' failed at src/shared/path-util.c:51, function path_get_file_name(). Aborting.

The unit file could not be found, and i->path would not be set.
In 02b9e969 a code path was added which attempts to remove symlinks
to a nonexistent (removed) unit file. This worked OK in case of
non-instance services, but broke in the case of instance services.

Behaviour wrt. to instance units is changed in the way that 02b9e969
changed it for non-instance units: it is now possible to remove
instance symlinks to a template unit that has been removed.

This patch isn't a full fix, because the behaviour wrt. to enabling
and disabling instance units is still broken: e.g it is possible to
start autovt@tty5.service, but it is not possible to enable it,
because autovt@.service is a symlink, and on the other hand, disabling
getty@tty5.service removes all symlinks to getty@.service, which is
wrong too. But segfaults make bad pr, so let's add at least this
partial fix for now.
2013-07-14 23:53:45 -04:00
Ross Lagerwall 92d430a9e0 install: make "reenable" work with templated units
Before, "systemctl reenable getty@tty1.service" would fail with:
Failed to issue method call: File exists
To fix this, reimplement "reenable" explicitly as a disable followed by
an enable.
This is shorter and is how the man page documents its behavior.
2013-07-13 07:56:11 -04:00
Zbigniew Jędrzejewski-Szmek d7b478b448 shared/install: fix trivial memleak
We lost the reference when setting path second time.
2013-07-12 13:24:06 -04:00
Zbigniew Jędrzejewski-Szmek 02b9e969a6 systemctl,core: allow nuking of symlinks to removed units
Before, one the unit file was deleted, install_context_for_removal()
would refuse to look for symlinks. But we can remove dangling symlinks
anyway.

In principle, package installation/deinstallation scripts should do
that before the unit is uninstalled, but they don't always do. Also,
a user might have added additional symlinks manually.

https://bugs.freedesktop.org/show_bug.cgi?id=62395
2013-06-03 13:55:17 -04:00
Václav Pavlín 99504dd4c1 systemctl: add commands set-default and get-default
systemctl set-default NAME links the default.target to the given unit,
get-default prints out the path to the currently set default target.
2013-05-30 20:44:41 -04:00
Michael Tremer 67820a0cbd systemctl: make systemctl is-enabled work for templated units
Patch resolves the problem that 'systemctl is-enabled' does
not work for templated units.

Without this patch, systemctl is-enabled something@abc.service
returned "No such file or directory", because it first checked
if /usr/lib/systemd/system/something@abc.service, etc. exists.
If systemctl is-enabled is called for templated units, this
check should be omitted and it should search for symlinks in
the .wants dirs right away.

This patch fixes the broken behaviour and resolves
  https://bugs.freedesktop.org/show_bug.cgi?id=55318.

[zj: fixed the patch to still check for broken symlinks and
     masked instances. Also removed untrue assumptions from
     the patch description.]
2013-05-21 09:23:51 -04:00
Lennart Poettering db5c012285 conf-parser: restrict .include usage
Disallow recursive .include, and make it unavailable in anything but
unit files.
2013-04-25 00:05:14 -03:00
Zbigniew Jędrzejewski-Szmek ef42202ac8 Add set_consume which always takes ownership
Freeing in error path is the common pattern with set_put().
2013-04-24 00:25:04 -04:00
Harald Hoyer 7fd1b19bc9 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-18 09:11:22 +02:00
Zbigniew Jędrzejewski-Szmek e8e581bf25 Report about syntax errors with metadata
The information about the unit for which files are being parsed
is passed all the way down. This way messages land in the journal
with proper UNIT=... or USER_UNIT=... attribution.

'systemctl status' and 'journalctl -u' not displaying those messages
has been a source of confusion for users, since the journal entry for
a misspelt setting was often logged quite a bit earlier than the
failure to start a unit.

Based-on-a-patch-by: Oleksii Shevchuk <alxchk@gmail.com>
2013-04-17 00:09:16 -04:00
Zbigniew Jędrzejewski-Szmek d3b6d0c21e fileio: in envfiles, do not skip lines following empty lines
https://bugs.freedesktop.org/show_bug.cgi?id=63477
2013-04-13 20:24:39 -04:00
Zbigniew Jędrzejewski-Szmek 7914d6bba4 Remove a few NULLs
Just {} is used in a lot of places now, and there's nothing
special abose those few.
2013-04-13 20:24:39 -04:00