Commit graph

663 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 16484a8a15 systemctl: use underlines to seperate unit types in listing
(printf("%.*s", -1, "…") is the same as not specifying the precision at all.)

v2: also underline highlighted (failing) units

Fixes #4137.
2016-10-17 11:37:41 -04:00
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