Commit graph

12528 commits

Author SHA1 Message Date
Daniel Mack fcf554fd7a Merge pull request #1178 from poettering/gpt-auto-fixes
handle LUKS root partitions better in gpt-auto, plus other fixes
2015-09-07 12:28:34 +02:00
Martin Pitt b3a7ba8968 tests: Skip test-cgroup-util test_mask_supported() when not running under systemd
Commit 5f4c5fef6 introduced this new test case, but this does not work in
build chroots where cgroupfs is not mounted. So skip the test if systemd is not
running.
2015-09-07 08:09:13 +02:00
Tom Gundersen 5bac59d920 Merge pull request #1179 from poettering/sd-event-sigchld-fix
sd-event: make sure to create a signal queue for the right signal
2015-09-07 03:02:08 +02:00
Tom Gundersen 6167a91c74 Merge pull request #1165 from poettering/nspawn-files
various fixes to the core, logind, machined, nspawn
2015-09-07 02:59:08 +02:00
Lennart Poettering 10edebf6cd sd-event: make sure to create a signal queue for the right signal
We should never access the "signal" part of the event source unless the
event source is actually for a signal. In this case it's a child pid
handler however, hence make sure to use the right signal.

This is a fix for PR #1177, which in turn was a fix for
9da4cb2be2.
2015-09-07 00:31:24 +02:00
Lennart Poettering 4c3e8e39ea systemctl: a number of cleanups regarding error handling in systemctl 2015-09-07 00:12:05 +02:00
Lennart Poettering dd2c31bb04 gpt-auto: minor simplificatin handling the no-auto GPT flag
Let's query the flags only once, and document why we ignore it for the
ESP.
2015-09-07 00:12:05 +02:00
Lennart Poettering c6ba0c184d gpt-auto: try to handle LUKS root partitions better
If the root file system is located on an encrypted root disk, we'll not
find the GPT partition table for it. Let's fix that by following the
slaves/ symlinks in /sys for the device. We only handle devices having
exactly one backing device.

Also see: #1167
2015-09-07 00:11:51 +02:00
Thomas Hindoe Paaboel Andersen b8a50a99a6 sd-event: fix call to event_make_signal_data
This looks like a typo from commit 9da4cb2b where it was added.
2015-09-06 22:19:09 +02:00
Lennart Poettering 480a4b9777 Merge pull request #1153 from evverx/dot-alias-handling
analyze: add "alias" handling to dot subcommand
2015-09-06 12:34:09 +02:00
Evgeny Vereshchagin 83efb7c227 analyze: add "alias" handling to dot subcommand
`systemd-analyze dot default.target` works fine
2015-09-06 06:10:16 +03:00
Lennart Poettering 25b31f2fbd Merge pull request #1159 from AnchorCat/polkit-details/v2
Provide unit name and operation in manage-units polkit checks (v2)
2015-09-06 02:00:05 +02:00
Lennart Poettering 9efce95846 Merge pull request #1162 from dvdhrm/bus-recursive-nodes
sd-bus: make introspection data non-recursive
2015-09-06 01:58:48 +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 5f430ff76e machine: make sure to call unlockpt() even for local host pty connections
This fixes breakage for local host pty handling, introduced in
395745ba53.

Fixes #1139
2015-09-05 20:27:52 +02:00
Lennart Poettering 91b3e7fb6c logind: make scope of wall message handling smaller 2015-09-05 20:27:52 +02:00
Lennart Poettering 8ff4d2ab0d unit: make unit_can_start() more accurate
This funciton is exposed via CanStart on the bus, and should be as
accurate as possible. Hence: make sure to return false for units of unit
types not supported on the system, and for unit types where
configuration failed to load.

