Commit graph

733 commits

Author SHA1 Message Date
Daniel Mack 0e97c93fe5 systemctl: report accounted network traffic in "systemctl status"
This hooks up the eposed D-Bus values and displays them like this:

-bash-4.3# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/etc/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2016-11-11 20:10:36 CET; 1min 29s ago
 Main PID: 33 (httpd)
   Status: "Total requests: 22514; Idle/Busy workers 92/7;Requests/sec: 259; Bytes served/sec:  87KB/sec"
  Network: 15.8M in, 51.1M out
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   CGroup: /system.slice/httpd.service
           ├─ 33 /usr/sbin/httpd -DFOREGROUND
           ├─ 37 /usr/sbin/httpd -DFOREGROUND
           ├─112 /usr/sbin/httpd -DFOREGROUND
           └─119 /usr/sbin/httpd -DFOREGROUND
2017-09-22 15:24:55 +02:00
Lennart Poettering aaa6732d78 systemctl: make sure we properly turn off color at the end of each line of "list-unit-files" (#6688)
Let's simplify the code a bit, and make sure we always turn off color
and underlining again on each line, if we used it.

Fixes: #6684
2017-09-05 16:31:26 +02:00
Lennart Poettering 8ce41a7f9a Merge pull request #6741 from keszybz/template-loading-fix
Fix for mask/unmask operations on templates and multiple units
2017-09-04 18:57:06 +02:00
Zbigniew Jędrzejewski-Szmek 173471b771 systemctl: fix masking of template units
systemctl would try to load the properties of the unit, which is impossible
for template names, and the whole operation would fail. It seems that this
regression was introduced in 00c83b4300.

Export the part of unit_find_paths() responsible for locating instance unit
fragments and reuse it from unit_exists() to fix the handling of template
units.

Fixes #6412.
2017-09-03 17:55:10 +03:00
Zbigniew Jędrzejewski-Szmek f8d6cb48a3 systemctl: check existence of all units, not just the first one 2017-09-03 17:49:02 +03:00
Alan Jenkins 78ca909980 systemctl: remove compiler warning (#6717)
913c1916 changed _ACTION_INVALID to negative, changing the enum to a
signed type.  Take care to avoid comparing it with an unsigned type.

../src/systemctl/systemctl.c: In function ‘start_unit’:
../src/systemctl/systemctl.c:3107:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 assert(arg_action < ELEMENTSOF(action_table));
2017-09-01 09:02:32 +09:00
Lennart Poettering dfff69bfc4 Merge pull request #6637 from sourcejedi/systemctl_cleanup
systemctl: improve readability of start_unit()
2017-08-31 18:51:25 +02:00
Lennart Poettering ee043777be tree-wide: use pid_is_valid() at more places 2017-08-31 15:45:04 +02:00
Alan Jenkins 913c19161a systemctl: improve readability of start_unit()
start_unit() is a little tangled.  There's an easy part we can untangle,
then readers can concentrate on the more necessary complexity.

* Derive (method, action, mode) more clearly, as disjoint cases based on
  the command.  Don't rely on action_table[_ACTION_INVALID].target being
  implicitly initialized to NULL.

  verb_to_method() is now only used on one case, but not because I strongly
  object to the implicit "StartUnit" cases.  It's more a syntax problem.
  I think the old code takes me longer to understand, because the call
  comes just above a similar-looking call to verb_to_action(), but the
  results of the two functions are used in different ways.  It also helps
  that the new code ends up having a more regular form, for the 4 different
  cases.

  These changes cost 6 extra lines.

* Add an assertion to confirm that we do not pass mode=NULL.
2017-08-31 14:05:28 +01:00
Alan Jenkins 081dc63822 systemctl: clarify code - some actions never appear in arg_action (#6638)
ACTION_EMERGENCY and ACTION_DEFAULT would be handled correctly by
start_with_fallback().  However there is no fallback available for
them, and they would never be set in `arg_action` in the first
place.  Remove the unused cases from the switch statement.

@poettering suggested this makes a good place to clarify the point,
explicitly listing all the `arg_action` values which would never be
set.
2017-08-31 10:54:12 +02:00
Alan Jenkins f886603b7e systemctl: don't allow --wait with commands that might not start units
There's no good reason to use `--wait` with ReloadOrRestartUnit, or
TryRestartUnit.

The message was also wrong in another sense.  'systemctl isolate'
starts units, but it did not support `--wait`.  Although it's
unlikely anyone would want to do that in the first place.
2017-08-18 13:46:41 +01:00
Lennart Poettering 7bf7ce28b5 string-util: add strlen_ptr() helper
strlen_ptr() is to strlen() what streq_ptr() is to streq(): i.e. it
handles NULL strings in a smart way.
2017-07-31 18:20:28 +02:00
Zbigniew Jędrzejewski-Szmek 4bc5d27b94 Drop busname unit type
Since busname units are only useful with kdbus, they weren't actively
used. This was dead code, only compile-tested. If busname units are
ever added back, it'll be cleaner to start from scratch (possibly reverting
parts of this patch).
2017-07-23 09:29:02 -04:00
Boucman decd79829a expand path of systemctl link argument (#6186)
systemctl link is the only systemctl verb that takes a filename (and not
a unit name) as argument

use path_strv_make_absolute_cwd to expand the provided filename in order
to make it easier to use from the command line

keep the absolute pathname requirement when --root is used

[zj: add explicit error messages for the cases of --root and plain filename
instead of skipping normalization and just relying on systemd to refuse
to link non-absolute arguments. This allows us to make the error message
more informative.]
2017-07-09 19:52:25 -04:00
Giedrius Statkevičius 601b08420d systemctl: print next timer trigger time with the status verb (#6242)
It is useful to know when a timer will trigger next when looking at a
timer status message so calculate and print that information.

Closes #5738.

Example output:
$ systemctl status dnf-makecache.timer
● dnf-makecache.timer - dnf makecache timer
   Loaded: loaded (/usr/lib/systemd/system/dnf-makecache.timer; enabled; vendor preset: enabled)
   Active: active (waiting) since Tue 2017-07-04 17:24:02 EDT; 24min ago
  Trigger: Tue 2017-07-04 18:15:56 EDT; 27min left
2017-07-04 17:51:02 -04:00
Lennart Poettering 60675884cb systemctl: quieten a few more messages if -q is specified
As suggested by @mbiebl in https://github.com/systemd/systemd/pull/6199
2017-06-26 20:42:08 +02:00
Lennart Poettering 8ecc68f430 systemctl: be truly quiet in systemctl -q is-enabled
Fixes: #6196
2017-06-26 16:11:20 +02:00
Lennart Poettering 6c223c6719 Merge pull request #6113 from keszybz/shell-quoting
Use "dollar-single-quotes" to escape shell-sensitive strings
2017-06-20 20:17:03 +02:00
Zbigniew Jędrzejewski-Szmek 804ee07c13 Use "dollar-single-quotes" to escape shell-sensitive strings
Also called "ANSI-C Quoting" in info:(bash) ANSI-C Quoting.

The escaping rules are a POSIX proposal, and are described in
http://austingroupbugs.net/view.php?id=249. There's a lot of back-and-forth on
the details of escaping of control characters, but we'll be only using a small
subset of the syntax that is common to all proposals and is widely supported.
Unfortunately dash and fish and maybe some other shells do not support it (see
the man page patch for a list).

This allows environment variables to be safely exported using show-environment
and imported into the shell. Shells which do not support this syntax will have
to do something like
    export $(systemctl show-environment|grep -v '=\$')
or whatever is appropriate in their case. I think csh and fish do not support
the A=B syntax anyway, so the change is moot for them.

Fixes #5536.

v2:
- also escape newlines (which currently disallowed in shell values, so this
  doesn't really matter), and tabs (as $'\t'), and ! (as $'!'). This way quoted
  output can be included directly in both interactive and noninteractive bash.
2017-06-19 19:39:43 -04:00
Zbigniew Jędrzejewski-Szmek e3f791a2b3 basic/path-util: allow flags for path_equal_or_files_same
No functional change, just a new parameters and the tests that
AT_SYMLINK_NOFOLLOW works as expected.
2017-06-17 12:37:16 -04:00
Zbigniew Jędrzejewski-Szmek 19fbf49cde systemctl: avoid spurious warning about missing reboot-param file
$ reboot -f
Failed to read reboot parameter file: No such file or directory

It seems that the warning on ENOENT was inadvertently introduced in
27c06cb516.

The warning reported in #5646 comes from systemctl, but let's fix the other
call site in the same way too.

Fixes #5646.
2017-05-30 23:41:31 -04:00
Ian Wienand 7e563bfc97 Add short-iso-precise for journalctl output (#5884)
This adds a short-iso-precise option for journalctl output.  It is similar to
short-iso, but includes microseconds.
2017-05-07 20:23:49 -04:00
Zbigniew Jędrzejewski-Szmek 79f1c8f619 build-sys: use a single ENABLE_LOGIND conditional
We used ENABLE_LOGIND for the automake conditional, and HAVE_LOGIND
for the ifdef. That wasn't wrong, but it certainly was confusing.

Also, move the ifdeffery to avoid warning about unused static function
logind_set_wall_message() when logind is disabled.
2017-04-04 20:36:09 -04:00
Felix Zhang 6070504015 systemctl: fix broken vertical lines in list-dependencies --all (#5608) 2017-03-20 11:27:39 +01:00
Lennart Poettering 523f8cde4c systemctl: fix bad memory access when mangle_names() fails (#5485)
Fixes #5483
2017-02-28 16:55:18 +01:00
Lennart Poettering 10ab1831de systemctl: suffix cmdline options that take arguments with =
Just to clarify, that these options expect arguments, following our
usual style.
2017-02-21 11:17:24 +01:00
Lucas Werkmeister cc7de2ba32 tree-wide: add man: to manpage references (#5402)
Found with:

    git grep '"[^"]*[a-z0-9]([0-9]\+p\?)' src/ | grep -vF man:
2017-02-20 18:45:35 -05:00
Benjamin Robin 5955df2c40 systemctl: Fix condition in start_special() (#5399) 2017-02-20 16:11:34 -05:00
Lennart Poettering 04a0891038 Merge pull request #5392 from keszybz/systemctl-edit
systemctl edit & reboot fixlets
2017-02-20 16:30:58 +01:00
Zbigniew Jędrzejewski-Szmek 2b0f4e6f21 systemctl: give a hint about --force --force when communication with manager fails
The hint is not too explicit, and just refers to the man page, because this
option is slightly dangereous. This was we don't have to discuss the limitation
in the hint itself.

Fixes #4002.
2017-02-19 18:56:02 -05:00
Zbigniew Jędrzejewski-Szmek 0dcabf0968 systemctl: fix hint with edit --global/--user 2017-02-19 17:42:18 -05:00
Zbigniew Jędrzejewski-Szmek b3734d9841 systemctl: fix editing of units with no fragment
"systemctl --user edit --force --full tmp.mount" would crash, when we'd do
basename(NULL). Fix this by creating a new unit or a new override even if
not path is found.

Tested with:
systemctl --user edit --force --full tmp.mount
systemctl --user edit --force tmp.mount
systemctl --user edit foo@.service
systemctl --user edit foo@bar.service
systemctl --user edit --full foo@.service
systemctl --user edit --full foo@bar.service
2017-02-19 17:42:18 -05:00
Zbigniew Jędrzejewski-Szmek b74df547a9 systemctl: when told to edit an instance, do not edit the template
Fixes #5383.
2017-02-19 17:42:18 -05:00
Lucas Werkmeister 6862111ecf systemctl: fix error messages (#5389) 2017-02-19 12:03:15 -05:00
Lennart Poettering 1c876927e4 copy: change the various copy_xyz() calls to take a unified flags parameter
This adds a unified "copy_flags" parameter to all copy_xyz() function
calls, replacing the various boolean flags so far used. This should make
many invocations more readable as it is clear what behaviour is
precisely requested. This also prepares ground for adding support for
more modes later on.
2017-02-17 10:22:28 +01:00
Lennart Poettering f9e0eefc7c tree-wide: make bus_map_all_properties return a proper sd_bus_error
And then show it, to make things a bit friendlier to the user if we fail
acquiring some props.

In fact, this fixes a number of actual bugs, where we used an error
structure for output that we actually never got an error in.
2017-02-09 16:13:07 +01:00
Jan Synacek 6bc30691b1 systemctl: make sure that --now is carried out (#5209)
When services are already enabled/disabled/masked, make sure
that --now still enforces start/stop.
2017-02-08 20:57:08 +01:00
Zbigniew Jędrzejewski-Szmek 9577878210 core: when loading .wants and .requires, follow the same logic as .d conf dropins
Essentially, instead of sequentially adding deps based on all symlinks
encountered in .wants and .requires dirs for each name and each unit file load
path, iteratate over the load paths and unit names gathering symlinks, then
order them based on priority, and then iterate over the final list, adding
dependencies.

This patch doesn't change the logic too much, except that the order in which
dependencies are applied might be different. It wasn't defined before, so that
not really a change. Adding filtering on the symlinks is left for later
patches.
2017-02-07 21:31:22 -05:00
Lennart Poettering 5c1d991f40 Merge pull request #5213 from keszybz/systemctl-root-cat
Two fixes to path lookup when --root is used
2017-02-03 11:02:28 +01:00
Franck Bui f1669917f5 systemctl: 'show' don't exit with a failure status if the requested property does not exist (#5201)
"systemctl show -pUnknown <service>" used to exit with '0' even if the property
passed by '-p' doesn't exist. But since commit 3dced37b7c (v231+),
it exits with a failure status.

"systemctl show" is supposed to be scriptable and therefore its behavior is
supposed to be stable.

This patch restores the old behavior on which a couple of scripts already rely
now.

Also when the requested property doesn't exist, it always logs it at the debug
level since this part of the code is only used by the show command.

Fixes: #5118
2017-02-02 13:29:44 -05:00
Zbigniew Jędrzejewski-Szmek 17e78d1825 systemctl: also use chase_symlinks for dropins
The general rule is:
- code in shared/ should take an "original_root" argument (possibly NULL)
  and pass it along down to chase_symlinks
- code in core/ should always use specify original_root==NULL, since we
  don't support running the manager from non-root directory
- code in systemctl and other tools should pass arg_root.

For any code that is called from tools which support --root, chase_symlinks
must be used to look up paths.
2017-02-02 12:17:20 -05:00
Zbigniew Jędrzejewski-Szmek 3ef21542b2 systemctl: do not prepend arg_root twice when catting units
The paths in lookup_paths already contain the arg_root prefix.

Fixes #5190.
2017-02-02 11:32:40 -05:00
Zbigniew Jędrzejewski-Szmek bef19548a2 systemctl: restore --failed (#5198)
'systemctl --failed' is an extremely common operation and it's nice to have
a shortcut for it.

Revert "man: don't document systemctl --failed" and add the option back to
systemctl's help and shell completion scripts.

This reverts commit 036359ba8d.
2017-02-02 00:23:46 +01:00
Zbigniew Jędrzejewski-Szmek 8a7a9ceab2 systemctl: ignore SIGTERM after switch root
https://bugzilla.redhat.com/show_bug.cgi?id=1414904#c14 and #c15.
2017-01-31 01:34:40 -05:00
Zbigniew Jędrzejewski-Szmek b3ad0ff48c systemctl: always avoid being killed when doing switch-root
The same logic as described in acc28e2e30 applies to any time we are
switching root, to just set the flag unconditionally.
2017-01-31 01:34:40 -05:00
Zbigniew Jędrzejewski-Szmek a9bd056ad9 systemctl: fix alignment with units in not-found state
A fixed value (6 and later 5) was added back in 4deb3b9391, and
not updated when load_len was added later on.

Also the other 5 with 1 + 1 + 1 + 1 + 1 to make it easier to see
that this is about the column separators.
2017-01-15 13:38:43 -05:00
Zbigniew Jędrzejewski-Szmek 43479f8d21 systemctl: uninitalized variable
CID #1368270.

Easily reproduced with COLUMNS=50 ./systemctl --no-pager.
2017-01-15 13:27:37 -05:00
Franck Bui a69f65dd3d systemctl: remove duplicate entries showed by list-dependencies (#5049)
When a unit is part of several dependency constraints of another
unit, list-dependencies repeats the name of the dependency for each
dep constraint the unit is encountered.

For example:

 $ systemctl cat test-main.target
 # /etc/systemd/system/test-main.target
 [Unit]
 Description=Main Target

 $ systemctl cat test.target
 [Unit]
 Description=Sub target
 PartOf=test-main.target

 [Install]
 WantedBy=test-main.target

 $ systemctl enable test.target
 Created symlink from /etc/systemd/system/test-main.target.wants/test.target to /etc/systemd/system/test.target.

 $ systemctl show test-main.target | grep test.target
 Wants=test.target
 ConsistsOf=test.target
 [...]

 $ systemctl list-dependencies test-main.target
 test-main.target
 ● ├─test.target
 ● └─test.target

With this patch applied, dependencies are shown only once.
2017-01-11 21:37:15 -05:00
Zbigniew Jędrzejewski-Szmek 6483ad89f5 systemctl: do not segfault when we cannot find template unit (#4915)
Core was generated by `systemctl cat test@.target test@.service'.
Program terminated with signal SIGSEGV, Segmentation fault.
32              movdqu  (%rdi), %xmm0
(gdb) bt
-0  strrchr () at ../sysdeps/x86_64/strrchr.S:32
-1  0x00007f57fdf837fe in __GI___basename (filename=0x0) at basename.c:24
-2  0x000055b8a77d0d91 in unit_find_paths (bus=0x55b8a9242f90, unit_name=0x55b8a92428f0 "test@.service", lp=0x7ffdc9070400, fragment_path=0x7ffdc90703e0, dropin_paths=0x7ffdc90703e8) at src/systemctl/systemctl.c:2584
-3  0x000055b8a77dbae5 in cat (argc=3, argv=0x7ffdc9070678, userdata=0x0) at src/systemctl/systemctl.c:5324
-4  0x00007f57fe55fc6b in dispatch_verb (argc=5, argv=0x7ffdc9070668, verbs=0x55b8a77f1c60 <verbs>, userdata=0x0) at src/basic/verbs.c:92
-5  0x000055b8a77e477f in systemctl_main (argc=5, argv=0x7ffdc9070668) at src/systemctl/systemctl.c:8141
-6  0x000055b8a77e5572 in main (argc=5, argv=0x7ffdc9070668) at src/systemctl/systemctl.c:8412

The right behaviour is not easy in this case. Implement some "sensible" logic.

Fixes #4912.
2016-12-20 11:09:59 +01:00
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