Commit graph

162 commits

Author SHA1 Message Date
Lennart Poettering a1e58e8ee1 tree-wide: use coccinelle to patch a lot of code to use mfree()
This replaces this:

        free(p);
        p = NULL;

by this:

        p = mfree(p);

Change generated using coccinelle. Semantic patch is added to the
sources.
2015-09-09 08:19:27 +02:00
Lennart Poettering d79200e26e unit: unify how we assing slices to units
This adds a new call unit_set_slice(), and simplifies
unit_add_default_slice(). THis should make our code a bit more robust
and simpler.
2015-08-31 13:20:43 +02:00
Lennart Poettering 21b735e798 core: add unit_dbus_interface_from_type() to unit-name.h
Let's add a way to get the type-specific D-Bus interface of a unit from
either its type or name to src/basic/unit-name.[ch]. That way we can
share it with the client side, where it is useful in tools like cgls or
machinectl.

Also ports over machinectl to make use of this.
2015-08-28 02:10:10 +02:00
Karel Zak 6f20f850f7 mount: remove obsolete -n
It seems that systemd still uses legacy -n option. The option has been
originally designed to avoid write to /etc/mtab during boot when root
FS is not ready or read-only.

This is not necessary for long time, because /etc/mtab is not a real
file (it's symlink) and write to the file is impossible. All utils
should be able to detect the symlink and ignore mtab. This concept is
supported for very long time before systemd.

The userspase mount options are currently maintained by libmount
(mount(8) and mount.nfs) in /run/mount) which is tmpfs initialized
during early boot.
2015-07-28 11:31:45 +02:00
Michal Schmidt c382d69e3d core: remove generic job completion messages from unit vtables
These units' message format strings are identical to the generic
strings. Since we can always rely on the fallback, these are now
redundant.
2015-07-21 19:24:20 +02:00
Michal Schmidt 2d018ae23b core: correct return value from reload methods
Return 1 from *_reload() methods to signify "we did something", just
like in *_start(). This causes "Reloading foo..." messages to be logged.
"Reloaded foo." messages are already logged.
2015-07-21 15:09:12 +02:00
Daniel Mack c0a7f8d3cb core/mount: skip incomplete mountinfo entries
Skip /proc/mountinfo entries for which libmount returns a NULL pointer
for 'source' or 'target'. This happened on Semaphore CI's build servers
when the test suite is run.
2015-06-04 19:00:46 +02:00
Lennart Poettering 394763f63c mount: properly check for mounts currently in /proc/self/mountinfo
http://lists.freedesktop.org/archives/systemd-devel/2015-May/032059.html
2015-05-19 17:19:27 +02:00
Lennart Poettering fcd8b266ed mount: don't claim a device is gone from /proc/self/mountinfo before it is gone from *all* lines
Devices might be referenced by multiple mount points in
/proc/self/mountinfo, hence we should consider them unmounted only after
they disappeared from all lines, not just from one.

http://lists.freedesktop.org/archives/systemd-devel/2015-May/032026.html
2015-05-19 13:50:36 +02:00
Dimitri John Ledkov f00929ad62 Default to /usr/bin/u?mount, configurable, rather than hard-coded /bin/u?mount. 2015-05-13 15:48:28 +02:00
Lennart Poettering 7ba2711d3f core: never create device depencies for /dev/root mounts
http://lists.freedesktop.org/archives/systemd-devel/2015-May/031658.html
2015-05-13 14:40:37 +02:00
Lennart Poettering b2c23da8ce core: rename SystemdRunningAs to ManagerRunningAs
It's primarily just a property of the Manager object after all, and we
try to refer to PID 1 as "manager" instead of "systemd", hence let's to
stick to this here too.
2015-05-11 22:51:49 +02:00
Lennart Poettering 8b4305c735 unit: move unit_warn_if_dir_nonempty() and friend to unit.c
The call is only used by the mount and automount unit types, but that's
already enough to consider it generic unit functionality, hence move it
out of mount.c and into unit.c.
2015-05-11 22:28:52 +02:00
Lennart Poettering f2341e0a87 core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.