Also see #1105.
2015-09-05 20:27:52 +02:00
Lennart Poettering 9ce56418b1 core: don't use uninitialized errno 2015-09-05 20:27:52 +02:00
Lennart Poettering 7d10550305 machine: clarify that /var/lib/containers is legacy 2015-09-05 20:27:51 +02:00
David Herrmann 44eb1adda9 sd-bus: make introspection data non-recursive
Currently, our introspection data looks like this:

        <node>
         <interface name="org.freedesktop.DBus.Peer">
           ...
         </interface>
         <interface name="org.freedesktop.DBus.Introspectable">
           ...
         </interface>
         <interface name="org.freedesktop.DBus.Properties">
           ...
         </interface>
         <node name="org"/>
         <node name="org/freedesktop"/>
         <node name="org/freedesktop/login1"/>
         <node name="org/freedesktop/login1/user"/>
         <node name="org/freedesktop/login1/user/self"/>
         <node name="org/freedesktop/login1/user/_1000"/>
         <node name="org/freedesktop/login1/seat"/>
         <node name="org/freedesktop/login1/seat/self"/>
         <node name="org/freedesktop/login1/seat/seat0"/>
         <node name="org/freedesktop/login1/session"/>
         <node name="org/freedesktop/login1/session/self"/>
         <node name="org/freedesktop/login1/session/c1"/>
        </node>

(ordered alphabetically for better visibility)

This is grossly incorrect. The spec says that we're allowed to return
non-directed children, however, it does not allow us to return data
recursively in multiple parents. If we return "org", then we must not
return anything else that starts with "org/".

It is unclear, whether we can include child-nodes as a tree. Moreover, it
is usually not what the caller wants. Hence, this patch changes sd-bus to
never return introspection data recursively. Instead, only a single
child-layer is returned.

This patch relies on enumerators to never return hierarchies. If someone
registers an enumerator via sd_bus_add_enumerator, they better register
sub-enumerators if they support *TRUE* hierarchies. Each enumerator is
treated as a single layer and not filtered.
Enumerators are still allowed to return nested data. However, that data
is still required to be a single hierarchy. For instance, returning
"/org/foo" and "/com/bar" is fine, but including "/com" or "/org" in that
dataset is not.
This should be the default for enumerators and I see no reason to filter
in sd-bus. Moreover, filtering that data-set would require to sort the
strv by path and then do prefix-filtering. This is O(n log n), which
would be fine, but still better to avoid.

Fixes #664.
2015-09-05 19:43:29 +02:00
David Herrmann 64ce4ad758 sd-bus: derive uid from cgroup if possible
Whenever we run in a user context, sd_bus_{default_user,open_user}() and
friends should always connect to the user-bus of the current context,
instead of deriving the uid from getuid(). This allows us running
programs via sudo/su, without the nasty side-effect of accidentally
connecting to the root user-bus.

This patch enforces the idea of making su/sudo *not* opening sessions by
default. That is, all they do is raising privileges, but keeping
everything set as before. You can still use su/sudo to open real sessions
by requesting a login-session (or loading pam_systemd otherwise).
However, in this case XDG_RUNTIME_DIR= will not be set (as usual in these
cases), hence, you will not be able to connect to *any* user-bus.

Long story short: With this patch applied, both:
        - ./busctl --user
        - sudo ./busctl --user
..will successfully connect to the user-bus of the local user.

Fixes #390.
2015-09-05 18:07:53 +02:00
Michael Chapman 88ced61bf9 core: pass details to polkit for some unit actions
The following details are passed:

- unit: the primary name of the unit upon which the action was
        invoked (i.e. after resolving any aliases);
- verb: one of 'start', 'stop', 'reload', 'restart', 'try-restart',
        'reload-or-restart', 'reload-or-try-restart', 'kill',
        'reset-failed', or 'set-property', corresponding to the
        systemctl verb used to invoke the action.

Typical use of these details in a polkit policy rule might be:

  // Allow alice to manage example.service;
  // fall back to implicit authorization otherwise.
  polkit.addRule(function(action, subject) {
      if (action.id == "org.freedesktop.systemd1.manage-units" &&
          action.lookup("unit") == "example.service" &&
          subject.user == "alice") {
          return polkit.Result.YES;
      }
  });

