Commit Graph

812 Commits

Author SHA1 Message Date
Lennart Poettering 2cdbbc9a34 man: avoid using the term "loaded" for units currently in memory, since we also have a unit state of that name
Fixes: #3971
2016-10-11 17:55:04 +02:00
Lennart Poettering 1f0958f640 core: when determining whether a process exit status is clean, consider whether it is a command or a daemon
SIGTERM should be considered a clean exit code for daemons (i.e. long-running
processes, as a daemon without SIGTERM handler may be shut down without issues
via SIGTERM still) while it should not be considered a clean exit code for
commands (i.e. short-running processes).

Let's add two different clean checking modes for this, and use the right one at
the appropriate places.

Fixes: #4275
2016-10-10 22:57:01 +02:00
Lennart Poettering 41e2036eb8 exit-status: kill is_clean_exit_lsb(), move logic to sysv-generator
Let's get rid of is_clean_exit_lsb(), let's move the logic for the special
handling of the two LSB exit codes into the sysv-generator by writing out
appropriate SuccessExitStatus= lines if the LSB header exists. This is not only
semantically more correct, bug also fixes a bug as the code in service.c that
chose between is_clean_exit_lsb() and is_clean_exit() based this check on
whether a native unit files was available for the unit. However, that check was
bogus since a long time, since the SysV generator was introduced and native
SysV script support was removed from PID 1, as in that case a unit file always
existed.
2016-10-10 21:48:08 +02:00
Martin Pitt 93a0884126 systemctl: Add --wait option to wait until started units terminate again
Fixes #3830
2016-10-01 17:58:59 +02:00
Zbigniew Jędrzejewski-Szmek bd5b9f0a12 systemctl: suppress errors with "show" for nonexistent units and properties
Show is documented to be program-parseable, and printing the warning about
about a non-existent unit, while useful for humans, broke a lot of scripts.
Restore previous behaviour of returning success and printing empty or useless
stuff for units which do not exist, and printing empty values for properties
which do not exists.

With SYSTEMD_LOG_LEVEL=debug, hints are printed, but the return value is
still 0.

This undoes parts of e33a06a and 3dced37b7 and fixes #3856.