Also contains a couple of other logging improvements:

- Drops a couple of strerror() invocations in favour of using %m.

- Not only .mount units now warn if a symlinks exist for the mount
  point already, .automount units do that too, now.

- A few invocations of log_struct() that didn't actually pass any
  additional structured data have been replaced by simpler invocations
  of log_unit_info() and friends.

- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
  that works like LOG_MESSAGE() but prefixes the message with the unit
  name. Similar, there's now LOG_LINK_MESSAGE() and
  LOG_NETDEV_MESSAGE().

- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
  LOG_NETDEV_INTERFACE() macros have been added that generate the
  necessary per object fields. The old log_unit_struct() call has been
  removed in favour of these new macros used in raw log_struct()
  invocations. In addition to removing one more function call this
  allows generated structured log messages that contain two object
  fields, as necessary for example for network interfaces that are
  joined into another network interface, and whose messages shall be
  indexed by both.

- The LOG_ERRNO() macro has been removed, in favour of
  log_struct_errno(). The latter has the benefit of ensuring that %m in
  format strings is properly resolved to the specified error number.

- A number of logging messages have been converted to use
  log_unit_info() instead of log_info()

- The client code in sysv-generator no longer #includes core code from
  src/core/.

- log_unit_full_errno() has been removed, log_unit_full() instead takes
  an errno now, too.

- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
  avoid double evaluation of their parameters
2015-05-11 22:24:45 +02:00
Lennart Poettering 6f856a0992 core: always initialize ExecParamters.bus_endpoint_fd to -1
Otherwise it might be passed in as 0, which is a valid fd, but usually
does not refer to a real endpoint.
2015-05-11 22:18:21 +02:00
Lennart Poettering 7410616cd9 core: rework unit name validation and manipulation logic
A variety of changes:

- Make sure all our calls distuingish OOM from other errors if OOM is
  not the only error possible.

- Be much stricter when parsing escaped paths, do not accept trailing or
  leading escaped slashes.

- Change unit validation to take a bit mask for allowing plain names,
  instance names or template names or an combination thereof.

- Refuse manipulating invalid unit name
2015-05-05 15:06:42 -07:00
Tom Gundersen 7dfbe2e3fc core: annotate event sources 2015-04-29 17:08:31 +02:00
Lennart Poettering be847e82cf Revert "core: do not spawn jobs or touch other units during coldplugging"
This reverts commit 6e392c9c45.

We really shouldn't invent external state keeping hashmaps, if we can
keep this state in the units themselves.
2015-04-24 15:51:10 +02:00
Michael Olbrich deb0a77cf0 automount: add expire support 2015-04-21 20:23:41 +02:00
Ronny Chevalier 6482f6269c shared: add formats-util.h 2015-04-10 23:54:48 +02:00
Lennart Poettering 527b7a421f util: rework cunescape(), improve error handling
Change cunescape() to return a normal error code, so that we can
distuingish OOM errors from parse errors.

This also adds a flags parameter to control whether "relaxed" or normal
parsing shall be done. If set no parse failures are generated, and the
only reason why cunescape() can fail is OOM.
2015-04-07 15:42:25 +02:00
Michal Sekletar 340a1d2330 mount: fix up wording in the comment 2015-04-01 13:08:25 +02:00
Lukas Nykryn 11041c8488 mount: don't run quotaon only for network filesystems
If you have for example ext4 on iscsi devices it is possible to setup
qoutas there. Unfortunately, because such fstab entry contains _netdev,
systemd will not add dependency to quotaon.service.
2015-04-01 12:16:53 +02:00
Ivan Shapovalov 6e392c9c45 core: do not spawn jobs or touch other units during coldplugging
Because the order of coldplugging is not defined, we can reference a
not-yet-coldplugged unit and read its state while it has not yet been
set to a meaningful value.

This way, already active units may get started again.

We fix this by deferring such actions until all units have been at
least somehow coldplugged.

