Commit Graph

70 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek a13ee4c792 cgroup-util: shorten cg_path_get_session 2014-08-30 17:41:32 -04:00
Lennart Poettering 70c949a42b cgroup: never try to create files in cgroupfs, only open them for writing
This should have the benefit that cg_set_attribute() returns ENOENT
instead of EACCESS when we use it for non-existing attributes.
2014-08-15 11:57:07 +02: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 de0671ee7f Remove unnecessary casts in printfs
No functional change expected :)
2014-05-15 15:29:58 +02:00
Dave Reisner dbb9401dba condense assignment and path_kill_slashes calls 2014-04-21 09:52:08 -04:00
Josh Triplett f8294e4175 Use strlen even for constant strings
GCC optimizes strlen("string constant") to a constant, even with -O0.
Thus, replace patterns like sizeof("string constant")-1 with
strlen("string constant") where possible, for clarity.  In particular,
for expressions intended to add up the lengths of components going into
a string, this often makes it clearer that the expression counts the
trailing '\0' exactly once, by putting the +1 for the '\0' at the end of
the expression, rather than hidden in a sizeof in the middle of the
expression.
2014-03-16 09:52:56 -04:00
Jan Engelhardt 73e231abde doc: update punctuation
Resolve spotted issues related to missing or extraneous commas, dashes.
2014-02-17 19:03:07 -05:00
Lennart Poettering 03b90d4bad core: find the closest parent slice that has a specfic cgroup controller enabled when enabling/disabling cgroup controllers for units 2014-02-17 15:49:21 +01:00
Lennart Poettering 89f7c8465c machined: optionally, allow registration of pre-existing units (scopes
or services) as machine with machined
2014-02-11 17:16:08 +01:00
Lennart Poettering 6e8314c420 cgroup: make sure to properly send SIGCONT to all processes of a cgroup if that's requested 2014-02-07 15:14:36 +01:00
Lennart Poettering af08d2f9cd bus: add API calls for connecting to starter bus
Add new calls sd_bus_open() and sd_bus_default() for connecting to the
starter bus a service was invoked for, or -- if the process is not a
bus-activated service -- the appropriate bus for the scope the process
has been started in.
2014-01-27 21:34:54 +01:00
Simon Peeters b68fa010f7 shared: procfs_file_alloca: handle pid==0
when pid is set to 0 use /proc/self
2014-01-05 00:59:13 -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 751bc6ac79 bus: properly shift cgroup data returned from kdbus by the container's root before parsing 2013-12-24 19:31:44 +01:00
Zbigniew Jędrzejewski-Szmek d4fffc4b8b Fix extraction of _SYSTEMD_USER_UNIT
Units from user services underneath user@.service would not be detected
properly.
2013-12-22 18:55:01 -05:00
Shawn Landden ec202eae8e __thread --> thread_local for C11 compat
Also make thread_local available w/o including <threads.h>.
(as the latter hasn't been implemented, but this part is trivial)
2013-12-17 21:45:43 +01:00
Lennart Poettering e9174f29c7 journald: cache cgroup root path, instead of querying it on every incoming log message 2013-12-11 23:31:07 +01:00
Lennart Poettering 674eb68520 bus: add generator that turns old dbus1 activation files into .busname + .service units 2013-12-03 01:13:48 +01:00
Lennart Poettering 9588bc3209 Remove dead code and unexport some calls
"make check-api-unused" informs us about code that is not used anymore
or that is exported but only used internally. Fix these all over the
place.
2013-11-08 18:12:45 +01:00
Lennart Poettering 1434ae6fd4 cgroup: there's no point in labelling cgroupfs dirs, so let's not do that
This allows us to get rid of the dep on libsystemd-label for cgroup
management.

https://bugs.freedesktop.org/show_bug.cgi?id=69966
2013-10-02 04:59:05 +02:00
Lennart Poettering baa89da40a cgroup: when referencing cgroup controller trees allow omission of the path 2013-09-26 20:20:30 +02:00
Lennart Poettering fecffe5d0a util: add macro for iterating through all prefixes of a path
Syntactic sugar in a macro PATH_FOREACH_PREFIX.
2013-09-25 21:04:35 +02:00
Lennart Poettering 13b84ec7df cgroup: if we do a cgroup operation then do something on all supported controllers
Previously we did operations like attach, trim or migrate only on the
controllers that were enabled for a specific unit. With this changes we
will now do them for all supproted controllers, and fall back to all
possible prefix paths if the specified paths do not exist.

This fixes issues if a controller is being disabled for a unit where it
was previously enabled, and makes sure that all processes stay as "far
down" the tree as groups exist.
2013-09-25 03:38:17 +02:00
Zbigniew Jędrzejewski-Szmek 4b549144d8 Verify validity of session name when received from outside
Only ASCII letters and digits are allowed.
2013-09-16 09:58:37 -05:00
Lennart Poettering d7bd3de065 cgroup: simplify how instantiated units are mapped to cgroups
Previously for an instantiated unit foo@bar.service we created a cgroup
foo@.service/foo@bar.service, in order to place all instances of the
same template inside the same subtree. As we now implicitly add all
instantiated units into one per-template slice we don't need this
complexity anymore, and instance units can map directly to the cgroups
of their full name.
2013-07-11 18:49:53 +02:00
Lennart Poettering ac9ef33358 cgroup: when uninstalling agent, actually turn it off first 2013-07-10 23:47:15 +02:00
Kay Sievers ad929bcc27 disable the cgroups release agent when shutting down
During shutdown, when we try to clean up all remaining processes, the
kernel will fork new agents every time a cgroup runs empty. These
new processes cause delays in the final SIGTERM, SIGKILL logic.

Apart from that, this should also avoid that the kernel-forked binaries
cause unpredictably timed access to the filesystem which we might need to
unmount.
2013-07-04 20:31:18 +02:00
Lennart Poettering 374ec6abf3 libsystemd-logind: fix detection of session/user/machine of a PID 2013-07-02 02:34:15 +02:00
Lennart Poettering 6c12b52e19 core: add new "scope" unit type for making a unit of pre-existing processes
"Scope" units are very much like service units, however with the
difference that they are created from pre-existing processes, rather
than processes that systemd itself forks off. This means they are
generated programmatically via the bus API as transient units rather
than from static configuration read from disk. Also, they do not provide
execution-time parameters, as at the time systemd adds the processes to
the scope unit they already exist and the parameters cannot be applied
anymore.

The primary benefit of this new unit type is to create arbitrary cgroups
for worker-processes forked off an existing service.

This commit also adds a a new mode to "systemd-run" to run the specified
processes in a scope rather then a transient service.
2013-07-01 00:18:00 +02:00
Lennart Poettering 4ad490007b core: general cgroup rework
Replace the very generic cgroup hookup with a much simpler one. With
this change only the high-level cgroup settings remain, the ability to
set arbitrary cgroup attributes is removed, so is support for adding
units to arbitrary cgroup controllers or setting arbitrary paths for
them (especially paths that are different for the various controllers).

This also introduces a new -.slice root slice, that is the parent of
system.slice and friends. This enables easy admin configuration of
root-level cgrouo properties.

This replaces DeviceDeny= by DevicePolicy=, and implicitly adds in
/dev/null, /dev/zero and friends if DeviceAllow= is used (unless this is
turned off by DevicePolicy=).
2013-06-27 04:17:34 +02:00
Lennart Poettering 1021b21bc6 login: add an api to determine the slice a PID is located in to libsystemd-login 2013-06-21 01:46:27 +02:00
Lennart Poettering 9444b1f20e logind: add infrastructure to keep track of machines, and move to slices
- This changes all logind cgroup objects to use slice objects rather
  than fixed croup locations.

- logind can now collect minimal information about running
  VMs/containers. As fixed cgroup locations can no longer be used we
  need an entity that keeps track of machine cgroups in whatever slice
  they might be located. Since logind already keeps track of users,
  sessions and seats this is a trivial addition.

- nspawn will now register with logind and pass various bits of metadata
  along. A new option "--slice=" has been added to place the container
  in a specific slice.

- loginctl gained commands to list, introspect and terminate machines.

- user.slice and machine.slice will now be pulled in by logind.service,
  since only logind.service requires this slice.
2013-06-20 03:49:59 +02:00
Lennart Poettering a016b9228f core: add new .slice unit type for partitioning systems
In order to prepare for the kernel cgroup rework, let's introduce a new
unit type to systemd, the "slice". Slices can be arranged in a tree and
are useful to partition resources freely and hierarchally by the user.

Each service unit can now be assigned to one of these slices, and later
on login users and machines may too.

Slices translate pretty directly to the cgroup hierarchy, and the
various objects can be assigned to any of the slices in the tree.
2013-06-17 21:36:51 +02:00
Lennart Poettering b043cd0b7e cgroup: the "tasks" attribute is obsolete, cgroup.procs is the new replacement 2013-06-06 15:49:01 +02:00
Lennart Poettering a0ab566574 cgroup: when escaping a cgroup object name, also escape names that start with a dot 2013-05-03 19:06:06 +02:00
Zbigniew Jędrzejewski-Szmek 44a6b1b680 Add __attribute__((const, pure, format)) in various places
I'm assuming that it's fine if a _const_ or _pure_ function
calls assert. It is assumed that the assert won't trigger,
and even if it does, it can only trigger on the first call
with a given set of parameters, and we don't care if the
compiler moves the order of calls.
2013-05-02 22:52:09 -04:00
Zbigniew Jędrzejewski-Szmek 38158b920e cgls: add --machine/-M
cg_get_machine_path is modified to include the escaped machine name
+ ".nspawn" if the machine argument is nonnull.
2013-05-01 10:15:25 -04:00
Lennart Poettering 8af8afd6b3 cgroup: make cg_pid_get_path() work properly for co-mounted controllers and normalized named hierarchies 2013-04-30 08:36:01 -03:00
Lennart Poettering 5954c07433 cgroup: do not allow manipulating the cgroup path of units within the systemd:/system subtree 2013-04-30 08:36:01 -03:00
Zbigniew Jędrzejewski-Szmek 2a371001f8 Use attribute(unused) in PROTECT_ERRNO
clang emits warnings about unused attribute _saved_errno_, which drown
out other—potentially useful—warnings. gcc documentation is not exactly
verbose about the effects of __attribute__((unused)) on variables, but
let's assume that it works if the unit test passes.
2013-04-25 21:50:48 -04:00
Lennart Poettering 78edb35ab4 cgroup: always validate cgroup controller names
Let's better be safe than sorry.
2013-04-24 19:02:13 -03:00
Lennart Poettering ae018d9bc9 cgroup: make sure all our cgroup objects have a suffix and are properly escaped
Session objects will now get the .session suffix, user objects the .user
suffix, nspawn containers the .nspawn suffix.

This also changes the user cgroups to be named after the numeric UID
rather than the username, since this allows us the parse these paths
standalone without requiring access to the cgroup file system.

This also changes the mapping of instanced units to cgroups. Instead of
mapping foo@bar.service to the cgroup path /user/foo@.service/bar we
will now map it to /user/foo@.service/foo@bar.service, in order to
ensure that all our objects are properly suffixed in the tree.
2013-04-22 23:14:12 -03:00
Lennart Poettering aff38e74bd nspawn: suffix the nspawn cgroups with ".nspawn"
As discussed with Dan Berrange it's a good idea to suffix all objects in
the cgroup tree with ".something", so that when the system is
partitioned using a resource management tool we can drop objects of
different types into the same partition directory without generate
namespace conflicts.

We'l add this to the Pax Control Group document as soon as write access
to the fdo wiki is restored.
2013-04-22 23:14:12 -03: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
Lennart Poettering 7027ff61a3 nspawn: introduce the new /machine/ tree in the cgroup tree and move containers there
Containers will now carry a label (normally derived from the root
directory name, but configurable by the user), and the container's root
cgroup is /machine/<label>. This label is called "machine name", and can
cover both containers and VMs (as soon as libvirt also makes use of
/machine/).

libsystemd-login can be used to query the machine name from a process.

This patch also includes numerous clean-ups for the cgroup code.
2013-04-16 04:41:21 +02:00
Lennart Poettering 6c03089c32 bus: handle env vars safely
Make sure that our library is safe for usage in SUID programs when it
comes to env var handling
2013-04-15 14:05:03 +02:00
Lennart Poettering 2d76d14ea3 cgroup: clean-ups 2013-04-08 20:35:25 +02:00
Lennart Poettering 974efc4658 cgroup: always keep access mode of 'tasks' and 'cgroup.procs' files in cgroup directories in sync 2013-04-08 18:22:47 +02:00
Lennart Poettering 574d5f2dfc util: rename write_one_line_file() to write_string_file()
You can write much more than just one line with this call (and we
frequently do), so let's correct the naming.
2013-04-03 20:12:56 +02:00
Harald Hoyer a5c32cff1f honor SELinux labels, when creating and writing config files
Also split out some fileio functions to fileio.c and provide a SELinux
aware pendant in fileio-label.c

see https://bugzilla.redhat.com/show_bug.cgi?id=881577
2013-02-14 16:19:38 +01:00