Commit Graph

812 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek be8386a3e5 systemctl: remove empty line between comment and action
It's harder to miss the comment without the newline ;)
See https://github.com/systemd/systemd/pull/3336#issuecomment-221749423
for context.
2016-05-28 11:48:59 -04:00
Zbigniew Jędrzejewski-Szmek 6f79340136 Merge pull request #3336 from eworm-de/systemctl-set-default
systemctl: return success for set-default, add-wants, add-requires...
2016-05-28 10:52:06 -04:00
Tejun Heo da4d897e75 core: add cgroup memory controller support on the unified hierarchy (#3315)
On the unified hierarchy, memory controller implements three control knobs -
low, high and max which enables more useable and versatile control over memory
usage.  This patch implements support for the three control knobs.

* MemoryLow, MemoryHigh and MemoryMax are added for memory.low, memory.high and
  memory.max, respectively.

* As all absolute limits on the unified hierarchy use "max" for no limit, make
  memory limit parse functions accept "max" in addition to "infinity" and
  document "max" for the new knobs.

* Implement compatibility translation between MemoryMax and MemoryLimit.

v2:

- Fixed missing else's in config_parse_memory_limit().
- Fixed missing newline when writing out drop-ins.
- Coding style updates to use "val > 0" instead of "val".
- Minor updates to documentation.
2016-05-27 18:10:18 +02:00
Christian Hesse 85b78539c9 systemctl: fix code path (and memory leak) on error 2016-05-27 09:33:27 +02:00
Christian Hesse 5f056378b0 systemctl: fix return values on success 2016-05-27 09:32:41 +02:00
Christian Hesse 7f30799ade systemctl: remove extra comma 2016-05-27 09:21:02 +02:00
Christian Hesse acc0269cad {machine,system}ctl: always pass &changes and &n_changes (#3350)
We have to pass addresses of changes and n_changes to
bus_deserialize_and_dump_unit_file_changes(). Otherwise we are hit by
missing information (subsequent calls to unit_file_changes_add() to
not add anything).

Also prevent null pointer dereference in
bus_deserialize_and_dump_unit_file_changes() by asserting.

Fixes #3339
2016-05-26 15:57:37 +02:00
Lennart Poettering f9e26ecc48 Merge pull request #3290 from htejun/cgroup2-io-compat
Implement compat translation between IO* and BlockIO* settings
2016-05-20 18:53:11 +02:00
Zbigniew Jędrzejewski-Szmek 35b132e8ad systemctl: suppress no-[Install] hint when --quiet is used (#3295)
https://bugzilla.redhat.com/show_bug.cgi?id=1336960
2016-05-19 22:08:41 +03:00
Franck Bui 823e5fabb7 systemctl: reload configuration when enabling sysv units too (#3297)
After enabling/disabling a unit, the daemon configuration is expected
to be unless '--no-reload' option is passed.

However this is not done when enabling a sysv units. This can lead to
the following scenario:

   $ cp /etc/init.d/named /etc/init.d/foo
   $ systemctl enable foo
   foo.service is not a native service, redirecting to systemd-sysv-install
   Executing /usr/lib/systemd/systemd-sysv-install enable foo
   $ systemctl start foo
   Failed to start foo.service: Unit foo.service failed to load: No such file or directory.

This can also be seen after installing a package providing a sysv
service: the service can't be started unless 'daemon-reload' is called
manually. This shouldn't be needed and this patch will fix this case
too since during package installation, the service is expected to be
enabled/disabled.
2016-05-19 10:37:04 -04:00
tblume f3f054f03e systemctl: restore the no-sync option for legacy halt (#3249)
The sync() call on shutdown had been removed with commit 57371e5829
together with the no-sync option for the shutdown commands.
The sync call was restored in commit 4a3ad39957 but the no-sync option
wasn't re-added.
I think we should restore this option at least for the legacy halt command.
2016-05-19 10:35:27 -04:00
Tejun Heo 9be572497d core: introduce CGroupIOLimitType enums
Currently, there are two cgroup IO limits, bandwidth max for read and write,
and they are hard-coded in various places.  This is fine for two limits but IO
is expected to grow more limits - low, high and max limits for bandwidth and
IOPS - and hard-coding each limit won't make sense.

This patch replaces hard-coded limits with an array indexed by
CGroupIOLimitType and accompanying string and default value tables so that new
limits can be added trivially.
2016-05-18 13:50:56 -07:00
Lennart Poettering 3103459e90 Merge pull request #3193 from htejun/cgroup-io-controller
core: add io controller support on the unified hierarchy
2016-05-16 22:05:27 +02:00
Zbigniew Jędrzejewski-Szmek 323b7dc903 tree-wide: rename draw_special_char to special_glyph
That function doesn't draw anything on it's own, just returns a string, which
sometimes is more than one character. Also remove "DRAW_" prefix from character
names, TREE_* and ARROW and BLACK_CIRCLE are unambigous on their own, don't
draw anything, and are always used as an argument to special_glyph().

Rename "DASH" to "MDASH", as there's more than one type of dash.
2016-05-09 15:17:57 -04:00
Zbigniew Jędrzejewski-Szmek 11690bcc50 systemctl: do not print header if no units will be listed
"0 units listed." is still printed.
2016-05-07 11:35:34 -04:00
Zbigniew Jędrzejewski-Szmek 0da999fada systemctl: rewrite code to explicitly take care of n_units==0 case
Coverity was complaing, but it was a false positive (CID #1354669).
Nevertheless, it's better to rewrite the code so that units is never
null.
2016-05-07 11:35:33 -04:00
Lennart Poettering baa9ecc1ee systemctl: indentation fix 2016-05-06 16:58:01 +02:00
Tejun Heo 13c31542cc core: add io controller support on the unified hierarchy
On the unified hierarchy, blkio controller is renamed to io and the interface
is changed significantly.

* blkio.weight and blkio.weight_device are consolidated into io.weight which
  uses the standardized weight range [1, 10000] with 100 as the default value.

* blkio.throttle.{read|write}_{bps|iops}_device are consolidated into io.max.
  Expansion of throttling features is being worked on to support
  work-conserving absolute limits (io.low and io.high).

* All stats are consolidated into io.stats.

This patchset adds support for the new interface.  As the interface has been
revamped and new features are expected to be added, it seems best to treat it
as a separate controller rather than trying to expand the blkio settings
although we might add automatic translation if only blkio settings are
specified.

* io.weight handling is mostly identical to blkio.weight[_device] handling
  except that the weight range is different.

* Both read and write bandwidth settings are consolidated into
  CGroupIODeviceLimit which describes all limits applicable to the device.
  This makes it less painful to add new limits.

* "max" can be used to specify the maximum limit which is equivalent to no
  config for max limits and treated as such.  If a given CGroupIODeviceLimit
  doesn't contain any non-default configs, the config struct is discarded once
  the no limit config is applied to cgroup.

* lookup_blkio_device() is renamed to lookup_block_device().

Signed-off-by: Tejun Heo <htejun@fb.com>
2016-05-05 16:43:06 -04:00
Lennart Poettering 87ec20ef20 core: fix detection whether per-unit drop-ins changed
This fixes fall-out from 6d10d308c6.

Until that commit, do determine whether a daemon reload was required we compare
the mtime of the main unit file we loaded with the mtime of it on disk for
equality, but for drop-ins we only stored the newest mtime of all of them and
then did a "newer-than" comparison. This was brokeni with the above commit,
when all checks where changed to be for equality.

With this change all checks are now done as "newer-than", fixing the drop-in
mtime case. Strictly speaking this will not detect a number of changes that the
code before above commit detected, but given that the mtime is unlikely to go
backwards, and this is just intended to be a helpful hint anyway, this looks OK
in order to keep things simple.

Fixes: #3123
2016-05-02 15:10:24 +02:00
kayrus 313fe66fbd core: Filter by unit name behind the D-Bus, instead on the client side (#3142)
This commit improves systemd performance on the systems which have
thousands of units.
2016-04-29 15:59:51 +02:00
Lennart Poettering f8591ee1b6 systemctl: add two minor assert()s 2016-04-22 16:06:20 +02:00
Lennart Poettering 0ff308c8de shared: drop kernel_thread bool from cgroups show code
Make this an output flag instead, so that our function prototypes can lose one
parameter
2016-04-22 16:06:20 +02:00
Lennart Poettering 291d565a04 core,systemctl: add bus API to retrieve processes of a unit
This adds a new GetProcesses() bus call to the Unit object which returns an
array consisting of all PIDs, their process names, as well as their full cgroup
paths. This is then used by "systemctl status" to show the per-unit process
tree.

This has the benefit that the client-side no longer needs to access the
cgroupfs directly to show the process tree of a unit. Instead, it now uses this
new API, which means it also works if -H or -M are used correctly, as the
information from the specific host is used, and not the one from the local
system.

Fixes: #2945
2016-04-22 16:06:20 +02:00
Zbigniew Jędrzejewski-Szmek 39207373dd systemctl,pid1: do not warn about missing install info with "preset"
When "preset" was executed for a unit without install info, we'd warn similarly
as for "enable" and "disable". But "preset" is usually called for all units,
because the preset files are provided by the distribution, and the units are under
control of individual programs, and it's reasonable to call "preset" for all units
rather then try to do it only for the ones that can be installed.
We also don't warn about missing info for "preset-all". Thus it seems reasonable
to silently ignore units w/o install info when presetting.

(In addition, when more than one unit was specified, we'd issue the warning
only if none of them had install info. But this is probably something to fix
for enable/disable too.)
2016-04-21 20:04:21 -04:00
Franck Bui 409472cb8c systemctl: hide "following" units if '--all' is not passed (#2967)
No need to dump all the redundant device units on the user, just because he
specified that he wants to see units of a specific state.

This was broken by commit ebc962656c.
2016-04-19 21:18:17 -04:00
Zbigniew Jędrzejewski-Szmek fe4aede922 systemctl: warning about missing install info for template units
The advice string didn't talk about template units at all. Extend
it and print when trying to enable a template unit without install info.

Fixes #2345.
2016-04-19 09:03:47 -04:00
Zbigniew Jędrzejewski-Szmek af3d811352 shared/install,systemctl,core: report offending file on installation error
Fixes #2191:

$ systemctl --root=/ enable sddm
Created symlink /etc/systemd/system/display-manager.service, pointing to /usr/lib/systemd/system/sddm.service.
$ sudo build/systemctl --root=/ enable gdm
Failed to enable unit, file /etc/systemd/system/display-manager.service already exists and is a symlink to /usr/lib/systemd/system/sddm.service.
$ sudo build/systemctl --root= enable sddm
$ sudo build/systemctl --root= enable gdm
Failed to enable unit: File /etc/systemd/system/display-manager.service already exists and is a symlink to /usr/lib/systemd/system/sddm.service.

(I tried a few different approaches to pass the error information back to the
caller. Adding a new parameter to hold the error results in a gigantic patch
and a lot of hassle to pass the args arounds. Adding this information to the
changes array is straightforward and can be more easily extended in the
future.)

In case local installation is performed, the full set of errors can be reported
and we do that. When running over dbus, only the first error is reported.
2016-04-19 08:58:00 -04:00
Zbigniew Jędrzejewski-Szmek 596fc2636a Various formatting and style fixes 2016-04-18 23:35:51 -04:00
Zbigniew Jędrzejewski-Szmek 9a0a413a19 systemctl/core: ignore masked units in preset-all
With any masked unit that would that would be enabled by presets, we'd get:

test@rawhide $ sudo systemctl preset-all
Failed to execute operation: Unit file is masked.

test@rawhide $ sudo systemctl --root=/ preset-all
Operation failed: Cannot send after transport endpoint shutdown

Simply ignore those units:

test@rawhide $ sudo systemctl preset-all
Unit xxx.service is masked, ignoring.
2016-04-16 21:51:09 -04:00
Zbigniew Jędrzejewski-Szmek 76ec966f0e tree-wide: use ERFKILL instead of ESHUTDOWN for "unit masked"
If the error code ever leaks (we print the strerror error instead of providing
our own), the message for ESHUTDOWN is "Cannot send after transport endpoint
shutdown", which can be misleading. In particular it suggest that some
mishandling of the dbus connection occured. Let's change that to ERFKILL which
has the advantage that a) it sounds implausible as actual error, b) has the
connotation of disabling something manually.
2016-04-16 18:41:34 -04:00
Zbigniew Jędrzejewski-Szmek bac75eb378 systemctl: make --root=/ disable dbus again
Before 0f03c2a4c0 specifying any path would cause the systemctl client
to do the installation itself, instead of going over dbus. Restore that
behaviour.
2016-04-16 17:41:46 -04:00
Zbigniew Jędrzejewski-Szmek 78df0edc1b systemctl: fix leak
CID #1354670.
2016-04-13 21:11:28 -04:00
Zbigniew Jędrzejewski-Szmek 81d621034b tree-wide: remove useless NULLs from strjoina
The coccinelle patch didn't work in some places, I have no idea why.
2016-04-13 08:56:44 -04:00
Lennart Poettering 3c6d8e57e8 systemctl: when we want to know whether there's a native unit file, don't choke on ELOOP
ELOOP indicates that there's a symlink in /etc for a native unit file, and
that's completely OK.
2016-04-12 16:19:57 +02:00
Lennart Poettering 8e20adcaa0 core: make sure we generate a nicer error when a linked unit is attempted to be enabled
We don't allow using config symlinks to enable units, but the error message we
printed was awful. Fix that, and generate a more readable error.

Fixes #3010.
2016-04-12 13:43:33 +02:00
Lennart Poettering 344ca7556b core,systemctl: add new "systemctl revert" command
This allows dropping all user configuration and reverting back to the vendor
default of a unit file. It basically undoes what "systemctl edit", "systemctl
set-property" and "systemctl mask" do.
2016-04-12 13:43:32 +02:00
Lennart Poettering 4943d14306 systemctl: don't confuse sysv code with generated units
The SysV compat code checks whether there's a native unit file before looking
for a SysV init script. Since the newest rework generated units will show up in
the unit path, and hence the checks ended up assuming that there always was a
native unit file for each init script: the generated one.

With this change the generated unit file directory is suppressed from the
search path when this check is done, to avoid the confusion.
2016-04-12 13:43:32 +02:00
Lennart Poettering c61b443d32 systemctl: add error message when we get unexpected event from waitid()
We should log about everything we don't expect.

Also, add a comment for one case were we do not log, on purpose, and make it
use a separate error code.
2016-04-12 13:43:32 +02:00
Lennart Poettering cc7cb0ca90 systemctl: fix incorrect errno for error message 2016-04-12 13:43:32 +02:00
Lennart Poettering e735decc38 systemctl: move check whether a service exists as native unit file to install.c
Move the search path check from the SysV service compat support into install.c
so that we can reuse the usual algorithm instead of rolling a private loop for
this.
2016-04-12 13:43:32 +02:00
Lennart Poettering 27c06cb516 core: rework reboot parameter logic a bit
Always warn if something fails, and clarify that the involved utility functions
do so in their name.

Drop the REBOOT_PARAM_FILE macro. We don't do this for other flag file paths
like this, so don't do this for this one either. The path isn't configurable
anyway, hence let's make this easier to read by avoiding this one indirection.
2016-04-12 13:43:32 +02:00
Lennart Poettering e4fca67ff0 install: introduce a new unit file state "transient"
Now, that the search path logic knows the unit path for transient units we also
can introduce an explicit unit file state "transient" that clarifies to the
user what kind of unit file he is encountering.
2016-04-12 13:43:31 +02:00
Lennart Poettering 463d0d1569 core: remove ManagerRunningAs enum
Previously, we had two enums ManagerRunningAs and UnitFileScope, that were
mostly identical and converted from one to the other all the time. The latter
had one more value UNIT_FILE_GLOBAL however.

Let's simplify things, and remove ManagerRunningAs and replace it by
UnitFileScope everywhere, thus making the translation unnecessary. Introduce
two new macros MANAGER_IS_SYSTEM() and MANAGER_IS_USER() to simplify checking
if we are running in one or the user context.
2016-04-12 13:43:30 +02:00
Lennart Poettering c51932be73 systemctl: port systemctl over to the new LookupPaths configuration directory fields 2016-04-12 13:43:30 +02:00
Lennart Poettering 7bfe3d44d0 core: when enabling a generated unit file, return a clean error
Let's be precise when the user tries to invoke an "enable" operation on a
generated unit file.
2016-04-12 13:43:29 +02:00
Lennart Poettering f413930863 core: add a new unit file state "generated"
Now that we store the generator directories in LookupPaths we can use this to
intrdouce a new unit file state called "generated", for units in these
directories.

Fixes: #2348
2016-04-12 13:43:29 +02:00
Lennart Poettering a3c4eb0710 core: rework generator dir logic, move the dirs into LookupPaths structure
A long time ago – when generators where first introduced – the directories for
them were randomly created via mkdtemp(). This was changed later so that they
use fixed name directories now. Let's make use of this, and add the genrator
dirs to the LookupPaths structure and into the unit file search path maintained
in it. This has the benefit that the generator dirs are now normal part of the
search path for all tools, and thus are shown in "systemctl list-unit-files"
too.
2016-04-12 13:43:29 +02:00
Lennart Poettering 382b56622a Merge pull request #2962 from keszybz/value-option
Add `--value` option to systemctl and loginctl to only print values
2016-04-06 10:47:37 +02:00
Zbigniew Jędrzejewski-Szmek 4f9a91055c systemctl: add --value option
With this option, systemctl will only print the rhs in show:
$ systemctl show -p Wants,After systemd-journald --value
systemd-journald.socket ...
systemd-journald-dev-log.socket ...

This is useful in scripts, because the need to call awk or similar
is removed.
2016-04-04 22:41:49 -04:00
Martin Pitt c6ba5b8069 systemctl: use correct printf macros for uint32
%u is a simple uint which might not be 32 bit on every platform. Use PRIu32
instead.
2016-04-01 14:21:35 +02:00
Franck Bui ebc962656c systemctl: no need to pass --all if inactive is explicitly requested in list-units
If list-units command is explicitly asked to show inactive units
by using '--state=inactive' option, there's no need to force the user
to pass '--all' option to include inactive units in the search in
this case.
2016-03-23 08:36:05 +01:00
Daniel Mack 280d397ab3 Merge pull request #2768 from benjarobin/fix-2718
systemctl: Replace check_one_unit() by get_state_one_unit()
2016-03-07 14:50:08 +01:00
Ronny Chevalier 0b8505b7c9 systemctl: improve error message when starting a unit failed
Fixes #2798
2016-03-05 12:47:21 +01:00
Ronny Chevalier 043717f9d3 systemctl: add missing OOM check 2016-03-03 18:16:31 +01:00
Ronny Chevalier 5f18271ec1 systemctl: rm empty dropin dirs after cancelled edit
Fixes #2734
2016-03-02 22:06:47 +01:00
Benjamin ROBIN d2e796739d systemctl: Fix warn: action_to_runlevel() is not used
If HAVE_SYSV_COMPAT is not defined: ‘action_to_runlevel’ defined but not used
2016-02-29 15:07:09 +01:00
Benjamin ROBIN fa0d5878c6 systemctl: Replace check_one_unit() by get_state_one_unit()
The get_state_one_unit returns the enum of the active state of the unit
Do not rely on the string value of the active state.

Fix #2718 since the refactoring allow to handle more case
2016-02-29 14:38:44 +01:00
Zbigniew Jędrzejewski-Szmek 06fb28b16e Merge pull request #2671 from 0xAX/move-pager-open-to-one-place
tree-wide: merge pager_open_if_enabled() to the pager_open()
2016-02-25 15:29:59 -05:00
Alexander Kuleshov ea4b98e657 tree-wide: merge pager_open_if_enabled() to the pager_open()
Many subsystems define own pager_open_if_enabled() function which
checks '--no-pager' command line argument and open pager depends
on its value. All implementations of pager_open_if_enabled() are
the same. Let's merger this function with pager_open() from the
shared/pager.c and remove pager_open_if_enabled() from all subsytems
to prevent code duplication.
2016-02-26 01:13:23 +06:00
Vito Caputo 9ed794a32d tree-wide: minor formatting inconsistency cleanups 2016-02-23 14:20:34 -08:00
Vito Caputo 313cefa1d9 tree-wide: make ++/-- usage consistent WRT spacing
Throughout the tree there's spurious use of spaces separating ++ and --
operators from their respective operands.  Make ++ and -- operator
consistent with the majority of existing uses; discard the spaces.
2016-02-22 20:32:04 -08:00
Zbigniew Jędrzejewski-Szmek c11bda1e3c systemctl: fix style to avoid modification of array passed by caller
Followup for 4524439edb.
2016-02-15 19:06:53 -05:00
Zbigniew Jędrzejewski-Szmek 4524439edb systemctl: include -M or -H arguments in the hint
https://github.com/systemd/systemd/issues/2431

Some newlines are added, but the output will still exceed 80 columns in many
cases. The fallback for oom conditions is changed from "n/a" to something
"<service>", and a similar pattern is used for the new code. This way we
have a realistic fallback for oom, which seems nicer than making the whole
function return an error code which would then have to be propagated.

$ systemctl -M fedora-rawhide restart systemd-networkd.service
Job for systemd-networkd.service failed because start of the service was attempted too often.
See "systemctl -M fedora-rawhide status systemd-networkd.service" and "journalctl -M fedora-rawhide -xe" for details.
To force a start use "systemctl -M fedora-rawhide reset-failed systemd-networkd.service"
followed by "systemctl -M fedora-rawhide start systemd-networkd.service" again.
2016-02-15 15:23:45 -05:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Lennart Poettering cab2aca3e7 core: fix support for transient resource limit properties
Make sure we can properly process resource limit properties. Specifically, allow transient configuration of both the
soft and hard limit, the same way from the unit files. Previously, only the the hard rlimits could be configured but
they'd implicitly spill into the soft hard rlimits.

This also updates the client-side code to be able to parse hard/soft resource limit specifications. Since we need to
serialize two properties in bus_append_unit_property_assignment() now, the marshalling of the container around it is
now moved into the function itself. This has the benefit of shortening the calling code.

As a side effect this now beefs up the rlimit parser of "systemctl set-property" to understand time and disk sizes
where that's appropriate.
2016-02-01 22:18:16 +01:00
Lennart Poettering d152dd467a systemctl: actually honour the try-reload-or-restart verb aabf5d4243 promised
The verb entry got lost in the ultimate commit.
2016-01-29 15:49:05 +01:00
Lennart Poettering 1e726cc963 systemctl: make most systemctl commands NOPs in a chroot() environment
Fixes #2015
2016-01-29 15:49:05 +01:00
Lennart Poettering 040524b4a3 systemctl: consider a chroot() environment always offline 2016-01-29 15:16:56 +01:00
Lennart Poettering aabf5d4243 systemctl: rename "reload-or-try-restart" verb to "try-reload-or-restart"
But also keep the old name as (undocumented) compatibility around.

The reload-or-try-restart was documented to be a NOP if the unit is not running, since the previous commits this is
also implemented. The old name suggests that the "try" logic only applies to restarting. Fix this, by moving the "try-"
to the front, to indicate that the whole option is a NOP if the service isn't running.
2016-01-28 18:57:04 +01:00
Lennart Poettering b430f85f22 systemctl: don't make up unit states, and don't eat up errors to eagerly
When checking a unit's state, don't ignore errors too eagerly, but generate proper error messages. Also, don't
synthesize an "unknown" state on error, but let the operation file. If a unit file isn't loaded treat this as
"inactive" as that's effectively what it means.
2016-01-28 16:53:06 +01:00
Lennart Poettering 6233b9023b systemctl: don't mangle unit names in check_unit_generic()
As it turns out all callers of check_unit_generic() already mangle unit names, or get the unit names directly from PID
1 (and hence arein normalized form anyway), hence there's no point in mangling then...
2016-01-28 16:34:21 +01:00
Lennart Poettering 1b53f64b00 systemctl: piece-meal strv extension is expensive
If we have many entries to add to an strv we really should try to be smarter than constantly realloc()ing the strv
array. Instead, grow it exponentially.
2016-01-27 02:21:28 +01:00
Lukas Nykryn d60f6ad0cb systemctl: is-active/failed should return 0 if at least one unit is in given state
Previously we have return the not-found code, in the case that we found a
unit which does not belong to set active (resp. failed), which is the
opposite than what is written in man page.
2016-01-25 15:21:28 +01:00
Douglas Christman 1e524ec6e2 systemctl: Allow 'edit' and 'cat' on unloaded units
Don't fail if the unit has a LoadError; otherwise `systemctl edit` cannot be
used to correct the error (e.g. multiple "ExecStart=" lines).

Remove file changed warning so cat output isn't interspersed with log messages.

Fixes #829
2016-01-21 18:22:55 -05:00
Lennart Poettering 3b159f328c Merge pull request #2085 from fbuihuu/more-use-of-check-load-state
core: use bus_unit_check_load_state() in transaction_add_job_and_depe…
2016-01-20 17:18:44 +01:00
Jan Synacek 40c9fe4c08 basic/terminal-util: introduce SYSTEMD_COLORS environment variable
... to determine if color output should be enabled. If the variable is not set,
fall back to using on_tty(). Also, rewrite existing code to use
colors_enabled() where appropriate.
2016-01-20 10:12:41 +01:00
Tom Gundersen becc96b726 Merge pull request #2316 from poettering/dnssec14
Fourteenth DNSSEC PR
2016-01-14 17:02:57 +01:00
WaLyong Cho 10ba483504 bus-util: print "systemctl --user" on user service manager
When a unit was started with "systemctl --user" and it failed, error
messages is printed as "systemctl status". But it should be "systemctl
--user status".
2016-01-14 15:33:43 +09:00
Lennart Poettering 4b2e9cfcf0 systemctl: improve wording of "systemctl enable" messages
Closes: #2299
2016-01-13 20:21:36 +01:00
Franck Bui ee87525c5e core: use bus_unit_check_load_state() in transaction_add_job_and_dependencies() 2015-12-02 17:03:28 +01:00
Lennart Poettering 4afd3348c7 tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.

With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.

The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).

This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.

Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:

       #define _cleanup_(function) __attribute__((cleanup(function)))

Or similar, to make the gcc feature easier to use.

Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.

See #2008.
2015-11-27 19:19:36 +01:00
Thomas Hindoe Paaboel Andersen bf40958019 systemctl: do not return uninitialized r
Regresssed during port to extract_first_word in
5ab22f3321

CID #1338060
2015-11-22 23:11:20 +01:00
Lennart Poettering 45090bf2ff systemctl: open pager for 'status', since process tree can get very long 2015-11-18 17:04:05 +01:00
Lennart Poettering 055ef36bc8 systemctl: make sure 'status' shows whether units are transient 2015-11-18 17:04:05 +01:00
Michal Schmidt 7152869f0a Merge pull request #1869 from poettering/kill-overridable
Remove support for RequiresOverridable= and RequisiteOverridable=
2015-11-13 14:04:34 +01:00
Lennart Poettering f32b43bda4 core: remove support for RequiresOverridable= and RequisiteOverridable=
As discussed at systemd.conf 2015 and on also raised on the ML:

http://lists.freedesktop.org/archives/systemd-devel/2015-November/034880.html

This removes the two XyzOverridable= unit dependencies, that were
basically never used, and do not enhance user experience in any way.
Most folks looking for the functionality this provides probably opt for
the "ignore-dependencies" job mode, and that's probably a good idea.

Hence, let's simplify systemd's dependency engine and remove these two
dependency types (and their inverses).

The unit file parser and the dbus property parser will now redirect
the settings/properties to result in an equivalent non-overridable
dependency. In the case of the unit file parser we generate a warning,
to inform the user.

The dbus properties for this unit type stay available on the unit
objects, but they are now hidden from usual introspection and will
always return the empty list when queried.

This should provide enough compatibility for the few unit files that
actually ever made use of this.
2015-11-12 19:27:24 +01:00
Lennart Poettering 0ec0deaa30 install: follow unit file symlinks in /usr, but not /etc when looking for [Install] data
Some distributions use alias unit files via symlinks in /usr to cover
for legacy service names. With this change we'll allow "systemctl
enable" on such aliases.

Previously, our rule was that symlinks are user configuration that
"systemctl enable" + "systemctl disable" creates and removes, while unit
files is where the instructions to do so are store. As a result of the
rule we'd never read install information through symlinks, since that
would mix enablement state with installation instructions.

Now, the new rule is that only symlinks inside of /etc are
configuration. Unit files, and symlinks in /usr are now valid for
installation instructions.

This patch is quite a rework of the whole install logic, and makes the
following addional changes:

- Adds a complete test "test-instal-root" that tests the install logic
  pretty comprehensively.

- Never uses canonicalize_file_name(), because that's incompatible with
  operation relative to a specific root directory.

- unit_file_get_state() is reworked to return a proper error, and
  returns the state in a call-by-ref parameter. This cleans up confusion
  between the enum type and errno-like errors.

- The new logic puts a limit on how long to follow unit file symlinks:
  it will do so only for 64 steps at max.

- The InstallContext object's fields are renamed to will_process and
  has_processed (will_install and has_installed) since they are also
  used for deinstallation and all kinds of other operations.

- The root directory is always verified before use.

- install.c is reordered to place the exported functions together.

- Stricter rules are followed when traversing symlinks: the unit suffix
  must say identical, and it's not allowed to link between regular units
  and templated units.

- Various modernizations

- The "invalid" unit file state has been renamed to "bad", in order to
  avoid confusion between UNIT_FILE_INVALID and
  _UNIT_FILE_STATE_INVALID. Given that the state should normally not be
  seen and is not documented this should not be a problematic change.
  The new name is now documented however.

Fixes #1375, #1718, #1706
2015-11-12 17:57:04 +01:00
Lennart Poettering d073dea0a8 install: never log from install functions
Instead, let the caller do that. Fix this by moving masked unit messages
into the caller, by returning a clear error code (ESHUTDOWN) by which
this may be detected.
2015-11-12 17:56:49 +01:00
Lennart Poettering 91d0f17e03 systemctl: make sure list-jobs doesn't return failure on success 2015-11-11 14:35:44 +01:00
Lennart Poettering 404f08d341 systemctl: add a comment that clarifies why we do "return r" at the end of main()
To avoid confusion as outlined in #1845.
2015-11-11 12:57:40 +01:00
Lennart Poettering 9eb4a5012c Revert "systemctl: return EXIT_SUCCESS on success"
This reverts commit 6a32563caa.
2015-11-11 10:59:11 +01:00
Tom Gundersen 620b7793fc Merge pull request #1839 from evverx/fix-systemctl-cancel
systemctl: fix cancel
2015-11-11 02:25:57 +01:00
Evgeny Vereshchagin 6a32563caa systemctl: return EXIT_SUCCESS on success 2015-11-11 01:17:13 +00:00
Zbigniew Jędrzejewski-Szmek 36b4a7ba55 Remove snapshot unit type
Snapshots were never useful or used for anything. Many systemd
developers that I spoke to at systemd.conf2015, didn't even know they
existed, so it is fairly safe to assume that this type can be deleted
without harm.

The fundamental problem with snapshots is that the state of the system
is dynamic, devices come and go, users log in and out, timers fire...
and restoring all units to some state from the past would "undo"
those changes, which isn't really possible.

Tested by creating a snapshot, running the new binary, and checking
that the transition did not cause errors, and the snapshot is gone,
and snapshots cannot be created anymore.

New systemctl says:
Unknown operation snapshot.
Old systemctl says:
Failed to create snapshot: Support for snapshots has been removed.

IgnoreOnSnaphost settings are warned about and ignored:
Support for option IgnoreOnSnapshot= has been removed and it is ignored

http://lists.freedesktop.org/archives/systemd-devel/2015-November/034872.html
2015-11-10 19:33:06 -05:00
Evgeny Vereshchagin 75fbd19388 systemctl: fix cancel
http://www.freedesktop.org/software/systemd/man/systemctl.html#cancel%20JOB...
> If no job ID is specified, cancel all pending jobs
2015-11-11 00:03:24 +00:00
Susant Sahani 5ab22f3321 systemctl: port to extract_first_word 2015-11-02 21:47:40 +05:30
Lennart Poettering b41b9d2ae9 systemctl: add a way to explicitly request client-side unit installing
This adds support for a new environment variable
SYSTEMCTL_INSTALL_CLIENT_SIDE, that ensures that systemctl executes
install operations client-side instead of passing them to PID1. This is
useful in debugging situations, but even beyond that. However, we don't
want to make it official API, hence let's just make it an undocumented
environment variable.

Similar, add a second variable, SYSTEMCTL_SKIP_SYSV which allows
skipping the SysV chkconfig fall-back if set. This is useful for similar
reasons, and exposed as undocumented as environment variable for similar
reasons, too.
2015-10-31 19:09:20 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 7d50b32a12 util-lib: split out globbing related calls into glob-util.[ch] 2015-10-27 13:25:58 +01:00
Lennart Poettering 7f4b3c5ea3 util-lib: move running_in_chroot() into virt.[ch]
It's a very weak kind of virtualization, after all.
2015-10-27 13:25:57 +01:00
Lennart Poettering 8752c5752f util-lib: move more locale-related calls to locale-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 8fcde01280 util-lib: split stat()/statfs()/stavfs() related calls into stat-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering f4f15635ec util-lib: move a number of fs operations into fs-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 78f22b973f util-lib: split out resource limits related calls into rlimit-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 5f311f8c0e util: remove path_get_parent(), in favour of dirname_malloc()
We don't need two functions that do essentialy the same, hence drop
path_get_parent(), and stick to dirname_malloc(), but move it to
path-util.[ch].
2015-10-27 13:25:55 +01:00
Lennart Poettering 6bedfcbb29 util-lib: split string parsing related calls from util.[ch] into parse-util.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering b1d4f8e154 util-lib: split out user/group/uid/gid calls into user-util.[ch] 2015-10-26 01:24:38 +01:00
Lennart Poettering c004493cde util-lib: split out IO related calls to io-util.[ch] 2015-10-26 01:24:38 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 0f03c2a4c0 path-util: unify how we process paths specified on the command line
Let's introduce a common function that makes relative paths absolute and
warns about any errors while doing so.
2015-10-24 23:03:49 +02:00
Lennart Poettering 5b7481633f systemctl: the various list commands actually can take any number of arguments
I accidentally broke this a while back when I ported systemctl to the
verbs logic.

Add support for this back.
2015-10-22 01:59:24 +02:00
Lennart Poettering 7e9d36e06b systemctl: fix how we decode types and states
There was a bad memory access among other smaller issues.
2015-10-01 14:27:20 +02:00
reverendhomer bc6c18fef1 systemctl: fix memory leak in systemctl_parse_argv
This commit fixes Coverity #1325228
2015-10-01 12:09:00 +03:00
Lennart Poettering 32c6d387bf Merge pull request #1422 from keszybz/sd-daemon-mq-badf
sd-daemon: fix return value for sd_is_mq
2015-09-30 22:33:50 +02:00
Lennart Poettering 23a749f285 Merge pull request #1419 from keszybz/shell-completion
Shell completion tweaks
2015-09-30 22:32:09 +02:00
Zbigniew Jędrzejewski-Szmek 7bbb5359c0 systemctl: do not set variable to be immediately overwritten 2015-09-30 12:33:31 -04:00
Lennart Poettering a4420f7b8e systemctl: when reading legacy -t argument for shutdown, don't drop following parameter
We currently completely ignore the following parameter, but we really
should not, as that is actually the time to shut down on.
2015-09-30 12:23:33 +02:00
Lennart Poettering 45519fd630 systemctl: various modernizations 2015-09-30 12:23:32 +02:00
Daniel Mack 5cfee41459 tree-wide: use strempty() where possible
Also add a Coccinell patch to detect such locations in the future.
2015-09-30 11:41:03 +02:00
Lennart Poettering 7f96539d45 systemctl: when a shutdown is scheduled, always go via logind 2015-09-29 21:55:53 +02:00
Lennart Poettering 19578bb26b systemctl: minor modernizations 2015-09-29 21:55:53 +02:00
Lennart Poettering e449de8777 systemctl: port verb dispatching to generic verbs.[ch] code
Let's parse the command line the same way in our various tools.
2015-09-29 21:55:53 +02:00
Lennart Poettering 7089051f67 systemctl: prefer shutting down through logind even as root
Otherwise, wall messages will not be generated for root.
2015-09-29 21:55:53 +02:00
Lennart Poettering 57ab90065d systemctl: split out code invoking SetExitCode() into function of its own 2015-09-29 21:55:53 +02:00
Lennart Poettering 4057e12315 systemctl: don't assert on the arguments array unnecessarily
In most verbs it's fine to treat the arguments array being NULL is empty
array, hence do so.
2015-09-29 21:55:53 +02:00
Lennart Poettering 14b316ebf8 systemctl: make use of strv_skip() where appropriate 2015-09-29 21:55:53 +02:00
Lennart Poettering 691395d84c systemctl: make use of log_error_errno() where we can
Also adds a couple of "return" statements, where they are missing.
2015-09-29 21:55:52 +02:00
Lennart Poettering 4fbd7192c5 systemctl: rework how we connect to busses
Sometimes we have to connect to the system manager directly (early boot,
initrd, late boot, ...), sometimes through the system bus (unprivileged,
remote, logind, ...). Instead of guessing in advance, which kind of
connection we require (and sometimes guessing incorrectly), let's make
sure each time we need  bus connection we request the right bus
explicitly.

This way, we set up exactly the bus connections require, never guess
incorrectly, and do so only immediately when necessary.

As effect this reworks avoid_bus() into install_client_side(), since
that's all it determines now: whether to install unit files client-side
or server-side (i.e. in PID 1).
2015-09-29 21:55:52 +02:00
Lennart Poettering 266f3e269d bus-util: rename bus_open_transport() to bus_connect_transport()
In sd-bus, the sd_bus_open_xyz() family of calls allocates a new bus,
while sd_bus_default_xyz() family tries to reuse the thread's default
bus. bus_open_transport() sometimes internally uses the former,
sometimes the latter family, but suggests it only calls the former via
its name. Hence, let's avoid this confusion, and generically rename the
call to bus_connect_transport().

Similar for all related calls.

And while we are at it, also change cgls + cgtop to do direct systemd
connections where possible, since all they do is talk to systemd itself.
2015-09-29 21:55:52 +02:00
Lennart Poettering 2cc7b0a25f systemctl: rename parse_time_spec() to parse_shutdown_time_spec()
Let's clarify that this function is specific to shutdown time
specifications, nothing else.
2015-09-29 21:55:52 +02:00
Lennart Poettering eca830bee9 systemctl: conditionalize /dev/initctl fallback on HAVE_SYSV_COMPAT 2015-09-29 21:55:52 +02:00
Lennart Poettering 172d7abfea systemctl: allocate arg_wall only on the heap
Previously, we'd allocate it sometimes from the heap, but otherwise let
it point directly int argv[]. Let's clean this up, so that we know
exactly how to release its resources, and do so at the end.
2015-09-29 21:55:52 +02:00
Lennart Poettering fc2ffaf17d systemctl: add 'const' where appropriate 2015-09-29 21:55:52 +02:00
Lennart Poettering 48ec22bc02 systemctl: remove client-side wall message support
logind sends out wall messages now, let's remove this from the systemctl
client side hence. If people build systemd without logind support they
won't get wall messages now, but that's OK.
2015-09-29 21:55:52 +02:00
Lennart Poettering e3ead6bb42 systemctl: move strv_skip_first() out of systemctl.c
Make it generic, call it strv_skip() and move it to strv.[ch]
2015-09-29 21:55:52 +02:00
Lennart Poettering 56a730fa56 systemctl: split out code that schedules shutdowsn into its own function 2015-09-29 21:55:52 +02:00
Lennart Poettering 2cf05793f2 systemctl: rename all logind-specific functions to logind_xyz() 2015-09-29 21:55:52 +02:00
Lennart Poettering 949d9ce954 systemctl: move shutdown cancelling code into its own function
Let's make sure the main switch statement only invokes functions, but
doesn't do anything real on its own.
2015-09-29 21:55:52 +02:00
Lennart Poettering 4f16c1f479 systemctl: don't special case ACTION_RUNLEVEL anymore
Let's move its dispatching to the main switch statement.
2015-09-29 21:55:51 +02:00
Lennart Poettering f2d11d35e9 systemctl: introduce a single function to set the wall message
Let's not have the same code three times, but reduce it to one function.
2015-09-29 21:55:51 +02:00
Lennart Poettering 94f099d813 systemctl: make "systemctl is-system-running" return "offline" if we are not booted with systemd
This sounds like the better place to expose this than in "systemd-notify
--booted".

Also document the so far undocumented "unknown" state the command might
return. And rearrange the table of states documented to be more like the
one for "is-running".

Also, don't document the precise exit code of this function, just say
errors are reported != 0 or > 0...
2015-09-29 21:55:51 +02:00
Lennart Poettering 3f6fd1ba65 util: introduce common version() implementation and use it everywhere
This also allows us to drop build.h from a ton of files, hence do so.
Since we touched the #includes of those files, let's order them properly
according to CODING_STYLE.
2015-09-29 21:08:37 +02:00
Zbigniew Jędrzejewski-Szmek 7e55de3b96 Move all unit states to basic/ and extend systemctl --state=help 2015-09-28 15:09:34 -04:00
Zbigniew Jędrzejewski-Szmek e16972e626 systemctl: add --state=help
This mirrors --type=help and simplifies completion scripts.

The array of states is dense, so the is no need to check if the string is null.
2015-09-28 15:09:34 -04:00
David Herrmann 840cdfcd81 Merge pull request #1334 from poettering/sd-bus-default-flush-close
sd-bus: introduce new sd_bus_default_flush_close() call
2015-09-22 17:33:58 +02:00
Lennart Poettering 1fc464f6fb cgtop: underline table header
Let's underline the header line of the table shown by cgtop, how it is
customary for tables. In order to do this, let's introduce new ANSI
underline macros, and clean up the existing ones as side effect.
2015-09-22 16:30:42 +02:00
Lennart Poettering fa2f8973ad sd-bus: introduce new sd_bus_default_flush_close() call
If code enqueues a message on one of the default busses, but doesn't
sync on it, and immediately drops the reference to the bus again, it
will stay queued and consume memory. Intrdouce a new call
sd_bus_default_flush_close() that can be invoked at the end of programs
(or threads) and flushes out all unsent messages on any of the default
busses.
2015-09-22 16:29:10 +02:00
Alban Crequy 287419c119 containers: systemd exits with non-zero code
When a systemd service running in a container exits with a non-zero
code, it can be useful to terminate the container immediately and get
the exit code back to the host, when systemd-nspawn returns. This was
not possible to do. This patch adds the following to make it possible:

- Add a read-only "ExitCode" property on PID 1's "Manager" bus object.
  By default, it is 0 so the behaviour stays the same as previously.
- Add a method "SetExitCode" on the same object. The method fails when
  called on baremetal: it is only allowed in containers or in user
  session.
- Add support in systemctl to call "systemctl exit 42". It reuses the
  existing code for user session.
- Add exit.target and systemd-exit.service to the system instance.
- Change main() to actually call systemd-shutdown to exit() with the
  correct value.
- Add verb 'exit' in systemd-shutdown with parameter --exit-code
- Update systemctl manpage.

I used the following to test it:

| $ sudo rkt --debug --insecure-skip-verify run \
|            --mds-register=false --local docker://busybox \
|            --exec=/bin/chroot -- /proc/1/root \
|            systemctl --force exit 42
| ...
| Container rkt-895a0cba-5c66-4fa5-831c-e3f8ddc5810d failed with error code 42.
| $ echo $?
| 42

Fixes https://github.com/systemd/systemd/issues/1290
2015-09-21 17:32:45 +02:00
Jan Synacek ac5e3a505e core: extend KillUnit() to return error when no unit was killed 2015-09-21 10:05:49 +02:00
Lennart Poettering 3227b2bced Merge pull request #1227 from intelfx/systemctl-legacy-tools-polkit
systemctl: fix various aspects of polkit authorization in legacy tools.
2015-09-10 19:53:31 +02:00
Daniel Mack a18f3caa56 Merge pull request #1239 from poettering/cgroup-pids
core: add support for the "pids" cgroup controller
2015-09-10 19:11:29 +02:00
Daniel Mack 786c5bf957 Merge pull request #1242 from poettering/no-off_t
Drop usage of off_t
2015-09-10 19:01:25 +02:00
Lennart Poettering 03a7b521e3 core: add support for the "pids" cgroup controller
This adds support for the new "pids" cgroup controller of 4.3 kernels.
It allows accounting the number of tasks in a cgroup and enforcing
limits on it.

This adds two new setting TasksAccounting= and TasksMax= to each unit,
as well as a gloabl option DefaultTasksAccounting=.

This also updated "cgtop" to optionally make use of the new
kernel-provided accounting.

systemctl has been updated to show the number of tasks for each service
if it is available.

This patch also adds correct support for undoing memory limits for units
using a MemoryLimit=infinity syntax. We do the same for TasksMax= now
and hence keep things in sync here.
2015-09-10 18:41:06 +02:00
Lennart Poettering 59f448cf15 tree-wide: never use the off_t unless glibc makes us use it
off_t is a really weird type as it is usually 64bit these days (at least
in sane programs), but could theoretically be 32bit. We don't support
off_t as 32bit builds though, but still constantly deal with safely
converting from off_t to other types and back for no point.

Hence, never use the type anymore. Always use uint64_t instead. This has
various benefits, including that we can expose these values directly as
D-Bus properties, and also that the values parse the same in all cases.
2015-09-10 18:16:18 +02:00
Evgeny Vereshchagin 1143adf722 systemctl: add RequisiteOf* as inverses of Requisite and RequisiteOverridable 2015-09-10 14:49:29 +03:00
Ivan Shapovalov 58158dc765 systemctl: improve clarity of error messages in the logind path 2015-09-10 14:45:00 +03:00
Ivan Shapovalov 2ac3930f5b systemctl: relax permission checks in halt_main()
Thus we allow (non-interactive) polkit auth to kick in for legacy commands
(halt, poweroff, reboot, telinit) as well.

Fixes (another aspect of) issue #213.
2015-09-10 14:45:00 +03:00
Ivan Shapovalov a9085ea356 systemctl: fix logind bus call error handling in halt_main()
Handle -EOPNOTSUPP and -EINPROGRESS like in start_special().
2015-09-10 14:44:59 +03:00
Ivan Shapovalov 4c315c2c7c systemctl: minor: use IN_SET() instead of repeated equality checks. 2015-09-10 14:39:46 +03:00
Ivan Shapovalov 16f017fa6e systemctl: legacy tools shall never be interactive
Fixes (the main concern of) issue #213.
2015-09-10 01:14:07 +03:00
Daniel Mack 7681f5b889 systemctl: add dry-run support for scheduled shutdowns
Prefix the action parameter with "dry-" in case the --dry-run command
line switch was passed.
2015-09-09 17:52:12 +02:00
Lennart Poettering ece174c543 tree-wide: drop {} from one-line if blocks
Patch via coccinelle.
2015-09-09 08:20:20 +02:00
Evgeny Vereshchagin fb30c438f3 systemctl: add ConsistsOf as the inverse of PartOf 2015-09-08 03:02:49 +03:00
Lennart Poettering 4c3e8e39ea systemctl: a number of cleanups regarding error handling in systemctl 2015-09-07 00:12:05 +02:00
Lennart Poettering 6f883237f1 cgroup: drop "ignore_self" argument from cg_is_empty()
In all cases where the function (or cg_is_empty_recursive()) ignoring
the calling process is actually wrong, as a process keeps a cgroup busy
regardless if its the current one or another. Hence, let's simplify
things and drop the "ignore_self" parameter.
2015-09-01 18:37:01 +02:00
Lennart Poettering 37a0d5bf21 Revert "systemctl: properly handle empty control group paths in "status""
This reverts commit b04c25f9ef.
2015-08-25 20:37:54 +02:00
Tom Gundersen 498fb56739 Merge pull request #1022 from poettering/machinectl-shell
Add new "machinectl shell" command for su(1)-like behaviour
2015-08-25 16:46:27 +02:00
Jan Synacek 9ef15026c0 logind/systemctl: introduce SetWallMessage and --message
Enable unprivileged users to set wall message on a shutdown
operation. When the message is set via the --message option,
it is logged together with the default shutdown message.

$ systemctl reboot --message "Applied kernel updates."

$ journalctl -b -1
...
systemd-logind[27]: System is rebooting. (Applied kernel updates.)
...
2015-08-25 13:52:44 +02:00
Lennart Poettering b04c25f9ef systemctl: properly handle empty control group paths in "status"
When showing the status of the "-.slice" slice root unit (whose reported
cgroup path is ""), we suppressed the cgroup tree so far, because
skipped it for all unit with an empty cgroup path. Let's fix that, and
properly handle the empty cgroup path.
2015-08-24 22:46:45 +02:00
Thomas Blume 98d52feb96 support reboot -f for kexec kernel
Fix error message:

-->--
Code should not be reached 'Unknown action.' at
src/systemctl/systemctl.c:6382, function halt_now(). Aborting.
Aborted
--<--

when executing 'reboot -f' from a system running a kexec kernel.
2015-08-12 08:11:15 +02:00
David Herrmann 97b11eedff tree-wide: introduce mfree()
Pretty trivial helper which wraps free() but returns NULL, so we can
simplify this:
        free(foobar);
        foobar = NULL;
to this:
        foobar = mfree(foobar);
2015-07-31 19:56:38 +02:00
Lennart Poettering 03976f7b4a sd-bus: introduce new sd_bus_flush_close_unref() call
sd_bus_flush_close_unref() is a call that simply combines sd_bus_flush()
(which writes all unwritten messages out) + sd_bus_close() (which
terminates the connection, releasing all unread messages) +
sd_bus_unref() (which frees the connection).

The combination of this call is used pretty frequently in systemd tools
right before exiting, and should also be relevant for most external
clients, and is hence useful to cover in a call of its own.

Previously the combination of the three calls was already done in the
_cleanup_bus_close_unref_ macro, but this was only available internally.

Also see #327
2015-07-03 19:49:03 +02:00
Jan Synacek 9ef5d8f2cb systemctl: fix edit when EDITOR contains arguments
Correctly support cases when the EDITOR environment variable and friends
also contain arguments. For example, to run emacs in terminal only, one
can say:

EDITOR="emacs -nw" systemctl edit myservice
2015-06-18 13:46:08 +02:00
Lennart Poettering 5cb14b3742 everywhere: actually make use of DUAL_TIMESTAMP_NULL macro
Let's use it as initializer where appropriate.
2015-06-16 01:08:12 +02:00
Lennart Poettering 14bcf25c8b util: when creating temporary file names, allow including extra id string in it
This adds a "char *extra" parameter to tempfn_xxxxxx(), tempfn_random(),
tempfn_ranomd_child(). If non-NULL this string is included in the middle
of the newly created file name. This is useful for being able to
distuingish the kind of temporary file when we see one.

This also adds tests for the three call.

For now, we don't make use of this at all, but port all users over.
2015-06-15 19:28:55 +02:00
David Herrmann e7e55dbdc3 tree-wide: fix memory leaks in users of bus_map_all_properties()
If you use bus_map_all_properties(), you must be aware that it might
touch output variables even though it may fail. This is, because we parse
many different bus-properties and cannot tell how to clean them up, in
case we fail deep down in the parser.

Fix all callers of bus_map_all_properties() to correctly cleanup any
context structures at all times.
2015-06-14 15:08:52 +02:00
Lennart Poettering ce30c8dcb4 tree-wide: whenever we fork off a foreign child process reset signal mask/handlers
Also, when the child is potentially long-running make sure to set a
death signal.

Also, ignore the result of the reset operations explicitly by casting
them to (void).
2015-06-10 01:28:58 +02:00
Michael Biebl 9391a1c3d6 systemctl: Use /usr/bin/editor if available
If the EDITOR environment variable is not set, the Debian policy
recommends to use the /usr/bin/editor program as default editor.
This file is managed via the dpkg alternatives mechanism and typically
used in Debian/Ubuntu and derivatives to configure the default editor.

See section 11.4 of the Debian policy [1].

Therefor prefer /usr/bin/editor over specific editors if available.

[1] https://www.debian.org/doc/debian-policy/ch-customized-programs.html
2015-06-03 14:14:42 +02:00
Lennart Poettering 24882e06c1 util: split out signal-util.[ch] from util.[ch]
No functional changes.
2015-05-29 20:14:11 +02:00
Martin Pitt 355ff44900 systemctl: Don't skip SysV init.d scripts when enabling/disabling units
If there is both a SysV init.d script and a systemd unit for a given name, we
want to do the same enable/disable operation for both, instead of just on the
systemd unit. This keeps the enablement status in sync so that switching init
systems behaves as expected.
2015-05-28 19:42:45 +02:00
Martin Pitt 0f0467e63b systemctl: drop hardcoded chkconfig invocation
Introduce /usr/lib/systemd/systemd-sysv-install [--root=] <action> <name>
abstraction, replacing the direct calling of chkconfig. This allows
distributions to call their specific tools like update-rc.d without patching
systemd.

Ship systemd-sysv-install.SKELETON as an example for packagers how to implement
this.

Drop the --enable-chkconfig configure option.

Document this in README and point to it in NEWS.
2015-05-28 19:42:45 +02:00
Lennart Poettering 958b66ea16 util: split all hostname related calls into hostname-util.c 2015-05-18 17:10:07 +02:00
Jan Synacek 57ab2eabb8 systemctl: introduce --now for enable, disable and mask
https://bugs.freedesktop.org/show_bug.cgi?id=42940
2015-05-15 11:59:36 +02:00
Thomas Hindoe Paaboel Andersen eacd853425 systemctl: fix check for template units
A typo from 7410616c. We want to ignore EINVAL but only catch errors.
2015-05-12 00:26:14 +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
Torstein Husebø ff9b60f38b treewide: Correct typos and spell plural of bus consistent 2015-05-11 15:51:30 +02:00
Daniel Buch cafbecf31c systemctl: null-initialize pointer with cleanup attribute 2015-05-06 09:26:20 -07: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
Daniel Mack d3a2a05329 systemctl: kill newline characters from log_error_errno() calls
log_error_errno() already adds a newline, so drop them.
2015-04-24 21:50:36 +02:00
Daniel Mack f0efea232a systemctl: talk to logind for scheduled shutdowns
Drop the code which communicates with shutdownd via its private socket,
and use the functionality in logind instead.

The code pathes which talk to logind have to create their own ad-hoc
bus connection because by default, systemctl connects to systemd's
private socket.
2015-04-24 17:48:12 +02:00
Daniel Mack 99f710dde8 shared/utmp-wtmp: add parameter for origin tty and callback userdata
Instead of looking up the tty from STDIN, let utmp_wall() take an argument
to specify an origin tty for the wall message. Only if that argument is
NULL do the STDIN lookup.

Also add an void *userdata argument that is handed back to the callback
function.
2015-04-24 17:48:12 +02:00
Zbigniew Jędrzejewski-Szmek 40acc203c0 systemctl: avoid bumping NOFILE rlimit unless needed
We actually only use the journal when showing status. Move setrlimit call
so it is only called for status.

https://bugzilla.redhat.com/show_bug.cgi?id=1184712
2015-04-14 21:47:20 -04:00
Ronny Chevalier 288a74cce5 shared: add terminal-util.[ch] 2015-04-11 00:34:02 +02:00
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
Jan Janssen a4921cf4e2 systemctl: Use logind for --firmware-setup if possible 2015-04-08 18:22:16 +02:00
Jan Janssen 5bdf22430e logind,systemctl: add reboot to EFI firmware support 2015-04-07 18:51:45 +02:00
David Herrmann 15411c0cb1 tree-wide: there is no ENOTSUP on linux
Replace ENOTSUP by EOPNOTSUPP as this is what linux actually uses.
2015-03-13 14:10:39 +01:00
Zbigniew Jędrzejewski-Szmek 2558691285 systemctl: remove dead check
r could never be less than zero.

CID #1271350.
2015-03-07 15:00:22 -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
Zbigniew Jędrzejewski-Szmek 95d383ee47 systemctl: bump NOFILE only for systemctl_main
It is not necessary when running as telinit, etc.

https://bugzilla.redhat.com/show_bug.cgi?id=1184712
2015-02-24 10:11:06 -05:00
Zbigniew Jędrzejewski-Szmek 8527b07be1 systemctl: support auditd.service better
We would print the filename header before trying to open the file. But since
the header was printed to stdout, and the error to stderr, the error would appear
on the terminal before the header. It is cleaner to open the file first, then
and only then print the header.

Also exit on first error. We shouldn't report success if we were unable to open
a file.
2015-02-23 23:38:31 -05:00
Zbigniew Jędrzejewski-Szmek d028e01814 systemctl: check validity of PID we received 2015-02-23 23:38:30 -05: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 d5d8429a12 everywhere: remove configurability of sysv runlevel to target mapping
With this change runlevel 2, 3, 4 are mapped to multi-user.target for
good, and 5 to graphical.target. This was already the previous mapping
but is now no longer reconfigurable, but hard-coded into the core.

This should generally simplify things, but also fix one bug: the
sysv-generator previously generated symlinks to runlevel[2-5].target
units, which possibly weren't picked up if these aliases were otherwise
only referenced by the real names "multi-user.target" and
"graphical.target".

We keep compat aliases "runlevel[2345].target" arround for cases where
this target name is explicitly requested.
2015-02-18 20:20:14 +01:00
Lennart Poettering 6e646d22f6 systemctl: allow interactive authorization for all bus calls
Make use of the new sd_bus_set_allow_interactive_authorization() call to
globally enable interactive authorization. Also, turn on PK agent for
more calls.

This allows us to make use of the sd_bus_call_method() convencience
helper at more places.
2015-02-18 18:56:27 +01:00
Lennart Poettering 1cfa9a4cbb systemctl: let's make use of FOREACH_STRING() where we can 2015-02-18 18:56:27 +01:00
Zbigniew Jędrzejewski-Szmek 2404701e67 Transpose args in strv_fnmatch() to be more oo 2015-02-16 14:04:36 -05:00
Zbigniew Jędrzejewski-Szmek bceccd5ecc Add helper for fnmatch over strv 2015-02-16 13:16:45 -05:00
Thomas Hindoe Paaboel Andersen 8744505aae remove unused variable 2015-02-12 20:44:06 +01:00
Michael Olbrich c31c4324c5 systemctl: don't update the reboot parameter if none is given
Otherwise systemd-reboot.service will remove the parameter that was set
before. This was broken in commit "b986229efe2cc96157aa14c37bab7843311bbef1
systemctl: bugfix for systemctl reboot command with argument"
2015-02-11 20:37:16 +01:00
Ivan Shapovalov dab2bce81e systemctl: unit_find_paths(): unify error handling in two code pathes 2015-02-04 20:10:28 -05:00
Ivan Shapovalov 029009d497 systemctl: cat, edit: further polish error messages 2015-02-04 20:10:27 -05:00
Ivan Shapovalov 3e7eed8497 systemctl: cat: fix error handling
- correctly check for local vs. remote transport
- return after receiving error from expand_names()
2015-02-04 20:10:27 -05:00
Ivan Shapovalov b5e6a60032 systemctl: cat, edit: improve unit load error reporting
- report actual load error for units which could not be loaded
- make unit_find_paths() report all kinds of errors it encounters
  (for consistency)
- consistently handle not-found errors in cat() and edit()
2015-02-04 20:10:27 -05: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
Zbigniew Jędrzejewski-Szmek 3e495a6651 systemctl: refuse --host with cat
This might be fixed one day, but for now it's better to fail.

https://bugzilla.redhat.com/show_bug.cgi?id=1186952
2015-01-28 21:56:10 -05:00
Sangjung Woo b986229efe systemctl: bugfix for systemctl reboot command with argument
According to systemctl man page, 'systemctl reboot [arg]' should work
without any errors. However, it does not work because of 'Invalid number
of arguments' error, except for 'reboot [arg]'. This patch fixes the bug
so that both of commands work in exactly the same way.
2015-01-23 09:30:44 -05: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
Zbigniew Jędrzejewski-Szmek 1fa2f38f0f Assorted format fixes
Types used for pids and uids in various interfaces are unpredictable.
Too bad.
2015-01-22 01:14:52 -05:00
Zbigniew Jędrzejewski-Szmek 250ba6647b systemctl: do not show dots with --plain
Plain implies a ... "plain" output.

Also do not say "No jobs" with --no-legend. We skip
reporting the number of jobs with --no-legend if there
are any, and 0 is also a number, and should be skipped.
2015-01-19 15:41:03 -05:00
Zbigniew Jędrzejewski-Szmek 3fb90db2d6 systemctl: fix import-environment description, trim help to 80 cols 2015-01-19 13:55:59 -05:00
Ronny Chevalier 86d81e502b systemctl: add missing output modes to help message 2015-01-09 13:54:19 +01:00
Lennart Poettering f2068bcce0 machined: when cloning a raw disk image, also set the NOCOW flag 2015-01-08 23:13:45 +01:00
Lennart Poettering b619ec8f83 man: bring systemctl man page and --help text into the same order 2015-01-08 23:13:45 +01:00
Lennart Poettering 079dac08c6 systemctl,loginctl: start polkit agent for all polkit enabled operations 2015-01-08 23:13:45 +01:00
Lennart Poettering 8b0cc9a36c machinectl: show most recent log output in "machinectl status", too 2015-01-08 23:13:45 +01:00
Lennart Poettering 3c7560019e loginctl: show the 10 most recent log user/session log lines in "loginctl user-status" and "loginctl session-status" 2015-01-08 23:13:45 +01:00
Lennart Poettering de45d72603 journal: bump RLIMIT_NOFILE when journal files to 16K (if possible)
When there are a lot of split out journal files, we might run out of fds
quicker then we want. Hence: bump RLIMIT_NOFILE to 16K if possible.

Do these even for journalctl. On Fedora the soft RLIMIT_NOFILE is at 1K,
the hard at 4K by default for normal user processes, this code hence
bumps this up for users to 4K.

https://bugzilla.redhat.com/show_bug.cgi?id=1179980
2015-01-08 03:20:45 +01:00
Ivan Shapovalov 60d27f1916 path-lookup, systemctl: export lookup_paths_init_from_scope() from shared/install.c and use it 2015-01-05 11:13:30 -05:00
Lennart Poettering aba843317d systemctl: properly iterate through service array when dispatching to sysv
https://bugzilla.redhat.com/show_bug.cgi?id=1175734
2015-01-05 01:56:47 +01:00
Zbigniew Jędrzejewski-Szmek a39b4bdd10 systemctl: do not repeat hibernate/sleep attempts
If some sleep operation was not possible (e.g. because swap is missing),
we would try twice: once through logind, which would result in a clean error:
  Failed to execute operation: Sleep verb not supported
and then second time by starting the appropriate unit directly, which is
more messy. If logind tells us that something is not possible (or already
in progress), report that to the user and quit. If logind is present and working
we should not try to work around it.

Loosely based on https://bugs.freedesktop.org/show_bug.cgi?id=87832.
2014-12-30 18:39:52 -05:00
Lennart Poettering d8f52ed25a machinectl: add "enable" and "disable" verbs for enabling/disabling systemd-nspawn for containers
This is basically just a shortcut for "systemctl enable
systemd-nspawn@<foobar>.service", but does escaping.
2014-12-29 17:00:05 +01:00
Lennart Poettering ebd011d95b machinectl: add new "start" verb to start a container as a service in nspawn 2014-12-29 17:00:05 +01:00
Lennart Poettering de33fc6257 sd-bus: rename sd_bus_open_system_container() to sd_bus_open_system_machine()
Pretty much everywhere else we use the generic term "machine" when
referring to containers in API, so let's do though in sd-bus too. In
particular, since the concept of a "container" exists in sd-bus too, but
as part of the marshalling system.
2014-12-24 16:53:04 +01:00
Jan Synacek 75836b9d20 systemctl: fix argument handling when invoked as "shutdown" 2014-12-16 00:30:34 -05:00
Zbigniew Jędrzejewski-Szmek bc854dc7cd systemctl: refuse to edit runtime dropins when they already exist in /etc
The check for existing unit files and dropins is unified.

path_join() is updated to not insert duplicate separators.
2014-12-16 00:30:34 -05:00
Zbigniew Jędrzejewski-Szmek ad2a035820 systemctl: share path lookup between 'cat' and 'edit'
'systemctl cat' now works for templates too.

'systemctl edit' does not refuse to edit units that have changed on
disk. That restriction didn't seem useful, actually editing units that
have changed on disk before they are started is very reasonable.

'edit' with instances and templates works again:

Now:

$ build/systemctl edit getty@
Failed to copy /etc/systemd/system/getty@.service.d/override.conf to /etc/systemd/system/getty@.service.d/.override.confdff6290408c86369: Permission denied
$ build/systemctl edit getty@tty3
Failed to create directories for /etc/systemd/system/getty@tty3.service.d/override.conf: Permission denied
$ build/systemctl edit --full getty@tty3
Failed to copy /usr/lib/systemd/system/getty@.service to /etc/systemd/system/.getty@tty3.serviced3d175087e7e439b: Permission denied
Failed to create temporary file for /etc/systemd/system/getty@tty3.service: Permission denied
$ build/systemctl edit --full getty@
Failed to copy /usr/lib/systemd/system/getty@.service to /etc/systemd/system/.getty@.servicea3caad491c0f2f3d: Permission denied
Failed to create temporary file for /etc/systemd/system/getty@.service: Permission denied
2014-12-16 00:30:34 -05:00
Zbigniew Jędrzejewski-Szmek 8df1850740 systemctl: split out LookupPaths initialization 2014-12-16 00:30:34 -05:00
Zbigniew Jędrzejewski-Szmek 33f6c497f3 systemctl: move two functions up
No functional change.
2014-12-16 00:30:33 -05:00
Zbigniew Jędrzejewski-Szmek 3f36991e00 systemctl: unify warning about unit files changed on disk 2014-12-16 00:30:33 -05:00
Zbigniew Jędrzejewski-Szmek 5b013a2f67 systemctl: do not use -1 for return code
Also make the error messages more specific to give a hint to the user
how to solve the problem.
2014-12-16 00:30:33 -05: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
Ronny Chevalier e9e310f8e9 systemctl: handle correctly template units for edit verb
Previously, if we provided getty@.service to systemctl edit it would
have failed when using the bus because it is an invalid unit name.
But it would have succeeded when searching in the filesystem.

Now, we check if we have a template, if we do we search in the
filesystem, if we don't have a templae and we can use the bus, we do.

Furthermore, if we provided getty@tty1.service it would not have worked
when searching the filesystem, but it would have worked with the bus.
So now, when using the filesystem we use the template name and not the
unit name, and the same when logging errors.

(Also did a refactoring to avoid a long function)
2014-12-13 15:29:47 +01:00
Lennart Poettering 7430ec6ac0 copy: use btrfs reflinking only whe we know we copy full files 2014-12-12 17:30:25 +01:00
Lennart Poettering ae6c3cc009 util: when using basename() for creating temporary files, verify the resulting name is actually valid
Also, rename filename_is_safe() to filename_is_valid(), since it
actually does a full validation for what the kernel will accept as file
name, it's not just a heuristic.
2014-12-12 13:35:32 +01:00
Torstein Husebø f7340ab269 treewide: correct spacing near eol in code comments 2014-12-11 15:10:03 +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
Zbigniew Jędrzejewski-Szmek a644abed54 systemctl: fix invalid free when enabling sysv services fails
The error was introduced in v215-343-g60731f32f1 'systemctl: do not
bother to mutate state on error', by causing strv_free to attempt to
free a static string. Simplify the whole thing by always keeping the
array in valid state.
2014-12-09 21:47:53 -05:00
Zbigniew Jędrzejewski-Szmek 553acb7b6b treewide: sanitize loop_write
loop_write() didn't follow the usual systemd rules and returned status
partially in errno and required extensive checks from callers. Some of
the callers dealt with this properly, but many did not, treating
partial writes as successful. Simplify things by conforming to usual rules.
2014-12-09 21:36:08 -05:00