Fixes https://bugs.freedesktop.org/show_bug.cgi?id=88401
2015-03-07 08:44:57 -05:00
Lennart Poettering 5ad096b3f1 core: expose consumed CPU time per unit
This adds support for showing the accumulated consumed CPU time per-unit
in the "systemctl status" output. The property is also readable via the
bus.
2015-03-02 12:15:25 +01:00
Lennart Poettering 628c89cc68 core: rework device state logic
This change introduces a new state "tentative" for device units. Device
units are considered "plugged" when udev announced them, "dead" when
they are not available in the kernel, and "tentative" when they are
referenced in /proc/self/mountinfo or /proc/swaps but not (yet)
announced via udev.

This should fix a race when device nodes (like loop devices) are created
and immediately mounted. Previously, systemd might end up seeing the
mount unit before the device, and would thus pull down the mount because
its BindTo dependency on the device would not be fulfilled.
2015-02-28 17:38:38 +01: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
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
Martin Pitt 06e9788888 core/mount: add dependencies to dynamically mounted mounts too
Add unit dependencies for dynamic (i. e. not from fstab) mounts. With that,
mount units properly bind to their underlying device, and thus get
automatically stopped/unmounted when the underlying device goes away.

This cleans up stale mounts from unplugged devices.

Thanks to Lennart Poettering for pointing out the fix!
2015-01-28 17:02:28 +01:00
Lennart Poettering 82a2b6bb5e core: output unit status output strings to console, only if we actually are changing unit state
Unit _start() and _stop() implementations can fail with -EAGAIN to delay
execution temporarily. Thus, we should not output status messages before
invoking these calls, but after, and only when we know that the
invocation actually made a change.
2015-01-28 15:07:13 +01:00
Lennart Poettering 874d3404cb core,shutdown: don't bother with unmounting any mounts below /sys, /proc, /dev when shutting down
After all, mounts below these directories are pretty much guaranteed to
be virtual, and it's hence unnecessary to unmount them during shutdown.
Moreover, in less-priviliged containers we might lack the rights to
unmount them, hence don't even try.

http://lists.freedesktop.org/archives/systemd-devel/2015-January/027113.html
2015-01-23 13:47:41 +01:00
Zbigniew Jędrzejewski-Szmek 76c37ab6d2 core/mount: remove "fail" again
deb6120920 'man: there's actually no "fail" fstab option, but only
"nofail" removed it from our documentation, which I missed.
fstab(5) only mentions "auto", "noauto", and "nofail". Stick to
those three.
2015-01-12 12:16:38 -05:00
Daniel Mack 0c47569ac9 core/mount: use isempty() to check for empty strings
strempty() will return an empty string in case the input parameter is
a NULL pointer. The correct test to check for an empty string is
isempty(), so use that instead.