We also supply a custom polkit message that includes the unit's name and
the requested operation.
2015-09-06 00:07:17 +10:00
Michael Chapman 403ed0e5c9 bus-util: support details in CheckAuthorization calls
Extra details for an action can be supplied when calling polkit's
CheckAuthorization method. Details are a list of key/value string pairs.
Custom policy can use these details when making authorization decisions.
2015-09-06 00:07:16 +10:00
David Herrmann 17258f5f27 Merge pull request #1140 from poettering/sd-event-signals
A variety of sd-event, sd-login and cgroup fixes
2015-09-05 15:20:21 +02:00
Lennart Poettering a67c56bff4 sd-login: minor header commenting improvements 2015-09-05 14:56:23 +02:00
Lennart Poettering f5aaf57562 sd-login: add new sd_pid_get_cgroup() API
This adds a new sd_pid_get_cgroup() call to sd-login which may be used
to query the control path of a process. This is useful for programs when
making use of delegation units, in order to figure out which subtree has
been delegated.

In light of the unified control group hierarchy this is finally safe to
do, hence let's add a proper API for it, to make it easier to use this.
2015-09-05 14:56:23 +02:00
Daniel Mack c7430c3d1a Merge pull request #1157 from dvdhrm/logind-wallfix
login: fix NULL-deref on wall_message
2015-09-05 14:33:56 +02:00
David Herrmann 3d1c455f9a login: fix NULL-deref on wall_message
We treat an empty wall-message equal to a NULL wall-message since:

        commit 5744f59a3e
        Author: Lennart Poettering <lennart@poettering.net>
        Date:   Fri Sep 4 10:34:47 2015 +0200

            logind: treat an empty wall message like a NULL one

Fix the shutdown scheduler to not deref a NULL pointer, but properly
check for an empty wall-message.

Fixes: #1120
2015-09-05 12:56:04 +02:00
Lennart Poettering 33ce5f6a0b Merge pull request #1149 from martinpitt/fix-dhcp-error-codes
networkd: adjust error codes for nonexisting DHCP data
2015-09-05 12:21:20 +02:00
Martin Pitt 397d15fd39 networkd: adjust error codes for nonexisting DHCP data
Commit 0339cd770 changed libsystemd-network's error code for missing DHCP lease
data from ENOENT to ENODATA. Adjust networkd accordingly.

This fixes interfaces being stuck in "degraded/configuring" mode forever.

https://github.com/systemd/systemd/issues/1147
2015-09-04 21:22:44 +02:00
Martin Pitt 3b3a64d754 tests: Skip tests which need to access /sys/fs/cgroup if that is not available
Commit efdb023 ("core: unified cgroup hierarchy support") introduced a new
error ENOEXEC in cg_unified() if /sys/fs/cgroup/ is not available. Adjust the
"skip" checks in various tests accordingly.

Add a corresponding "skip" check to test-bus-creds as well, as
sd_bus_creds_new_from_pid() now calls cg_unified() as well.

This re-fixes "make check" in build chroots without /sys/fs/cgroup.

