Commit graph

684 commits

Author SHA1 Message Date
Lennart Poettering c4f4fce79e fs-util: add flags parameter to chase_symlinks()
Let's remove chase_symlinks_prefix() and instead introduce a flags parameter to
chase_symlinks(), with a flag CHASE_PREFIX_ROOT that exposes the behaviour of
chase_symlinks_prefix().
2016-12-01 00:25:51 +01:00
Franck Bui c5024cd05c systemctl: fix 'is-enabled' exit status on failure when executed in chroot (#4773) 2016-11-30 18:27:42 +01:00
Franck Bui acc28e2e30 core: make sure initrd-switch-root command survives PID1's killing spree (#4730)
This is a different way to implement the fix proposed by commit
a4021390fe suggested by Lennart Poettering.

In this patch we instruct PID1 to not kill "systemctl switch-root" command
started by initrd-switch-root service using the "argv[0][0]='@'" trick.

See: https://www.freedesktop.org/wiki/Software/systemd/RootStorageDaemons/ for
more details.

We had to backup argv[0] because argv is modified by dispatch_verb().
2016-11-24 18:52:04 +01:00
Zbigniew Jędrzejewski-Szmek 76d8ca2229 core/dbus-job, systemctl: shorten some code 2016-11-16 21:01:11 -05:00
Zbigniew Jędrzejewski-Szmek bc357ce5d7 systemctl: shorter list-jobs --before/--after output a bit
(before)$ systemctl list-jobs  --before --after
 JOB UNIT                                          TYPE  STATE
8769 foobar.device                                 start running
        A job waits for this job: 8669 (run-rb6da596d0cfa4e36b7c594cd973e795a.service/start)
8669 run-rb6da596d0cfa4e36b7c594cd973e795a.service start waiting
        This job waits for a job: 8769 (foobar.device/start)

2 jobs listed.

(after)$ systemctl list-jobs  --before --after
 JOB UNIT                                          TYPE  STATE
8769 foobar.device                                 start running
        waiting for job 8669 (run-rb6da596d0cfa4e36b7c594cd973e795a.service/start)
8669 run-rb6da596d0cfa4e36b7c594cd973e795a.service start waiting
        blocking job 8769 (foobar.device/start)

2 jobs listed.
2016-11-16 20:51:47 -05:00
Lennart Poettering 82948f6c8e systemctl: show waiting jobs when "systemctl list-jobs --after/--before" is called
Let's expose the new bus functions we added in the previous commit in
systemctl.
2016-11-16 17:01:46 +01:00
Lennart Poettering d4015567ad systemctl: add env var to force connection to system manager via the bus
Sometimes it is useful for debugging purposes to force systemctl to connect to
PID 1 via the bus instead of direct connection, even if the direct connection
is possible.
2016-11-16 15:03:26 +01:00
Felipe Sateler c6dd36b65c systemctl: resolve symlinks when finding unit paths (#4545)
Otherwise we think the alias is the real unit, and may edit/cat the
wrong unit.

Before this patch:
 $ systemctl edit autovt@ # creates dropin in /etc/systemd/system/autovt@.service.d
 $ systemctl cat autovt@ | grep @.service
 # /lib/systemd/system/autovt@.service
 # that serial gettys are covered by serial-getty@.service, not this
 # /etc/systemd/system/autovt@.service.d/override.conf
 $ systemctl cat getty@ | grep @.service
 # /lib/systemd/system/getty@.service
 # that serial gettys are covered by serial-getty@.service, not this

After this patch
 $ systemctl edit autovt@ # creates dropin in /etc/systemd/system/getty@.service.d
 $ systemctl cat autovt@ | grep @.service
 # /usr/lib/systemd/system/getty@.service
 # that serial gettys are covered by serial-getty@.service, not this
 # /etc/systemd/system/getty@.service.d/override.conf
 systemctl cat getty@ | grep @.service
 # /usr/lib/systemd/system/getty@.service
 # that serial gettys are covered by serial-getty@.service, not this
 # /etc/systemd/system/getty@.service.d/override.conf
2016-11-11 21:28:06 -05:00
Zbigniew Jędrzejewski-Szmek c58bd76a6a tree-wide: make invocations of extract_first_word more uniform (#4627)
extract_first_words deals fine with the string being NULL, so drop the upfront
check for that.
2016-11-11 18:58:41 +01:00
Zbigniew Jędrzejewski-Szmek f97b34a629 Rename formats-util.h to format-util.h
We don't have plural in the name of any other -util files and this
inconsistency trips me up every time I try to type this file name
from memory. "formats-util" is even hard to pronounce.
2016-11-07 10:15:08 -05:00
Lennart Poettering 493fd52f1a Merge pull request #4510 from keszybz/tree-wide-cleanups
Tree wide cleanups
2016-11-03 13:59:20 -06:00
Zbigniew Jędrzejewski-Szmek 7fa6328cc4 Merge pull request #4481 from poettering/perpetual
Add "perpetual" unit concept, sysctl fixes, networkd fixes, systemctl color fixes, nspawn discard.
2016-11-02 21:03:26 -04:00
Lucas Werkmeister 5b9635d166 systemctl: fix incorrect "need reload" on cat (#4535)
Reported by @evverx in #4493.
2016-11-02 16:12:03 -06:00
Lennart Poettering b5d7f1bbfa systemctl: tweak the "systemctl list-units" output a bit
Make the underlining between the header and the body and between the units of
different types span the whole width of the table.

Let's never make the table wider than necessary (which is relevant due the
above).

When space is limited and we can't show the full ID or description string
prefer showing the full ID over the full description. The ID is after all
something people might want to copy/paste, while the description is mostly just
helpful decoration.
2016-11-02 11:39:49 -06:00
Lennart Poettering 835a19e02f systemctl: properly turn off color after active column
If we turn on red color for the active column and it is not combined with
underlining, then we need to turn it off explicitly afterwards. Do that.
2016-11-02 11:39:49 -06:00
Lucas Werkmeister e100155dcc systemctl: warn when cat shows changed unit files (#4493)
Suggested by @keszybz in #4488.
2016-10-27 09:28:10 -04:00
Lennart Poettering 6fa4160def systemctl: fix two minor memory leaks in --wait handling
(Also, let's not use the binary |= operator on "bool" variables).

Fix-up for 93a0884126.
2016-10-25 12:19:13 +02:00
Jan Synacek 3b3557c410 shared, systemctl: teach is-enabled to show installation targets
It may be desired by users to know what targets a particular service is
installed into. Improve user friendliness by teaching the is-enabled
command to show such information when used with --full.

This patch makes use of the newly added UnitFileFlags and adds
UNIT_FILE_DRY_RUN flag into it. Since the API had already been modified,
it's now easy to add the new dry-run feature for other commands as
well. As a next step, --dry-run could be added to systemctl, which in
turn might pave the way for a long requested dry-run feature when
running systemctl start.
2016-10-24 10:19:08 +02:00
Jan Synacek b3796dd834 install: introduce UnitFileFlags
Introduce a new enum to get rid of some boolean arguments of unit_file_*
functions. It unifies the code, makes it a bit cleaner and extensible.
2016-10-24 10:19:08 +02:00
Zbigniew Jędrzejewski-Szmek 605405c6cc tree-wide: drop NULL sentinel from strjoin
This makes strjoin and strjoina more similar and avoids the useless final
argument.

spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c)

git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/'

This might have missed a few cases (spatch has a really hard time dealing
with _cleanup_ macros), but that's no big issue, they can always be fixed
later.
2016-10-23 11:43:27 -04:00
Zbigniew Jędrzejewski-Szmek 6ae3e62a54 systemctl: ditto for list-unit-files 2016-10-17 11:47:45 -04:00
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