This fixes a regression from commit 17a1c59 ("core/mount: filter out
noauto,auto,nofail,fail options").
2015-01-12 14:01:45 +01:00
Zbigniew Jędrzejewski-Szmek 17a1c597c5 core/mount: filter out noauto,auto,nofail,fail options
We passed the full option string from fstab to /bin/mount. It would in
turn pass the full option string to its helper, if it needed to invoke
one. Some helpers would ignore things like "nofail", but others would
be confused. We could try to get all helpers to ignore those
"meta-options", but it seems better to simply filter them out.

In our model, /bin/mount simply has no business in knowing whether the
mount was configured as fail or nofail, auto or noauto, in the
fstab. If systemd tells invokes a command to mount something, and it
fails, it should always return an error. It seems cleaner to filter
out the option, since then there's no doubt how the command should
behave.

https://bugzilla.redhat.com/show_bug.cgi?id=1177823
2015-01-11 23:41:42 -05:00
Zbigniew Jędrzejewski-Szmek d15d0333be Add new function to filter fstab options
This fixes parsing of options in shared/generator.c. Existing code
had some issues:

- it would treate whitespace and semicolons as seperators. fstab(5)
  is pretty clear that only commas matter. And the syntax does
  not allow for spaces to be inserted in the field in fstab.
  Whitespace might be escaped, but then it should not seperate
  options. Treat whitespace and semicolons as any other character.
- it assumed that x-systemd.device-timeout would always be followed
  by "=". But this is not guaranteed, hasmntopt will return this
  option even if there's no value. Uninitialized memory could be read.
- some error paths would log, and inconsistently, some would just
  return an error code.

Filtering is split out to a separate function and tests are added.

Similar code paths in other places are adjusted to use the new function.
2015-01-11 23:41:41 -05:00
Zbigniew Jędrzejewski-Szmek e86b3761c4 mount: do not use -n when running in --user mode
-n is only allowed for root. /etc/mtab is nowadays almost always a link to /proc/,
so in practice this does not really matter too much, but should allow .mount units
to work in --user mode.

https://bugs.freedesktop.org/show_bug.cgi?id=87602
2015-01-01 14:39:21 -05:00
Shawn Paul Landden 0254e9448f util: fix strict aliasing violations in use of struct inotify_event v5
There is alot of cleanup that will have to happen to turn on
-fstrict-aliasing, but I think our code should be "correct" to the rule.
2014-12-24 16:53:04 +01:00
Lennart Poettering 0faacd470d unit: handle nicely of certain unit types are not supported on specific systems
Containers do not really support .device, .automount or .swap units;
Systems compiled without support for swap do not support .swap units;
Systems without kdbus do not support .busname units.

With this change attempts to start a unsupported unit types will result
in an immediate "unsupported" job result, which is a lot more
descriptive then before. Also, attempts to start device units in
containers will now immediately fail instead of causing jobs to be
enqueued that never go away.
2014-12-15 19:02:17 +01:00
Lennart Poettering 7d54a03a87 core: retry unmounting until we are done, in case of stacked mounts 2014-12-12 20:12:35 +01:00
Lennart Poettering 96aad8d15a sd-bus: move common errors src/shared/bus-errors.h → src/libsystemd/sd-bus/bus-common-errors.h
Stuff in src/shared/ should not use stuff from src/libsystemd/ really.
2014-12-10 19:07:48 +01:00
Lennart Poettering b730764239 mount: clarify that we really need to replace the utab inotify code with the native API for this in libmount, as soon as that's stable 2014-12-10 01:48:39 +01:00
Lennart Poettering f7c1ad4fd4 core: unify how we iterate over inotify events
Let's add some syntactic sugar for iterating through inotify events, and
use it everywhere.
2014-12-10 01:48:39 +01:00
Lennart Poettering df63dda6d4 mount: use bools where appropriate 2014-12-10 01:48:39 +01:00
Zbigniew Jędrzejewski-Szmek 4e920142cc mount: use DEFINE_TRIVIAL_CLEANUP_FUNC 2014-11-28 17:04:54 -05:00
Zbigniew Jędrzejewski-Szmek e6a7b9f455 mount: constify MountParameters 2014-11-28 14:30:50 -05:00
Zbigniew Jędrzejewski-Szmek fddf1a3189 mount: deal with inotify queue overflow
Overflow is very unlikely, since we are watching a privileged directory,
but could be triggered if thousands of mounts are suddently executed.
2014-11-28 14:30:50 -05:00
Zbigniew Jędrzejewski-Szmek 90598531b0 mount: create directory before adding watches on it 2014-11-28 14:30:50 -05:00
Zbigniew Jędrzejewski-Szmek 5cca8defd2 mount: be more careful about errors when parsing mtab
Fixup for 4a3a9ef610.
2014-11-28 14:30:50 -05:00
Zbigniew Jędrzejewski-Szmek 9d05dd2e1e mount: simplify mount_needs_network check 2014-11-28 14:30:50 -05:00
Chris Leech affc3d8343 mount: check options as well as fstype for network mounts
When creating a new mount unit after an event on /proc/self/mountinfo,
check the mount options as well as the fstype to determine if this is a
remote mount that requires network access.
2014-11-28 14:30:50 -05:00