We might consider adding an explicit switch to fail on missing units/properties
(e.g. --ensure-exists or similar), and make -P foobar equivalent to
--ensure-exists --property=foobar.
2016-09-24 21:09:39 -04:00
Zbigniew Jędrzejewski-Szmek 1cf03a4f8e systemctl,networkctl,busctl,backlight: use STRPTR_IN_SET 2016-09-24 20:22:05 -04:00
Zbigniew Jędrzejewski-Szmek 72240b52f1 systemctl: use STR_IN_SET 2016-09-24 19:17:31 -04:00
Cireo a6405ca288 systemctl: usable status command for special units (#4072)
Prior to this commit, users could be given an unusable command to run if
they attempted to stop or start special services.  For example:

    $ systemctl stop -- -.mount
    Failed to stop -.mount: Operation refused, unit -.mount may be \
        requested by dependency only.
    See system logs and 'systemctl status -.mount' for details.
    
    $ systemctl status -.mount
    systemctl: invalid option -- '.'
    
This adds a '--' to the example command in these situations.
2016-09-01 11:04:36 +02:00
WaLyong Cho 96e131ea09 core: introduce MemorySwapMax=
Similar to MemoryMax=, MemorySwapMax= limits swap usage. This controls
controls "memory.swap.max" attribute in unified cgroup.
2016-08-30 11:11:45 +09:00
Clinton Roy 169d7fb684 systemctl: kill all units specified on the command line, not just the first one. 2016-08-20 08:59:02 +10:00
Lennart Poettering 8673cf13c0 bus-util: unify loop around bus_append_unit_property_assignment()
This is done exactly the same way a couple of times at various places, let's
unify this into one version.
2016-08-18 22:23:31 +02:00
Zbigniew Jędrzejewski-Szmek 584c6e7050 journalctl,systemctl: add "short-full", "short-unix" mode to --help 2016-08-04 09:03:31 -04:00
Lukáš Nykrýn 7f5da8bd4f systemctl: consider service running only when it is in active or reloading state (#3874)
Otherwise for example services that are failing on start and have Restart=on-failure
and bigger RestartSec systemctl status will return 0.

Fixes: #3864
2016-08-03 17:08:37 +02:00
Christian Rebischke 689e4e6a94 systemctl: be sure to be quiet with 'systemctl is-enabled --quiet' (#3819)
Fixes #3813.
2016-07-27 22:40:20 -04:00
Michal Sekletar 1d3c86c06f systemctl: allow disable on the unit file path, but warn about it (#3806)
systemd now returns an error when it is asked to perform disable on the
unit file path. In the past this was allowed, but systemd never really
considered an actual content of the [Install] section of the unit
file. Instead it performed disable on the unit name, i.e. purged all
symlinks pointing to the given unit file (undo of implicit link action
done by systemd when enable is called on the unit file path) and all
symlinks that have the same basename as the given unit file.

However, to notice that [Install] info of the file is not consulted one
must create additional symlinks manually. I argue that in most cases
users do not create such links. Let's be nice to our users and don't
break existing scripts that expect disable to work with the unit file
path.

Fixes #3706.
2016-07-26 08:25:52 -04:00
Zbigniew Jędrzejewski-Szmek 9bb7194019 systemctl: use _cleanup_ for UnitCondition 2016-07-25 13:51:34 -04:00
Zbigniew Jędrzejewski-Szmek f8654baa08 systemctl: simplify machine_info_clear
It is only used with info allocated on the stack, so the pointer cannot be
NULL.
2016-07-25 13:51:34 -04:00
Zbigniew Jędrzejewski-Szmek 662bea6729 systemctl: avoid "leaking" some strings in UnitStatusInfo
% valgrind --leak-check=full systemctl status multipathd.service --no-pager -n0
...
==431== 16 bytes in 2 blocks are definitely lost in loss record 1 of 2
==431==    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
==431==    by 0x534AF19: strdup (in /usr/lib64/libc-2.23.so)
==431==    by 0x4E81AEE: free_and_strdup (string-util.c:794)
==431==    by 0x4EF66C1: map_basic (bus-util.c:1030)
==431==    by 0x4EF6A8E: bus_message_map_all_properties (bus-util.c:1153)
==431==    by 0x120487: show_one (systemctl.c:4672)
==431==    by 0x1218F3: show (systemctl.c:4990)
==431==    by 0x4EC359E: dispatch_verb (verbs.c:92)
==431==    by 0x12A3AE: systemctl_main (systemctl.c:7742)
==431==    by 0x12B1A8: main (systemctl.c:8011)
==431==
==431== LEAK SUMMARY:
==431==    definitely lost: 16 bytes in 2 blocks

This happens because map_basic() strdups the strings. Other code in systemctl
assigns strings to UnitStatusInfo without copying them, relying on the fact
that the message is longer lived than UnitStatusInfo. Add a helper function
that is similar to map_basic, but only accepts strings and does not copy them.
The alternative of continuing to use map_basic() but adding proper cleanup
to free fields in UnitStatusInfo seems less attractive because it'd require
changing a lot of code and doing a lot of more allocations for little gain.

(I put "leaking" in quotes, because systemctl is short lived anyway.)
2016-07-25 12:15:57 -04:00
Zbigniew Jędrzejewski-Szmek a733551846 systemctl: use cleanup function for UnitStatusInfo
There is no functional change, but clarity of the code is increased
by splitting out the cleanup part and putting it next to the structure
definition.
2016-07-25 11:53:14 -04:00
Zbigniew Jędrzejewski-Szmek 3d391fa84f Merge pull request #3681 from walyong/systemctl_condition 2016-07-25 11:27:14 -04:00
Zbigniew Jędrzejewski-Szmek b1ed76ae19 systemctl: style tweaks for the new condition code 2016-07-25 11:20:58 -04:00
Lennart Poettering 3990961df0 man: update systemctl man page for unit file commands, in particular "systemctl enable"
Clarify that "systemctl enable" can operate either on unit names or on unit
file paths (also, adjust the --help text to clarify this). Say that "systemctl
enable" on unit file paths also links the unit into the search path.

Many other fixes.

This should improve the documentation to avoid further confusion around #3706.
2016-07-25 15:16:48 +02:00
Zbigniew Jędrzejewski-Szmek d710aaf7a5 Use "return log_error_errno" in more places" 2016-07-22 21:25:09 -04:00
Zbigniew Jędrzejewski-Szmek 31b14fdb6f Merge pull request #3777 from poettering/id128-rework
uuid/id128 code rework
2016-07-22 21:18:41 -04:00
Lennart Poettering e08ab37902 systemctl: never check inhibitors if -H or -M are used (#3781)
Don't check inhibitors when operating remotely. The interactivity inhibitors
imply can#t be provided anyway, and the current code checks for local sessions
directly, via various sd_session_xyz() APIs, hence bypass it entirely if we
operate on remote systems.

Fixes: #3476
2016-07-22 17:39:21 +02:00
Lennart Poettering 2a6736ddd0 systemctl: fix format string for uint64_t field 2016-07-22 12:59:36 +02:00
Lennart Poettering 1089dcd469 systemctl: fix output alignment in "systemctl status"
If we show both a control and a main PID for a service fix this line in the
output of "systemctl status":

 Main PID: 19670 (sleep);         : 19671 (sleep)

to become this:

 Main PID: 19670 (sleep); Control PID: 19671 (sleep)
2016-07-22 12:59:36 +02:00
Thomas Hindoe Paaboel Andersen ba19c6e181 treewide: remove unused variables 2016-07-18 22:32:08 +02:00
WaLyong Cho d5db7fe66a systemctl: show failed condition list
When unit has multiple condition list, systemctl is not showing which
conditions were failed. When user want to know which conditions were
failed, user has to check for each conditions.
So, show failed condition list also.
2016-07-11 10:19:55 +09:00
Susant Sahani d6568222d7 systemctl mask of an non-existent unit should print a warning (#3521)
fixes https://bugzilla.redhat.com/show_bug.cgi?id=842060
2016-06-28 21:27:07 +01:00
Lénaïc Huard a1abf5ea7f Remove blank line in the output of “systemctl show” (#3614)
“systemctl show” added an extra blank line after the dump of the
EnvironmentFile property of the unit.
2016-06-28 20:15:33 +02:00
Lennart Poettering dbf43a1b3a systemctl: fix an error condition from "-1" to something meaningful
We really shouldn't make up errors like "-1", but use proper errno definitions.
2016-06-24 21:03:47 +02:00
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
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