Commit Graph

82 Commits

Author SHA1 Message Date
Ronny Chevalier 0b452006de shared: add process-util.[ch] 2015-04-10 23:54:49 +02:00
Ronny Chevalier 6482f6269c shared: add formats-util.h 2015-04-10 23:54:48 +02:00
Lennart Poettering da00518b3f path-util: fix more path_is_mount e792e890f fallout 2015-04-07 16:03:45 +02: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
Luke Shumaker 3208148114 cg_path_get_user_unit(): Did not correctly parse user-unit templates.
It ran either skip_session() or skip_user_manager(), then ran skip_slices()
iff skip_session() ran.  It needs to run skip_slices() in either case.

Included is a test case demonstrating why.
2015-02-04 02:16:33 +01:00
Lennart Poettering 63c372cb9d util: rework strappenda(), and rename it strjoina()
After all it is now much more like strjoin() than strappend(). At the
same time, add support for NULL sentinels, even if they are normally not
necessary.
2015-02-03 02:05:59 +01:00
Lennart Poettering 934277fe6a core: add a property that shows the current memory usage of a unit
This is exposed the memory.usage_in_bytes cgroup property on the bus,
and makes "systemctl status" show it in its default output.
2015-01-23 03:00:15 +01:00
Lennart Poettering b12afc8c5c nspawn: mount most of the cgroup tree read-only in nspawn containers except for the container's own subtree in the name=systemd hierarchy
More specifically mount all other hierarchies in their entirety and the
name=systemd above the container's subtree read-only.
2015-01-05 01:40:51 +01:00
Lennart Poettering 7b3fd6313c scope: make attachment of initial PIDs a bit more robust 2014-12-10 22:06:44 +01:00
Ross Lagerwall dc8962da74 cgroup-util: Don't send SIGCONT after SIGKILL 2014-11-30 22:58:55 +01:00
Lennart Poettering fed1e721fd treewide: introduce UID_INVALID (and friends) as macro for (uid_t) -1 2014-11-28 20:55:04 +01: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
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