Commit graph

630 commits

Author SHA1 Message Date
Doug Christman 39c38ce17c systemctl: Create new unit files with "edit --force" (#3584) 2016-06-24 08:00:35 +02:00
Douglas Christman 79d4ace11e systemctl: Add missing "/" to files created by 'edit --runtime' 2016-06-22 15:09:33 -04:00
Lennart Poettering 749a1d0684 Merge pull request #3546 from keszybz/systemctl-fixes
Systemctl fixes
2016-06-16 18:40:53 +02:00
Zbigniew Jędrzejewski-Szmek d2ad7e1ba5 systemctl: delay pager/polkit agent opening as much as possible
In https://github.com/systemd/systemd/issues/3543, we would open the pager
before starting ssh, and the pipe fd was "leaked" into the ssh child as the
stderr fd. Previous commit fixes bus-socket to nullify stderr before launching
the child, but it seems reasonable to also delay starting the pager.
If we are going to croak when trying to open the transport, it seems better
to do this before starting the pager.

This commit would also fix #3543 on its own.
2016-06-16 09:30:18 -04:00
Lennart Poettering cf647b69ba systemctl: make sure we terminate the bus connection first, and then close the pager (#3550)
If "systemctl -H" is used, let's make sure we first terminate the bus
connection, and only then close the pager. If done in this order ssh will get
an EOF on stdin (as we speak D-Bus through ssh's stdin/stdout), and then
terminate. This makes sure the standard error we were invoked on is released by
ssh, and only that makes sure we don't deadlock on the pager which waits for
all clients closing its input pipe.

(Similar fixes for the various other xyzctl tools that support both pagers and
-H)

Fixes: #3543
2016-06-16 09:29:16 -04:00
Zbigniew Jędrzejewski-Szmek 33d52725f5 systemctl: also fall back to ListUnitsFiltered on access denied
When running systemctl from git on systemd from systemd-229-8.fc24.x86_64,
ListUnitsByPatterns results in org.freedesktop.DBus.Error.AccessDenied.
2016-06-15 10:03:33 -04:00
Zbigniew Jędrzejewski-Szmek 193edd61c3 systemctl: do not open pager twice
Second attempt had no effect anyway.
2016-06-15 09:44:07 -04:00
Lennart Poettering 3dced37b7c systemctl: rework "systemctl status" a bit
This reworks "systemctl status" and "systemctl show" a bit. It removes the
definition of the `property_info` structure, because we can simply reuse the
existing UnitStatusInfo type for that.

The "could not be found" message is now printed by show_one() itself (and not
its caller), so that it is shown regardless by who the function is called.
(This makes it necessary to pass the unit name to the function.)

This also adds all properties found to a set, and then checks if any of the
properties passed via "--property=" is mising in it, if so, a proper error is
generated.

Support for checking the PID file of a unit is removed, as this cannot be done
reasonably client side (since the systemd instance we are talking to might sit
on another host)

Replaces: #3411
Fixes: #3425
Also see: #3504
2016-06-13 19:17:14 +02:00
Lennart Poettering 51e22f8851 systemctl: fix assertion hit when showing state of a unit without control group 2016-06-13 18:54:36 +02:00
Zbigniew Jędrzejewski-Szmek 988b3b1765 systemctl: disallow systemctl --user reboot (#3519)
... as well as halt/poweroff/kexec/suspend/hibernate/hybrid-sleep.
Running those commands will fail in user mode, but we try to set the wall
message first, which might even succeed for privileged users. Best to nip
the whole sequence in the bud.

https://github.com/systemd/systemd/pull/3453#issuecomment-225455156
2016-06-13 07:57:28 +03:00
Lennart Poettering 2853b60ab5 systemctl: prolong timeout of "systemctl daemon-reload"
Reloading or reexecuting PID 1 means the unit generators are rerun, which are
timed out at 90s. Make sure the method call asking for the reload is timed out
at twice that, so that the generators have 90s and the reload operation has 90s
too.

This reworks the daemon_reload() call in systemctl, and makes it exclusively
about reloading/reexecing. Previously it was used for other trivial method
calls too, which didn't really help readability. As the code paths are now
sufficiently different, split out the old code into a new function
trivial_method().

This call also does a similar change as
c8ad4efb277c3235d58789170af11bb3c847d655 but for the reload/reexec operation.

Fixes: #3353
2016-06-10 20:13:29 +02:00
Lennart Poettering 033f0ab85d systemctl: don't suppress error code when handling legacy commands
For legacy commands such as /sbin/halt or /sbin/poweroff we support legacy
fallbacks that talk via traditional SysV way with PID 1 to issue the desired
operation. We do this on any kind of error if the primary method of operation
fails. When this is the case we suppress any error message that is normally
generated, in order to not confuse the user. When suppressing this log message,
don't suppress the original error code, because there's really no reason to.
2016-06-10 20:02:16 +02:00
Evgeny Vereshchagin 592705f2f7 systemctl: install sigbus handler (#3435)
This makes systemctl robust regarding journal truncation.
This is a follow-up for 2cf4172a71

Fixes:
Core was generated by `./systemctl status systemd-journald'.
Program terminated with signal SIGBUS, Bus error.
PID 8569 - core
TID 8569:
 #0  0x00007f246cc89ed6 __memcmp_sse4_1
 #1  0x0000557ebbc6f42c journal_file_init_header
 #2  0x0000557ebbc77262 journal_file_open
 #3  0x0000557ebbc42999 file_type_wanted
 #4  0x0000557ebbc42e08 add_any_file
 #5  0x0000557ebbc43832 add_directory
 #6  0x0000557ebbc4401c add_root_directory
 #7  0x0000557ebbc442e9 add_root_directory
 #8  0x0000557ebbc446fc add_search_paths
 #9  0x0000557ebbbacb5e show_journal_by_unit
 #10 0x0000557ebbb8376d print_status_info
 #11 0x0000557ebbb86a0b show_one
 #12 0x0000557ebbb87954 show
 #13 0x0000557ebbc20b1f dispatch_verb
 #14 0x0000557ebbb90615 systemctl_main
 #15 0x0000557ebbb9159f main
 #16 0x00007f246cb3e731 __libc_start_main
 #17 0x0000557ebbb75ae9 _start
2016-06-04 19:24:20 -04:00
Zbigniew Jędrzejewski-Szmek 20f8477be5 Merge pull request #3392 from poettering/assorted-stuff
Assorted stuff
2016-06-04 18:47:56 -04:00
Susant Sahani e33a06a1eb systemctl: systemctl show --property' needs verification of property (#3364)
systemctl --property doesn't validate if a requested property is valid or not,
and always returns with an exit code of 0, regardless of whether the requested
property exists or not.

How reproducible:

This works fine:

Id=multi-user.target
But put in a non-existing property:

Id=default.targets.service
Id=default.targets.service
0
[root@shou18lkvm8 ~]# systemctl show --property Id this.is.rubbish; echo $?
Id=this.is.rubbish.service
0

After:

sus@maximus bz-95593]$ ./systemctl show --property Id this.is.rubbish; echo $?
Can't display property this.is.rubbish. Unit this.is.rubbish.service does not
exist.
4

fixes #2295
2016-05-31 18:20:25 +02:00
Susant Sahani b613907ea9 systemctl: Replace init script error codes with enum (#3400)
Now we just using constants for the init script exit status codes.
Replace those error codes with enum so that it's more meaningful
and readable.
2016-05-31 15:36:58 +02:00
Lennart Poettering 3c6f7c3402 util-lib: make localed's nonempty() generic, rename it to empty_to_null() and make use of it everywhere 2016-05-30 17:59:43 +02:00
Susant Sahani ca473d572f systemctl: return diffrent error code if service exist or not (#3385)
Before:
[sus@maximus bz-1256858]$ systemctl status rsyslog.service;echo $?
● rsyslog.service - System Logging Service
   Loaded: loaded (/usr/lib/systemd/system/rsyslog.service; enabled; vendor
preset: enabled)
  Drop-In: /etc/systemd/system/rsyslog.service.d
           └─50-CPUShares.conf
   Active: inactive (dead) since Mon 2016-05-30 11:54:25 IST; 2h 26min ago
     Docs: man:rsyslogd(8)
           http://www.rsyslog.com/doc/
  Process: 1159 ExecStart=/usr/sbin/rsyslogd -n $SYSLOGD_OPTIONS (code=exited,
status=0/SUCCESS)
 Main PID: 1159 (code=exited, status=0/SUCCESS)

May 30 11:07:50 maximus systemd[1]: Starting System Logging Service...
May 30 11:07:50 maximus systemd[1]: Started System Logging Service.
May 30 11:54:25 maximus systemd[1]: Stopping System Logging Service...
May 30 11:54:25 maximus systemd[1]: Stopped System Logging Service.
3
[sus@maximus bz-1256858]$ systemctl status hello.service;echo $?
● hello.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
3

After:
$ ./systemctl status hello.service;echo $?
Failed to dump process list, ignoring: Access denied
● hello.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
4
[sus@maximus bz-1256858]$  ./systemctl status rsyslog.service;echo $?
Failed to dump process list, ignoring: Access denied
● rsyslog.service - System Logging Service
   Loaded: loaded (/usr/lib/systemd/system/rsyslog.service; enabled; vendor
preset: enabled)
  Drop-In: /etc/systemd/system/rsyslog.service.d
           └─50-CPUShares.conf
   Active: inactive (dead) since Mon 2016-05-30 11:54:25 IST; 2h 24min ago
     Docs: man:rsyslogd(8)
           http://www.rsyslog.com/doc/
  Process: 1159 ExecStart=/usr/sbin/rsyslogd -n $SYSLOGD_OPTIONS (code=exited,
status=0/SUCCESS)
 Main PID: 1159 (code=exited, status=0/SUCCESS)

May 30 11:07:50 maximus systemd[1]: Starting System Logging Service...
May 30 11:07:50 maximus systemd[1]: Started System Logging Service.
May 30 11:54:25 maximus systemd[1]: Stopping System Logging Service...
May 30 11:54:25 maximus systemd[1]: Stopped System Logging Service.
3

Fixes: 1092
2016-05-30 16:53:15 +02:00
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