https://github.com/systemd/systemd/issues/1132
2015-09-04 16:34:21 +02:00
Lennart Poettering 2cf088b56d logind: when parsing a boolean via sd-bus the type must be "int"
And not bool.
2015-09-04 10:36:08 +02:00
Lennart Poettering 5744f59a3e logind: treat an empty wall message like a NULL one 2015-09-04 10:34:47 +02:00
Lennart Poettering 19af675e99 cgroups: delegation to unprivileged services is safe in the unified hierarchy
Delegation to unpriviliged processes is safe in the unified hierarchy,
hence allow it. This has the benefit of permitting "systemd --user"
instances to further partition their resources between user services.
2015-09-04 09:23:07 +02:00
Lennart Poettering 707b66c663 sd-login: rework error handling
Makre sure we always return sensible errors for the various, following
the same rules, and document them in a comment in sd-login.c. Also,
update all relevant man pages accordingly.
2015-09-04 09:07:31 +02:00
Lennart Poettering 9da4cb2be2 sd-event: make sure RT signals are not dropped
RT signals operate in a queue, and we should be careful to never merge
two queued signals into one. Hence, makes sure we only ever dequeue a
single signal at a time and leave the remaining ones queued in the
signalfd. In order to implement correct priorities for the signals
introduce one signalfd per priority, so that we only process the highest
priority signal at a time.
2015-09-04 09:07:31 +02:00
Lennart Poettering 348637b28a test: add one more test case for parse_pid() 2015-09-04 09:07:31 +02:00
Lennart Poettering 98e4d8d763 nspawn: enable all controllers we can for the "payload" subcgroup we create
In the unified hierarchy delegating controller access is safe, hence
make sure to enable all controllers for the "payload" subcgroup if we
create it, so that the container will have all controllers enabled the
nspawn service itself has.
2015-09-04 09:07:31 +02:00
Lennart Poettering 5f4c5fef66 cgroup: always read the supported controllers from the root cgroup of the local container
Otherwise we might end up thinking that we support more controllers than
actually enabled for the container we are running in.
2015-09-04 09:07:31 +02:00
Lennart Poettering ba09d9c687 cgroup: fix potential access of uninitialized variable 2015-09-04 09:07:31 +02:00
Lennart Poettering 1c80e42512 cgroup-util: make cg_pid_get_path() return -ENODATA when controller can't be found
If the controller managed by systemd cannot found in /proc/$PID/cgroup,
return ENODATA, the usual error for cases where the data being looked
for does not exist, even if the process does.
2015-09-04 09:07:31 +02:00
Lennart Poettering 989189eabf cgroup: fix potential bad memory access 2015-09-04 09:07:31 +02:00
Lennart Poettering 9a66c87a23 cgroup: make sure cg_is_empty_recursive() returns 1 for non-existing cgroups
Previously, on the legacy hierarchy a non-existing cgroup was considered
identical to an empty one, but the unified hierarchy the check for a
non-existing one returned ENOENT.
2015-09-04 09:07:31 +02:00
Lennart Poettering b8725df8b3 cgroup: when comparing agent paths, use path_equal()
After all a path is a path is a path and we should use path_equal() to
comapre those.
2015-09-04 09:07:31 +02:00
Lennart Poettering d7e46e01ac audit: audit calls should return ENODATA when process are not in an audit session
ENODATA is how we usually indicate such "missing info" cases, so we
should do this here, too.
2015-09-04 09:07:31 +02:00
Lennart Poettering ef5c570edf util: document why parse_uid() returns ENXIO
parse_uid() returns EINVAL for invalid strings, but ENXIO for the
(uid_t) -1 user ids in order to distinguish these two cases. Document
this.
2015-09-04 09:07:31 +02:00
Lennart Poettering b3ac818be8 core: split up manager_get_unit_by_pid()
Let's move the actual cgroup part of it into a new separate function
manager_get_unit_by_pid_cgroup(), and then make
manager_get_unit_by_pid() just a wrapper that also checks the two pid
hashmaps.

Then, let's make sure the various calls that want to deliver events to
the owners of a PID check both hashmaps and the cgroup and deliver the
event to *each* of them. OTOH make sure bus calls like GetUnitByPID()
continue to check the PID hashmaps first and the cgroup only as
fallback.
2015-09-04 09:07:31 +02:00
Lennart Poettering 569b19d8fe cgroup: move controller to dirname translation into join_path_legacy()
Let's simplify things a bit.
2015-09-04 09:07:30 +02:00
Lennart Poettering a1f686daf5 util: add new uid_is_valid() call
This simply factors out the uid validation checks from parse_uid() and
uses them everywhere. This simply verifies that the passed UID is
neither 64bit -1 nor 32bit -1.
2015-09-04 09:07:30 +02:00
Lennart Poettering fea72cc033 macro: introduce new PID_TO_PTR macros and make use of them
This adds a new PID_TO_PTR() macro, plus PTR_TO_PID() and makes use of
it wherever we maintain processes in a hash table. Previously we
sometimes used LONG_TO_PTR() and other times ULONG_TO_PTR() for that,
hence let's make this more explicit and clean up things.
2015-09-04 09:07:30 +02:00