Commit Graph

1120 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 2811184a09 systemctl: add comment why whitespace in message is needed 2018-12-18 12:18:49 +01:00
Lennart Poettering 9a6f746fb6 locale-util: prefix special glyph enum values with SPECIAL_GLYPH_
This has been irritating me for quite a while: let's prefix these enum
values with a common prefix, like we do for almost all other enums.

No change in behaviour, just some renaming.
2018-12-14 08:22:54 +01:00
Zbigniew Jędrzejewski-Szmek 9be3c60570
Merge pull request #10892 from mbiebl/revert-systemctl-runtime-unmask-breakage
Revert "systemctl: when removing enablement or mask symlinks, cover both /run and /etc
2018-12-12 14:23:04 +01:00
Yu Watanabe 416b88013c systemctl: check triggering units only for stopped units
Fixes #11088.
2018-12-10 11:06:28 +01:00
Zbigniew Jędrzejewski-Szmek 2e7e19cafc systemctl: be nice to users and give hint how to specify "-.mount"
https://bugzilla.redhat.com/show_bug.cgi?id=1656639
Using "--" is a trick that is hard to discover. Let's give users a hint:

$ build/systemctl status -.service
  build/systemctl: invalid option -- '.'
  Hint: to specify units starting with a dash, use "--":
        build/systemctl [OPTIONS...] {COMMAND} -- -.service ...

I use program_invocation_name because that's what getopt seems to use.
"::" is used in the option string so that getopt doesn't complain about
a missing argument in case somebody passes "-." as the argument. After all
"." is not a real option.
2018-12-07 02:49:03 +01:00
Zbigniew Jędrzejewski-Szmek 871fa294ff Merge pull request #10935 from poettering/rlimit-nofile-safe
Merged by hand to resolve a trivial conflict in TODO.
2018-12-06 17:19:21 +01:00
Zbigniew Jędrzejewski-Szmek 2d479ff1cc
Merge pull request #10963 from poettering/bus-force-state-change-signal
force PropertiesChanged bus signal on all unit state changes
2018-12-06 16:42:21 +01:00
Marc-Antoine Perennou f73a961826 systemctl: drop my copyright
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2018-12-05 11:33:28 +01:00
Yu Watanabe f2a3de0116 tree-wide: add whitespace between type and variable name 2018-12-04 09:29:54 +01:00
Lennart Poettering e4de72876e util-lib: split out all temporary file related calls into tmpfiles-util.c
This splits out a bunch of functions from fileio.c that have to do with
temporary files. Simply to make the header files a bit shorter, and to
group things more nicely.

No code changes, just some rearranging of source files.
2018-12-02 13:22:29 +01:00
Lennart Poettering 109b0cbf24 systemctl: rework --wait logic
Let's not honour PropertiesChanged signals unless the Jobs properties is
empy. After all we shouldn't consider a service finished unless its
state is inactive/failed *and* no job is queued for it anymore.
2018-12-01 12:53:26 +01:00
Lennart Poettering 0672e2c6f8 tree-wide: use FORK_RLIMIT_NOFILE_SAFE wherever possible
Similar to the previous commit: in many cases no further fd processing
needs to be done in forked of children before execve() or any of its
flavours are called. In those case we can use FORK_RLIMIT_NOFILE_SAFE
instead.
2018-12-01 12:50:45 +01:00
Lennart Poettering 595225af7a tree-wide: invoke rlimit_nofile_safe() before various exec{v,ve,l}() invocations
Whenever we invoke external, foreign code from code that has
RLIMIT_NOFILE's soft limit bumped to high values, revert it to 1024
first. This is a safety precaution for compatibility with programs using
select() which cannot operate with fds > 1024.

This commit adds the call to rlimit_nofile_safe() to all invocations of
exec{v,ve,l}() and friends that either are in code that we know runs
with RLIMIT_NOFILE bumped up (which is PID 1 and all journal code for
starters) or that is part of shared code that might end up there.

The calls are placed as early as we can in processes invoking a flavour
of execve(), but after the last time we do fd manipulations, so that we
can still take benefit of the high fd limits for that.
2018-12-01 12:50:45 +01:00
Zbigniew Jędrzejewski-Szmek 652ef29887 path-util: allow NULLs in arguments to path_join()
This removes the need to remember to put strempty() in places, thus reducing
the likelihood of a stupid mistake.
2018-11-30 22:21:17 +01:00
Zbigniew Jędrzejewski-Szmek 62a85ee0a9 tree-wide: rename path_join_many() to path_join()
$ git grep -e path_join_many -l|xargs sed -r -i 's/path_join_many/path_join/g'

The two test functions are merged into one.
2018-11-30 10:59:47 +01:00
Zbigniew Jędrzejewski-Szmek 30016f21b3 tree-wide: replace path_join with path_join_many 2018-11-30 10:40:38 +01:00
Lennart Poettering 02a126a33d systemctl: if service manager couldn't load unit file, don't rely on it to tell us the fragment path
Previously, "systemctl edit" exclusively used the service manager's
per-unit FragmentPath property to figure out which file to edit, when
operating on a non-template unit. If for some reason loading the unit
file failed entirely though (LoadState=error), then FragmentPath would
be empty, and thus the unit not editable.

Let's fix this, by falling back to client-side unit file searching in
this case.

(Also, various other clean-ups to make the relevant functions follow our
coding style)

Fixes: #9561
2018-11-29 11:25:32 +01:00
Lennart Poettering 85163756da systemctl: rework message suggesting how to create a new unit file
We need to specifiy --full for creating full unit files.

Also, this is an explanatory hint, hence shouldn't be logged on LOG_ERR
level.
2018-11-29 11:25:32 +01:00
Lennart Poettering df79fdab21 systemctl: shorten code a bit 2018-11-29 11:25:32 +01:00
Lennart Poettering 5daacba233 systemctl: improve message when we skip a unit for editing a bit 2018-11-29 11:25:32 +01:00
Lennart Poettering 92d6b0bfdc systemctl: use _cleanup_ logic for error paths in unit_file_create_copy(), too 2018-11-29 11:25:32 +01:00
Lennart Poettering 919d272085 systemctl: rework error paths in unit_file_create_new()
Let's use _cleanup_ to clean up stuff for us.
2018-11-29 11:25:32 +01:00
Lennart Poettering b03677e2da systemctl: rework unit_find_template_path() to follow coding style
This makes sure that we don't clobber return values on failure and reset
all return values on success.
2018-11-29 11:25:32 +01:00
Lennart Poettering f67cb27060 systemctl: make sure we initialize return parameters in unit_file_find_path() on success
According to our coding style return values should be initialized when
we return any form of success, do so here too.
2018-11-29 11:21:55 +01:00
Lennart Poettering c45e7e0cbf systemctl: rename unit_file_find_path()'s return paramete to indicate that it is one 2018-11-29 11:15:45 +01:00
Lennart Poettering ac9bbabbc5 systemctl: separate out paragraphs in long message with empty line 2018-11-28 08:43:47 +01:00
Lennart Poettering 18c93ee3ed systemctl: bullet lists FTW!
There's no reason to number these items, let's make this a bit nicer by
using proper bullets.
2018-11-28 08:43:47 +01:00
Lennart Poettering 46efc9780d systemctl: downgrade log message to LOG_NOTICE
This log message is not problematic at all, it is merely explanatory,
hence LOG_WARN is too high for this.
2018-11-28 08:43:47 +01:00
Lennart Poettering 1b9706b1cb systemctl: suffix unit file settings with = in our output
We do this in our man pages and log messages, and hence also in this
explanatory text.
2018-11-28 08:43:47 +01:00
Michael Biebl 1830ac51a4 Revert "systemctl: when removing enablement or mask symlinks, cover both /run and /etc"
Having systemctl disable/unmask remove all symlinks in /etc and /run is
unintuitive and breaks existing use cases.
systemctl should behave symmetrically.
A "systemctl --runtime unmask" should undo a "systemctl --runtime mask"
action.
Say you have a service, which was masked by the admin in /etc.
If you temporarily want to mask the execution of the service (say in a
script), you'd create a runtime mask via "systemctl --runtime mask".
It is is now no longer possible to undo this temporary mask without
nuking the admin changes, unless you start rm'ing files manually.

While it is useful to be able to remove all enablement/mask symlinks in
one go, this should be done via a separate command line switch, like
"systemctl --all unmask".

This reverts commit 4910b35078.

Fixes: #9393
2018-11-27 15:15:52 +01:00
Zbigniew Jędrzejewski-Szmek baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Zbigniew Jędrzejewski-Szmek d1405af399 systemctl: define main through macro and call ask_password_agent_close() from the macro
This doesn't save us anything, but I like consistency.
2018-11-21 09:14:00 +01:00
Zbigniew Jędrzejewski-Szmek 294bf0c34a Split out pretty-print.c and move pager.c and main-func.h to shared/
This is high-level functionality, and fits better in shared/ (which is for
our executables), than in basic/ (which is also for libraries).
2018-11-20 18:40:02 +01:00
Zbigniew Jędrzejewski-Szmek cd5a29ce98
Merge pull request #10742 from poettering/c-utf8
default to C.UTF-8 locale, and many improvements to env var file parsing/kernel cmdline parsing
2018-11-15 12:47:17 +01:00
Lennart Poettering 01771226c2 tree-wide: replace all remaining uses of parse_env_file() for parsing /proc/cmdline
Let's always go through the proc-cmdline.c APIs.
2018-11-14 17:01:54 +01:00
Zbigniew Jędrzejewski-Szmek 0221d68a13 basic/pager: convert the pager options to a flags argument
Pretty much everything uses just the first argument, and this doesn't make this
common pattern more complicated, but makes it simpler to pass multiple options.
2018-11-14 16:25:11 +01:00
Lennart Poettering bea1a01310 strv: wrap strv_new() in a macro so that NULL sentinel is implicit 2018-10-31 18:00:52 +01:00
Yu Watanabe 14cb109d45 tree-wide: replace 'unsigned int' with 'unsigned' 2018-10-19 22:19:12 +02:00
Lennart Poettering a42984dbc7
Merge pull request #10428 from keszybz/failure-actions
Implement manager status changes using SuccessAction=
2018-10-17 21:29:10 +02:00
Zbigniew Jędrzejewski-Szmek f03ec2b180 systemctl: fix typo 2018-10-16 23:03:52 +02:00
Lennart Poettering 1abaf4887d tree-wide: uniformly bump RLIMIT_NOFILE in all our tools that access the journal
This makes use of rlimit_nofile_bump() in all tools that access the
journal. In some cases this replaces older code to achieve this, and
others we add it in where it was missing.
2018-10-16 16:33:55 +02:00
Lennart Poettering 0e8d9c0c4d systemctl: clean up start_unit_one() error handling
Let's split exit code handling in two: "r" is only used for errno-style
errors, and "ret" is used for exit() codes. Then, let's use EXIT_SUCCESS
for checking whether the latter is already used.

This way it should always be clear what kind of error we are processing,
and when we propaate one into the other.

Moreover this allows us to drop "q" form all inner loops, avoiding
confusion when to use "q" and when "r" to store received errors.

Fixes: #9704
2018-10-13 14:38:46 +02:00
Lennart Poettering 8b7ec7bbfa systemctl: add missing OOM check 2018-10-13 14:34:56 +02:00
Zbigniew Jędrzejewski-Szmek 1b20d88987 Move logic to find default sd-boot entry from systemctl to shared
In preparation for use in other places. No functional change.
2018-10-08 16:06:26 +02:00
Yu Watanabe 93bab28895 tree-wide: use typesafe_qsort() 2018-09-19 08:02:52 +09:00
Lennart Poettering b0b3ba69c0
Merge pull request #10061 from xnox/fix-logindless-scheduled-shutdown
Fix logindless scheduled shutdown
2018-09-12 20:45:31 +02:00
Yu Watanabe eda193578e bus-util: make --property= optionally take value 2018-09-12 12:11:25 +09:00
Dimitri John Ledkov 940bec70bb systemctl: correctly proceed to immediate shutdown if scheduling fails
Actually check the return code from logind_schedule_shutdown() and proceed to
immediate shutdown if that fails. Negative return codes can be returned if
systemctl is compiled without logind support, or if logind otherwise failed
(either too old, disabled/masked, or it is incomplete
systemd-shim/systemd-service implementation).
2018-09-11 10:41:56 +01:00
Dimitri John Ledkov cf9cda441a Revert "systemctl: if no logind, don't try to schedule shutdown"
This reverts commit c68867da32.
2018-09-10 19:54:12 +01:00
Dimitri John Ledkov 7f56c3d46e Revert "systemctl: fix compilation w/o logind"
This reverts commit 807690fb7f.
2018-09-10 19:53:59 +01:00
Zbigniew Jędrzejewski-Szmek 807690fb7f systemctl: fix compilation w/o logind
Fixes #10006.
2018-09-04 09:34:16 +02:00
Samuel Morris c68867da32 systemctl: if no logind, don't try to schedule shutdown
If logind is not supported, don't try to schedule a shutdown,
immediately poweroff. This is the behavior indicated by the current
message given to the user, but the command is returning an error. I
believe this was broken on this commit:
7f96539d45
2018-08-29 17:51:53 +02:00
Tejun Heo 6ae4283cb1 core: add IODeviceLatencyTargetSec
This adds support for the following proposed latency based IO control
mechanism.

  https://lkml.org/lkml/2018/6/5/428
2018-08-22 16:46:18 +02:00
Lennart Poettering 37ec0fdd34 tree-wide: add clickable man page link to all --help texts
This is a bit like the info link in most of GNU's --help texts, but we
don't do info but man pages, and we make them properly clickable on
terminal supporting that, because awesome.

I think it's generally advisable to link up our (brief) --help texts and
our (more comprehensive) man pages a bit, so this should be an easy and
straight-forward way to do it.
2018-08-20 11:33:04 +02:00
Filipe Brandenburger adb6cd9be2 systemctl: add support for --wait to is-system-running
This makes it possible to wait until boot is finished without having to poll
for this command repeatedly, instead using the syntax:

  $ systemctl is-system-running --wait

Waiting is implemented by waiting for the StartupFinished signal to be posted
on the bus.

Register the matcher before checking for the property to avoid race conditions.

Tested by artificially delaying startup with a oneshot service and calling this
command, checked that it emitted `running` and exited with a 0 return code as
soon as the delay service completed startup.

Also tested that booting to degraded state unblocks the command.

Inserted a delay between getting the property and waiting for the signal and
confirmed this seems to work free of race conditions.

Updated the --help text (under --wait) and the man page to document the new
feature.
2018-08-07 09:33:25 +02:00
Zbigniew Jędrzejewski-Szmek 5b316330be
Merge pull request #9624 from poettering/service-state-flush
flush out ExecStatus structures when a new service cycle begins
2018-08-02 09:50:39 +02:00
Yu Watanabe aa8d423ef9 systemctl: set string table size for safety 2018-07-23 23:59:09 +09:00
Lennart Poettering 3e14d36a8a systemctl: show ExecStop= data after ExecStart= data
the service manager serializes ExecStop= execution data after
ExecStart=, like it makes sense and how it should be expected. However,
systemctl previously would reverse them when deserializing them locally,
and thus show ExecStop= results before ExecStart= results. And that's
confusing. Let's fix that.
2018-07-23 13:36:47 +02:00
Filipe Brandenburger 46f2579c2a systemctl: Only wait when there's something to wait for.
Tested:
- `systemctl --wait start i-do-not-exist.service` does not wait.
- `systemctl --wait start i-do-not-exist.service valid-unit.service` does.
2018-07-21 23:40:08 +09:00
Lennart Poettering 8b3169b9a1
Merge pull request #9600 from keszybz/systemctl-mask-check
Systemctl mask check
2018-07-18 21:03:02 +02:00
Lennart Poettering 8d568e8d3e
Merge pull request #9346 from keszybz/journald-exact2
Store a copy of the input message if any stripping or truncation occurs
2018-07-18 21:00:43 +02:00
Zbigniew Jędrzejewski-Szmek 86f004fbb5 systemctl: allow 'edit' to work on templates again
This got broken in 9d9dd746d4, because a template
is not a valid unit, so the check for being masked failed. Avoid this by
handling templates specially. Fixes #9554.

Also, this improves 'cat' with masked units:

(before) $ systemctl cat foofoofoo@.service
Failed to derive unit name prefix from unit name: Invalid argument
Failed to derive unit name prefix from unit name: Invalid argument
Failed to derive unit name prefix from unit name: Invalid argument
Failed to derive unit name prefix from unit name: Invalid argument
Failed to derive unit name prefix from unit name: Invalid argument
Failed to derive unit name prefix from unit name: Invalid argument
Failed to derive unit name prefix from unit name: Invalid argument
Failed to derive unit name prefix from unit name: Invalid argument
Failed to derive unit name prefix from unit name: Invalid argument
Failed to derive unit name prefix from unit name: Invalid argument

(after) $ build/systemctl cat foofoofoo@.service

In check_triggering_units(), the call to unit_is_masked() is replaced with an
open-coded check. This is a bit unfortunate, but unit_is_masked() now requires
LookupPaths to be initialized, which we don't have or need in this case, so it
seems easiest to just accept this tiny code duplication.
2018-07-16 15:52:40 +02:00
Lennart Poettering db9eee7e45
Merge pull request #9530 from keszybz/sd-bus-doc
More documentation for sd-bus
2018-07-16 15:01:12 +02:00
Zbigniew Jędrzejewski-Szmek d35f51ea84 tree-wide: use "polkit" to refer to PolicyKit/polkit
Back in 2012 the project was renamed, see the release notes for v 0.105
[https://cgit.freedesktop.org/polkit/tree/NEWS#n754]. Let's update our
documentation and comments to do the same. Referring to PolicyKit is confusing
to users because at the time the polkit api changed too, and we support the new
version. I updated NEWS too, since all the references to PolicyKit there were
added after the rename.

"PolicyKit" is unchanged in various URLs and method call names.
2018-07-16 12:44:24 +02:00
Lennart Poettering 99352de644
Merge pull request #9462 from yuwata/strv_split
make strv_split() accept empty string and use it in pager_open()
2018-07-13 20:32:37 +02:00
Tejun Heo 4842263577 core: add MemoryMin
The kernel added support for a new cgroup memory controller knob memory.min in
bf8d5d52ffe8 ("memcg: introduce memory.min") which was merged during v4.18
merge window.

Add MemoryMin to support memory.min.
2018-07-12 08:21:43 +02:00
Yu Watanabe 70d6e5bd99 systemctl: make variable which stores environment variable constant 2018-07-07 01:39:14 +09:00
Zbigniew Jędrzejewski-Szmek 855a86a349 systemctl: fix assert for failed mktime conversion
mktime returns -1 on error, so checking for != 0 is not useful.
2018-07-04 23:54:43 +02:00
Lennart Poettering bfeec178db systemctl: if we can't detect the system-is-running state, assume it's not running 2018-06-25 17:10:27 +02:00
Lennart Poettering e686a616e8 systemctl: log errors to LOG_DEBUG rather than eating them up entirely 2018-06-25 17:10:27 +02:00
Lennart Poettering 9897b09ba7 systemctl: add 'static' to constant state array 2018-06-25 17:10:27 +02:00
Franck Bui 25c59b5d85 systemctl: mask always reports the same unit names when different unknown units are passed
Before this patch:

  # systemctl --runtime mask abuild.mount does-not-exist.mount does-also-not-exist.mount
  Unit abuild.mount does not exist, proceeding anyway.
  Unit abuild.mount does not exist, proceeding anyway.
  Unit abuild.mount does not exist, proceeding anyway.
  Created symlink /run/systemd/system/abuild.mount → /dev/null.
  Created symlink /run/systemd/system/does-not-exist.mount → /dev/null.
  Created symlink /run/systemd/system/does-also-not-exist.mount → /dev/null.

After this patch:

  # systemctl --runtime mask abuild.mount does-not-exist.mount does-also-not-exist.mount
  Unit abuild.mount does not exist, proceeding anyway.
  Unit does-not-exist.mount does not exist, proceeding anyway.
  Unit does-also-not-exist.mount does not exist, proceeding anyway.
  Created symlink /run/systemd/system/abuild.mount → /dev/null.
  Created symlink /run/systemd/system/does-not-exist.mount → /dev/null.
  Created symlink /run/systemd/system/does-also-not-exist.mount → /dev/null.
2018-06-20 21:53:23 +02:00
Yu Watanabe 31d99bd172 tree-wide: do not assign values if not used 2018-06-19 08:44:55 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Zbigniew Jędrzejewski-Szmek bbac65bcc2
Merge pull request #9157 from poettering/unit-config-load-error
introduce a new "bad-setting" unit load state in order to improve "systemctl status" output when bad settings are used
2018-06-11 14:37:10 +02:00
xginn8 a98f7575ae Add counter for socket unit refuse events (#9217)
core: add counter for socket unit rejection events
2018-06-11 12:56:26 +02:00
Lennart Poettering 9a0abfa8aa systemctl: load_error is a string, don't compare it with 0
Using isempty() is nicer anyway.
2018-06-11 12:53:12 +02:00
Lennart Poettering c4555ad8f6 core: introduce a new load state "bad-setting"
Since bb28e68477 parsing failures of
certain unit file settings will result in load failures of units. This
introduces a new load state "bad-setting" that is entered in precisely
this case.

With this addition error messages on bad settings should be a lot more
explicit, as we don't have to show some generic "errno" error in that
case, but can explicitly say that a bad setting is at fault.

Internally this unit load state is entered as soon as any configuration
loader call returns ENOEXEC. Hence: config parser calls should return
ENOEXEC now for such essential unit file settings. Turns out, they
generally already do.

Fixes: #9107
2018-06-11 12:53:12 +02:00
Lennart Poettering 950d6889c3 systemctl: when GetProcesses() doesn't work, say for which unit 2018-06-06 19:46:23 +02:00
Lennart Poettering 0be9b12be2
Merge pull request #9147 from keszybz/runtime-enablement
Runtime enablement
2018-06-04 11:58:21 +02:00
Zbigniew Jędrzejewski-Szmek 4910b35078 systemctl: when removing enablement or mask symlinks, cover both /run and /etc
'systemctl disable --runtime' would disable a unit, but only if it was enabled
with '--runtime', and silently do nothing if the unit was enabled persistently.
And similarly 'systemctl disable' would do nothing if the unit was enabled in
/run. This just doesn't seem useful.

This pathch changes enable/disable and mask/unmask to be asymmetrical. enable
and mask create symlinks in /etc or /run, depending on whether --runtime was
specified. disable and unmask remove symlinks from both locations. --runtime
cannot be specified for the disable and unmask verbs.

The advantage is that 'disable' now means that the unit is disabled, period.
And similarly for 'unmask', all masks are removed.

Similarly for preset and preset-all, they now cannot be called with --runtime,
and are asymmetrical: when they enable a unit, symlinks are created in /etc.
When they disable a unit, all symlinks are nuked.

$ systemctl --root=/ enable bluetooth
Created symlink /etc/systemd/system/dbus-org.bluez.service → /usr/lib/systemd/system/bluetooth.service.
Created symlink /etc/systemd/system/bluetooth.target.wants/bluetooth.service → /usr/lib/systemd/system/bluetooth.service.
$ systemctl --root=/ --runtime enable bluetooth
Created symlink /run/systemd/system/dbus-org.bluez.service → /usr/lib/systemd/system/bluetooth.service.
Created symlink /run/systemd/system/bluetooth.target.wants/bluetooth.service → /usr/lib/systemd/system/bluetooth.service.
$ systemctl --root=/ disable bluetooth
Removed /run/systemd/system/bluetooth.target.wants/bluetooth.service.
Removed /run/systemd/system/dbus-org.bluez.service.
Removed /etc/systemd/system/bluetooth.target.wants/bluetooth.service.
Removed /etc/systemd/system/dbus-org.bluez.service.
$ systemctl --root=/ disable --runtime bluetooth
--runtime cannot be used with disable

$ systemctl --root=/ mask --runtime bluetooth
Created symlink /run/systemd/system/bluetooth.service → /dev/null.
$ systemctl --root=/ mask bluetooth
Created symlink /etc/systemd/system/bluetooth.service → /dev/null.
$ systemctl --root=/ unmask bluetooth
Removed /run/systemd/system/bluetooth.service.
Removed /etc/systemd/system/bluetooth.service.
$ systemctl --root=/ unmask --runtime bluetooth
--runtime cannot be used with unmask

$ systemctl --root=/ --runtime enable bluetooth
Created symlink /run/systemd/system/dbus-org.bluez.service → /usr/lib/systemd/system/bluetooth.service.
Created symlink /run/systemd/system/bluetooth.target.wants/bluetooth.service → /usr/lib/systemd/system/bluetooth.service.
$ systemctl --root=/ enable bluetooth
Created symlink /etc/systemd/system/dbus-org.bluez.service → /usr/lib/systemd/system/bluetooth.service.
Created symlink /etc/systemd/system/bluetooth.target.wants/bluetooth.service → /usr/lib/systemd/system/bluetooth.service.
$ systemctl --root=/ preset bluetooth
Removed /run/systemd/system/bluetooth.target.wants/bluetooth.service.
Removed /run/systemd/system/dbus-org.bluez.service.
Removed /etc/systemd/system/bluetooth.target.wants/bluetooth.service.
Removed /etc/systemd/system/dbus-org.bluez.service.
$ systemctl --root=/ preset --runtime bluetooth
--runtime cannot be used with preset

$ systemctl preset-all --runtime
--runtime cannot be used with preset-all
2018-06-01 15:10:33 +02:00
Zbigniew Jędrzejewski-Szmek e2e6ca54c3 systemctl: remove newlines
This file is long enough already, we don't need extra vertical whitespace.
2018-05-31 20:42:07 +02:00
Zbigniew Jędrzejewski-Szmek 4d9685be5f Use const char* for timestamp strings which we don't plan to modify
Makes the intent a bit clearer.
2018-05-31 14:30:23 +02:00
Lennart Poettering 1a5a177eaf fileio: accept FILE* in addition to path in parse_env_file()
Most our other parsing functions do this, let's do this here too,
internally we accept that anyway. Also, the closely related
load_env_file() and load_env_file_pairs() also do this, so let's be
systematic.
2018-05-24 17:01:57 +02:00
Lennart Poettering 5c828e66b5 tree-wide: port various bits of the tree over to the new DUMP_STRING_TABLE() macro 2018-05-22 13:14:18 +02:00
Lennart Poettering 81321f51cf
Merge pull request #8824 from keszybz/analyze-show-config
systemd-analyze show-config
2018-05-10 11:14:23 -07:00
Yu Watanabe fb507898a3 bus-util: print a friendly message when PID1 is not systemd
Follow-up for 861f16d267.

Fixes #8913.
2018-05-09 17:07:37 +09:00
Yu Watanabe 29a3db75fd util: rename signal_from_string_try_harder() to signal_from_string()
Also this makes the new `signal_from_string()` function reject
e.g, `SIG3` or `SIG+5`.
2018-05-03 16:52:49 +09:00
Guillem Jover 2955e0d4dc systemctl: make sure legacy "reboot", "suspend" and friends are always asynchronous (#8848)
Currently, "reboot" behaves differently in setups with and without logind.
If logind is used (which is probably the more common case) the operation
is asynchronous, we should behave in the same way as "systemctl <verb>".
Let's clean this up, and always expose the same behaviour, regardless if
logind is used or not: let's always make it asynchronous.

See: #6479
Fixes: commit 130246d2e8
2018-04-30 18:21:27 +02:00
Lennart Poettering da6053d0a7 tree-wide: be more careful with the type of array sizes
Previously we were a bit sloppy with the index and size types of arrays,
we'd regularly use unsigned. While I don't think this ever resulted in
real issues I think we should be more careful there and follow a
stricter regime: unless there's a strong reason not to use size_t for
array sizes and indexes, size_t it should be. Any allocations we do
ultimately will use size_t anyway, and converting forth and back between
unsigned and size_t will always be a source of problems.

Note that on 32bit machines "unsigned" and "size_t" are equivalent, and
on 64bit machines our arrays shouldn't grow that large anyway, and if
they do we have a problem, however that kind of overly large allocation
we have protections for usually, but for overflows we do not have that
so much, hence let's add it.

So yeah, it's a story of the current code being already "good enough",
but I think some extra type hygiene is better.

This patch tries to be comprehensive, but it probably isn't and I missed
a few cases. But I guess we can cover that later as we notice it. Among
smaller fixes, this changes:

1. strv_length()' return type becomes size_t

2. the unit file changes array size becomes size_t

3. DNS answer and query array sizes become size_t

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
2018-04-27 14:29:06 +02:00
Zbigniew Jędrzejewski-Szmek 854a42fb2e analyze: add 'cat-config' verb
This is used as 'systemd-analyze show-config systemd/logind.conf', which
will dump
   /etc/systemd/system/user@.service
   /etc/systemd/system/user@.service.d/*.conf
   /run/systemd/system/user@.service.d/*.conf
   /usr/local/lib/systemd/system/user@.service.d/*.conf
   /usr/lib/systemd/system/user@.service.d/*.conf

The idea is to make it easy to dump the configuration using the same locations
and order that systemd programs use themselves (including masking, in the right
order, etc.). This is the generic variant that works with any configuration
scheme that follows the same general rules:

$ systemd-analyze cat-config systemd/system.conf
$ systemd-analyze cat-config systemd/user.conf
$ systemd-analyze cat-config systemd/logind.conf
$ systemd-analyze cat-config systemd/sleep.conf
$ systemd-analyze cat-config systemd/journald.conf
$ systemd-analyze cat-config systemd/journal-remote.conf
$ systemd-analyze cat-config systemd/journal-upload.conf
$ systemd-analyze cat-config systemd/coredump.conf
$ systemd-analyze cat-config systemd/resolved.conf
$ systemd-analyze cat-config systemd/timesyncd.conf
$ systemd-analyze cat-config udev/udev.conf
2018-04-27 10:06:24 +02:00
Zbigniew Jędrzejewski-Szmek 81f5e51368 Move function to cat file & dropins into basic/
This fixes a buglet where the second and later drop-in would not be seperated
properly by a newline.
2018-04-26 13:52:46 +02:00
Lennart Poettering 8e766630f0 tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.

In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.

Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.

Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.

Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
Lennart Poettering c708025774 systemctl: format unit file and dropin paths as clickable links in status output 2018-04-19 18:04:26 +02:00
Lennart Poettering 78c7d20ebc systemctl: format documentation links in status output as clickable links 2018-04-19 18:04:26 +02:00
Lennart Poettering eb2c3192dc systemctl: fix indentation in output of "systemcl status" if there are multiple drop-in dirs
We were a few whitespace off. Let's fix that.
2018-04-13 11:34:48 +02:00
Lennart Poettering b667d50d34
Merge pull request #8700 from keszybz/hibernation
Various improvements related to hibernation
2018-04-11 10:26:27 +02:00
Zbigniew Jędrzejewski-Szmek bd062910c8 Move utility function to query unit state from systemctl to shared/ 2018-04-10 21:31:59 +02:00
Lennart Poettering 4d09e1c8ba
Merge pull request #8676 from keszybz/drop-license-boilerplate
Drop license boilerplate
2018-04-10 14:53:31 +02:00
Zbigniew Jędrzejewski-Szmek f39cbb6e69 systemctl: pass BUS_MAP_STRDUP when needed (#8682)
This fixes an assert in "systemctl list-dependencies".
Follow-up for a7e4861c74.
2018-04-08 15:12:18 +09:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Yu Watanabe 1cc6c93a95 tree-wide: use TAKE_PTR() and TAKE_FD() macros 2018-04-05 14:26:26 +09:00
Mike Gilbert 83c76e8c38 systemctl: try opening /run/initctl before /dev/initctl
This ensures compatability with old/new sysvinit.

http://git.savannah.nongnu.org/cgit/sysvinit.git/commit/?id=80dbcf3de3c1b83aeaa713a8fe5b8d35d8649af2
2018-03-30 16:52:14 -04:00
Mario Limonciello e68c79db91 Rename suspend-to-hibernate to suspend-then-hibernate
Per some discussion with Gnome folks, they would prefer this name
as it's more descriptive of what's happening.
2018-03-28 15:11:10 -05:00
Zbigniew Jędrzejewski-Szmek 9d9dd746d4 systemctl: refuse to edit masked units (#8602)
Note: in check_triggering_units 'path' will be allocated twice. This is a
conscious choice, this way the implementation is simpler and not worth
optimizing.

Fixes #8519.
2018-03-28 17:25:04 +02:00
Yu Watanabe a7e4861c74 bus-util: add flags for bus_map_all_properties() (#8546)
This adds flags BUS_MAP_STRDUP and BUS_MAP_BOOLEAN_AS_BOOL.
If BUS_MAP_STRDUP is set, then each "s" message is duplicated.
If BUS_MAP_BOOLEAN_AS_BOOL is set, then each "b" message is
written to a bool pointer.

Follow-up for #8488.
See https://github.com/systemd/systemd/pull/8488#discussion_r175816270.
2018-03-28 13:37:27 +02:00
Lennart Poettering ae2a15bc14 macro: introduce TAKE_PTR() macro
This macro will read a pointer of any type, return it, and set the
pointer to NULL. This is useful as an explicit concept of passing
ownership of a memory area between pointers.

This takes inspiration from Rust:

https://doc.rust-lang.org/std/option/enum.Option.html#method.take

and was suggested by Alan Jenkins (@sourcejedi).

It drops ~160 lines of code from our codebase, which makes me like it.
Also, I think it clarifies passing of ownership, and thus helps
readability a bit (at least for the initiated who know the new macro)
2018-03-22 20:21:42 +01:00
Zbigniew Jędrzejewski-Szmek 37cbc1d579 When mangling names, optionally emit a warning (#8400)
The warning is not emitted for absolute paths like /dev/sda or /home, which are
converted to .device and .mount unit names without any fuss.

Most of the time it's unlikely that users use invalid unit names on purpose,
so let's warn them. Warnings are silenced when --quiet is used.

$ build/systemctl show -p Id hello@foo-bar/baz
Invalid unit name "hello@foo-bar/baz" was escaped as "hello@foo-bar-baz" (maybe you should use systemd-escape?)
Id=hello@foo-bar-baz.service

$ build/systemd-run --user --slice foo-bar/baz --unit foo-bar/foo true
Invalid unit name "foo-bar/foo" was escaped as "foo-bar-foo" (maybe you should use systemd-escape?)
Invalid unit name "foo-bar/baz" was escaped as "foo-bar-baz" (maybe you should use systemd-escape?)
Running as unit: foo-bar-foo.service

Fixes #8302.
2018-03-21 15:26:47 +01:00
Yu Watanabe 07636114b1 bus-util: introduce bus_message_print_all_properties()
Then, use it where applicable.
2018-03-20 00:44:37 +09:00
Yu Watanabe 4679a8c301 systemctl: use bus_map_all_properties() in status command 2018-03-20 00:44:34 +09:00
Yu Watanabe 8559e61d64 systemctl: use string table for show() 2018-03-20 00:44:30 +09:00
Yu Watanabe f37f8a61c0 bus-util: make bus_map_all_properties() not copy string 2018-03-20 00:42:48 +09:00
Yu Watanabe 32b4727965 systemctl: use bus_map_all_properties() in list-dependencies command 2018-03-19 22:53:39 +09:00
Yu Watanabe ee5324aa04 tree-wide: voidify pager_open()
Even if pager_open() fails, in general, we should continue the operations.
All erroneous cases in pager_open() show log message in the function.
So, it is not necessary to check the returned value.
2018-03-19 21:04:02 +09:00
Yu Watanabe cc6861006e
Merge pull request #8399 from keszybz/systemctl-kexec
Systemctl kexec buglet fixes
2018-03-19 18:35:41 +09:00
Zbigniew Jędrzejewski-Szmek dbc9830cde systemctl: honour --dry-run also on logind calls
Fixes #7670.
2018-03-09 10:43:54 +01:00
Zbigniew Jędrzejewski-Szmek d23b5ce2b6 systemctl: if kexec fails with --force, continue to reboot normally
When we are in late shutdown, and for whatever reason kexec fails, we should
proceed with a normal reboot. Network is down and sessions have been terminated
when we attempt to do the kexec, so rebooting normally is a better solution.

Logs from the case where the kexec kernel is not usable:
Mar 08 11:23:10 fuefi systemd[1]: Reached target Final Step.
Mar 08 11:23:10 fuefi systemd[1]: Starting Reboot via kexec...
Mar 08 11:23:10 fuefi systemctl[1480]: Cannot find the ESP partition mount point.
Mar 08 11:23:10 fuefi systemctl[1480]: Failed to load kexec kernel, continuing without.
Mar 08 11:23:10 fuefi systemd[1]: Shutting down.
... and then we proceed to do a normal reboot

Related to #7730.
2018-03-09 10:43:54 +01:00
Zbigniew Jędrzejewski-Szmek c0d7321498 systemctl: if kexec is missing, do not try to kexec 2018-03-09 10:43:54 +01:00
Zbigniew Jędrzejewski-Szmek df685d5784 systemctl: propagate the error from kexec 2018-03-09 10:43:54 +01:00
Zbigniew Jędrzejewski-Szmek cd086a014b systemctl: raise level of log line about kernel loading
It's pretty important after all. Also include the actual kexecuted command in
the log message, that's useful to debug if something goes wrong.
2018-03-09 10:43:54 +01:00
Mario Limonciello c58493c00a Introduce suspend-to-hibernate (#8274)
Suspend to Hibernate is a new sleep method that invokes suspend
for a predefined period of time before automatically waking up
and hibernating the system.

It's similar to HybridSleep however there isn't a performance
impact on every suspend cycle.

It's intended to use with systems that may have a higher power
drain in their supported suspend states to prevent battery and
data loss over an extended suspend cycle.

Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
2018-03-08 14:17:33 +01:00
Lennart Poettering c54819ca80 systemctl: document telinit/init matching a bit (#8339)
See: #8305
2018-03-02 12:51:57 +01:00
Douglas Christman 68da321f66 systemctl: remove redundant option parsing code
"-f" used to be overloaded to mean both "--force" and "--follow";
aae9a96d removed "--follow", leaving behind some duplicate code.
2018-03-01 21:50:38 +08:00
Lennart Poettering 15eac526e0
Merge pull request #8258 from keszybz/log-issues
Fix some logging issues
2018-02-23 19:54:32 +01:00
Zbigniew Jędrzejewski-Szmek 5b464a18e7 systemctl: do not hint logs when a unit cannot be reloaded
The logs don't contain any additional information.
2018-02-23 11:13:42 +01:00
Zbigniew Jędrzejewski-Szmek 135775c156 systemctl: use VARIABLE as the placeholder for a variable name
The man page was already using VARIABLE=VALUE, so no change there.
2018-02-22 14:53:56 +01:00
Zbigniew Jędrzejewski-Szmek fbf3283bdd systemctl,man: use PROPERTY as the placeholder for a property name 2018-02-22 14:53:56 +01:00
Zbigniew Jędrzejewski-Szmek da5e955fbd systemctl,man: use UNIT as the placeholder for a unit name
NAME is kind of meaningless, because everything has a name. "Unit"
makes it more obvious that a name of a unit is necessary. I was always
momentarily baffled by "set-property NAME ASSIGNMENT...", where there
are two objects (the unit and the property), and it's not clear which of
the two "NAME" is supposed to signify.
2018-02-22 14:53:56 +01:00
Lennart Poettering c01dcddf80 reboot-util: unify reboot with parameter in a single implementation
So far, we had two implementations of reboot-with-parameter doing pretty
much the same. Let's unify that in a generic implementation used by
both.

This is particulary nice as it unifies all /run/systemd/reboot-param
handling in a single .c file.
2018-02-22 10:46:26 +01:00
Lennart Poettering e3631d1c80 basic: split out update_reboot_parameter_and_warn() into its own .c/.h files
This is primarily preparation for a follow-up commit that adds a common
implementation of the other side of the reboot parameter file, i.e. the
code that reads the file and issues reboot() for it.
2018-02-22 10:46:12 +01:00
Lennart Poettering c52a937b46 basic: add a common syscall wrapper around reboot()
This mimics the raw_clone() call we have in place already and
establishes a new syscall wrapper raw_reboot() that wraps the kernel's
reboot() system call in a bit more low-level fashion that glibc's
reboot() wrapper. The main difference is that the extra "arg" argument
is supported.

Ultimately this just replaces the syscall wrapper implementation we
currently have at three places in our codebase by a single one.

With this change this means that all our syscall() invocations are
neatly separated out in static inline system call wrappers in our header
functions.
2018-02-22 10:42:06 +01:00
Yu Watanabe 009192bb03 systemctl: show: use EnvironmentFiles= instead of EnvironmentFile=
EnvironmentFile= is used in the unit file, but in the dbus,
the related field name is EnvironmentFiles=.
As the other variables, let's use the field name instead of the name
used in the unit file setting.
2018-02-05 15:28:02 +09:00
Yu Watanabe c7366cf17f systemctl: update 'show' format for path units
Before this.
```
$ systemctl show cups.path | grep ^Path
PathExistsGlob=/var/spool/cups/d*
$ systemctl show --property PathExistsGlob cups.path
$ systemctl show --property Paths cups.path
PathExistsGlob=/var/spool/cups/d*
```

After this.
```
$ systemctl show cups.path | grep ^Path
Paths=/var/spool/cups/d* (PathExistsGlob)
$ systemctl show --property Paths cups.path
Paths=/var/spool/cups/d* (PathExistsGlob)
```
2018-02-05 15:27:53 +09:00
Yu Watanabe eabc13c781 systemctl: update 'show' format for socket units
Before this.
```
$ systemctl show systemd-journald.socket | grep Listen
ListenStream=/run/systemd/journal/stdout
ListenDatagram=/run/systemd/journal/socket
$ systemctl show --property ListenStream systemd-journald.socket
$ systemctl show --property ListenDatagram systemd-journald.socket
$ systemctl show --property Listen systemd-journald.socket
ListenStream=/run/systemd/journal/stdout
ListenDatagram=/run/systemd/journal/socket
```

After this.
```
$ systemctl show systemd-journald.socket | grep Listen
Listen=/run/systemd/journal/stdout (Stream)
Listen=/run/systemd/journal/socket (Datagram)
$ systemctl show --property Listen systemd-journald.socket
ListenStream=/run/systemd/journal/stdout
ListenDatagram=/run/systemd/journal/socket
```

Fixes #8064.
2018-02-05 15:27:47 +09:00
Yu Watanabe fa6dee52ca systemctl: show Timers{Monotonic,Calendar}= 2018-02-05 15:27:42 +09:00
Lennart Poettering 3d083b2245 systemctl: load unit if needed in "systemctl is-active"
Previously, we'd explicitly use "GetUnit()" on the server side to
convert a unit name into a bus path, as that function will return an
error if the unit is not currently loaded. If we'd convert the path on
the client side, and access the unit this way directly the unit would be
loaded automatically in the background.

The old logic was done in order to minimize the effect of "is-active" on
the system, i.e. that a monoitoring command does not itself alter the
state of the system.

however, this is problematic as this can lead to confusing results if
the queried unit name is an alias that currently is not loaded: we'd
claim the unit wasn't active even though this isn't strictly true: the
unit the name is an alias for might be.

Hence, let's simplify the code, and accept that we might end up loading
a unit briefly here, and let's make "systemctl is-active" skip the
GetUnit() thing and calculate the unit path right away.

Fixes: #7875
2018-01-25 15:19:13 +01:00
Lennart Poettering db4a47e9fe coccinelle: O_NDELAY → O_NONBLOCK
Apparently O_NONBLOCK is the modern name used in most documentation and
for most cases in our sources. Let's hence replace the old alias
O_NDELAY and stick to O_NONBLOCK everywhere.
2018-01-24 11:09:29 +01:00
Yu Watanabe a219c2698e systemctl: remove unused variable
Follow-up for 98f6093687.
2018-01-24 12:54:15 +09:00
Reverend Homer 98f6093687 systemctl: replace manual GetAll call with bus_map_all_properties() in unit_exists() 2018-01-22 20:33:15 +01:00
Yu Watanabe 3e7e587d32 systemctl: comment that the verb 'check' is deprecated 2018-01-15 23:44:31 +09:00
Lennart Poettering 31b2cd5d23 tree-wide: make the Subscribe() method calls asynchronous too 2018-01-05 13:58:32 +01:00
Lennart Poettering 75152a4d6a tree-wide: install matches asynchronously
Let's remove a number of synchronization points from our service
startups: let's drop synchronous match installation, and let's opt for
asynchronous instead.

Also, let's use sd_bus_match_signal() instead of sd_bus_add_match()
where we can.
2018-01-05 13:58:32 +01:00
Lennart Poettering b4a343112e tree-wide: use EXIT_SUCCESS when comparing child process exit statuses
When we check the exit status of a subprocess, let's compare it with
EXIT_SUCCESS rather than 0 when looking for success.

This clarifies in code what kind of variable we are looking at and what
we are doing.
2018-01-04 13:27:27 +01:00
Lennart Poettering d2e0ac3d1e tree-wide: unify the process name we pass to wait_for_terminate_and_check() with the one we pass to safe_fork() 2018-01-04 13:27:27 +01:00
Lennart Poettering 2e87a1fde9 tree-wide: make use of wait_for_terminate_and_check() at various places
Using wait_for_terminate_and_check() instead of wait_for_terminate()
let's us simplify, shorten and unify the return value checking and
logging of waitid().  Hence, let's use it all over the place.
2018-01-04 13:27:27 +01:00
Lennart Poettering 1f5d1e0247 process-spec: add another flag FORK_WAIT to safe_fork()
This new flag will cause safe_fork() to wait for the forked off child
before returning. This allows us to unify a number of cases where we
immediately wait on the forked off child, witout running any code in the
parent after the fork, and without direct interest in the precise exit
status of the process, except recgonizing EXIT_SUCCESS vs everything
else.
2018-01-04 13:27:27 +01:00
Lennart Poettering 7d4904fe7a process-util: rework wait_for_terminate_and_warn() to take a flags parameter
This renames wait_for_terminate_and_warn() to
wait_for_terminate_and_check(), and adds a flags parameter, that
controls how much to log: there's one flag that means we log about
abnormal stuff, and another one that controls whether we log about
non-zero exit codes. Finally, there's a shortcut flag value for logging
in both cases, as that's what we usually use.

All callers are accordingly updated. At three occasions duplicate logging
is removed, i.e. where the old function was called but logged in the
caller, too.
2018-01-04 13:27:27 +01:00
Lennart Poettering b6e1fff13d process-util: add another fork_safe() flag for enabling LOG_ERR/LOG_WARN logging 2018-01-04 13:27:26 +01:00
Lennart Poettering 4c253ed1ca tree-wide: introduce new safe_fork() helper and port everything over
This adds a new safe_fork() wrapper around fork() and makes use of it
everywhere. The new wrapper does a couple of things we previously did
manually and separately in a safer, more correct and automatic way:

1. Optionally resets signal handlers/mask in the child

2. Sets a name on all processes we fork off right after forking off (and
   the patch assigns useful names for all processes we fork off now,
   following a systematic naming scheme: always enclosed in () – in order
   to indicate that these are not proper, exec()ed processes, but only
   forked off children, and if the process is long-running with only our
   own code, without execve()'ing something else, it gets am "sd-" prefix.)

3. Optionally closes all file descriptors in the child

4. Optionally sets a PR_SET_DEATHSIG to SIGTERM in the child, in a safe
   way so that the parent dying before this happens being handled
   safely.

5. Optionally reopens the logs

6. Optionally connects stdin/stdout/stderr to /dev/null

7. Debug logs about the forked off processes.
2017-12-25 11:48:21 +01:00
Lennart Poettering 15ce164770 systemctl: don't show vendor preset state for generated/transient units (#7711)
Showing the preset state for those suggests they could actually be
enabled/disabled, but that concept doesn't exist for generated/transient
units, hence hide this information.

This came up here:

https://lists.freedesktop.org/archives/systemd-devel/2017-December/040022.html
2017-12-24 08:47:24 +09:00
Yu Watanabe 89ada3ba08 bus-unit-util: add socket unit related options
Also, split bus_append_unit_property_assignment().
2017-12-23 18:48:16 +09:00
Lennart Poettering b794712a1c
Merge pull request #7631 from cgwalters/systemctl-offline
systemctl,verbs: Introduce SYSTEMCTL_OFFLINE environment variable
2017-12-15 10:29:21 +01:00
Colin Walters c56d1e2c1b verbs: Rename VERB_OFFLINE to VERB_ONLINE_ONLY, expand MUSTBEROOT
Followup to previous commit. Suggested by @poettering.
Reindented the `verbs[]` tables to match the apparent previous
whitespace rules (indent to one flag, allow multiple flags to overflow?).
2017-12-14 16:12:14 -05:00
Colin Walters f38951a628 systemctl,verbs: Introduce SYSTEMD_OFFLINE environment variable
A lot of code references the `running_in_chroot()` function; while
I didn't dig I'm pretty certain this arose to deal with situations
like RPM package builds in `mock` - there we don't want the `%post`s
to `systemctl start` for example.

And actually this exact same use case arises for
[rpm-ostree](https://github.com/projectatomic/rpm-ostree/)
where we implement offline upgrades by default; the `%post`s are
always run in a new chroot using [bwrap](https://github.com/projectatomic/bubblewrap).

And here's the problem: bwrap creates proper mount roots, so it
passes `running_in_chroot()`, and then if a script tries to do
`systemctl start` we get:
`System has not been booted with systemd as init system (PID 1)`
but that's an *error*, unlike the `running_in_chroot()` case where we ignore.

Further complicating things is there are real world RPM packages
like `glusterfs` which end up invoking `systemctl start`.

A while ago, the `SYSTEMD_IGNORE_CHROOT` environment variable was
added for the inverse case of running in a chroot, but still wanting
to use systemd as PID 1 (presumably some broken initramfs setups?).

Let's introduce a `SYSTEMD_OFFLINE` environment variable for cases like
mock/rpm-ostree so we can force on the "ignore everything except preset" logic.
This way we'll still not start services even if mock switches to use nspawn or
bwrap or something else that isn't a chroot.

We also cleanly supercede the `SYSTEMD_IGNORE_CHROOT=1` which is now spelled
`SYSTEMD_OFFLINE=0`.  (Suggested by @poettering)

Also I made things slightly nicer here and we now print the ignored operation.
2017-12-14 16:00:16 -05:00
Lennart Poettering fbd0b64f44
tree-wide: make use of new STRLEN() macro everywhere (#7639)
Let's employ coccinelle to do this for us.

Follow-up for #7625.
2017-12-14 19:02:29 +01:00
Lennart Poettering 0c63eb7138 verbs: add a new VERB_MUSTBEROOT flag
Given that we regularly have verbs that require privileges, let's just
make this a flag of the verb.
2017-12-11 23:19:46 +01:00
Lennart Poettering fba868fa71 tree-wide: unify logging of "Must be root" message
Let's unify this in one call, generalizing must_be_root() from
bootctl.c.
2017-12-11 23:19:45 +01:00
Lennart Poettering 5caa3167ff efi: rework find_esp() error propagation/logging a bit
This renames find_esp() to find_esp_and_warn() and tries to normalize its
behaviour:

1. Change the error that is returned when we can't find the ESP to
   ENOKEY (from ENOENT). This way the error code can only mean one
   thing: that our search loop didn't find a good candidate.
2. Really log about all errors, except for ENOKEY and EACCES, and
   document the letter cases.
3. Normalize parameters to the call: separate out the path parameter in
   two: an input path and an output path. That way the memory management
   is clear: we will access the input parameter only for reading, and
   only write out the output parameter, using malloc() memory.
   Before the calling convention were quire surprising for internal API
   code, as the path parameter had to be malloc() memory and might and
   might not have changed.
4. Rename bootctl's find_esp_warn() to acquire_esp(), and make it a
   simple wrapper around find_esp_warn(), that basically just adds the
   friendly logging for the ENOKEY case. This rework removes double
   logging in a number of error cases, as we no longer log here in
   anything but ENOKEY, and leave that entirely to find_esp_warn().
5. find_esp_and_warn() now takes a bool flag parameter
   "unprivileged_mode", which disables logging in the EACCES case, and
   skips privileged validation of the path. This makes the function less
   magic, and doesn't hide this internal silencing automatism from the
   caller anymore.

With all that in place "bootctl list" and "bootctl status" work properly
(or as good as they can) when I invoke the tools whithout privileges on
my system where /boot is not world-readable
2017-12-11 23:18:56 +01:00
Vito Caputo 508f63b411 *: fix some inconsistent control statement style 2017-12-01 16:49:52 -08:00
Lennart Poettering a081b9cea0 systemctl: don't use get_process_comm() on non-local PIDs (#7518)
Let's not use local process data for remote processes, that can only
show nonsense.

Maybe one day we should add a bus API to query the comm field of a
process remotely, but for now, let's not bother, the information is
redundant anyway, as the cgroup data shows it too (and the cgroup tree
is show as part of status as well, and is requested from remote through
dbus, without local kernel calls).

Fixes: #7516
2017-12-01 11:21:58 +01:00
Lennart Poettering e9f4aabd80 systemctl: reword "needs-reload" message a bit
This message is displayed either when the unit file itself is newer than
what is loaded, but also when any of the drop-ins is newer. Say so in
the message, in order not to confuse the user unnecessarily.
2017-11-29 12:34:12 +01:00
Zbigniew Jędrzejewski-Szmek 224b0e7ad0 Add set/hashmap helpers for non-trivial freeing and use where straighforward
A macro is needed because otherwise we couldn't ensure type safety.
Some simple tests are included.
No functional change intended.
2017-11-28 21:30:30 +01:00
Lennart Poettering b068c6f587 systemctl: ignore shutdown's "-t" argument (#7459)
We should not only ignore "-t" itself, but also whatever is passed to
it.

This pretty much reverts the core of
a4420f7b8e, and adds back in the status
quo ante. What a difference a ':' can make.

This also adds a quick comment for this, so that we don't make this
mistake again.

Fixes: #7413
2017-11-24 17:01:32 +01:00
Lennart Poettering 4ff183d419
Merge pull request #7154 from keszybz/bootspec
List bootspec entries in bootctl and use the default for kexec
2017-11-20 13:06:33 +01:00
Lennart Poettering 021723c63e systemctl: elapsation → elapse 2017-11-20 10:57:41 +01:00
Lennart Poettering 0133d5553a
Merge pull request #7198 from poettering/stdin-stdout
Add StandardInput=data, StandardInput=file:... and more
2017-11-19 19:49:11 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Zbigniew Jędrzejewski-Szmek 4bb2e9d466 systemctl: make sure the kernel is loaded before kexec'ing
We just load the same kernel that would be loaded by default by sd-boot, with
the same options. Changing the kernel or initramfs or options is left for
later.

Now we will refuse to continue if loading fails. This makes 'systemctl kexec'
more predictable: it will not fall back to normal reboot if the kernel is
not loaded.
2017-11-19 12:33:35 +01:00
Lennart Poettering 08f3be7a38 core: add two new unit file settings: StandardInputData= + StandardInputText=
Both permit configuring data to pass through STDIN to an invoked
process. StandardInputText= accepts a line of text (possibly with
embedded C-style escapes as well as unit specifiers), which is appended
to the buffer to pass as stdin, followed by a single newline.
StandardInputData= is similar, but accepts arbitrary base64 encoded
data, and will not resolve specifiers or C-style escapes, nor append
newlines.

This may be used to pass input/configuration data to services, directly
in-line from unit files, either in a cooked or in a more raw format.
2017-11-17 11:13:44 +01:00
Alan Jenkins 28abce5d25 systemctl: other wayland sessions should inhibit shutdown, like x11 sessions do (#7353)
Update systemctl code to match the manpage for sd_session_get_type().

"wayland" sessions should be treated the same as "x11".  "mir" too, fwiw.
2017-11-16 11:02:34 +01:00
Lennart Poettering 861f16d267 systemctl: print a friendly message when systemctl is invoked, but PID 1 is not systemd (#7318)
We only show this message when we can't talk to systemd, so that client
side install can work.

Fixes: https://bugzilla.freedesktop.org/show_bug.cgi?id=69962
2017-11-13 22:03:32 +01:00
Lennart Poettering 459b9f9ff7 merge two lines in our get_output_flags() functions
loginctl, machinectl, systemctl all have very similar implementations of
a get_output_flags() functions. Simplify it by merging two lines that
set the same flag.
2017-11-10 21:40:47 +01:00
Zbigniew Jędrzejewski-Szmek 1ae17672a2 systemctl: add --dry-run argument 2017-11-07 15:15:09 +01:00
Zbigniew Jędrzejewski-Szmek 8a4b13c5cb treewide: unify identical definitions of polkit_agent_open_if_enabled() (#7187)
Follows the same pattern as pager_open() now.
2017-10-30 09:57:53 +01:00
Boucman 92f34a9c47 Display the systemctl status in green if state is "running" (#7094) 2017-10-15 12:22:47 +02:00
Lubomir Rintel 4e93d369b9 systemctl: clarify --global, --root and --runtime options (#7071)
They're not only for enabling.
2017-10-12 08:14:25 +02:00
Zbigniew Jędrzejewski-Szmek c9905d4dd2 Merge pull request #6944 from poettering/suspend-fix
systemctl reboot/suspend tweaks
2017-10-05 11:26:44 +02:00
Zbigniew Jędrzejewski-Szmek 03d4358277 Merge pull request #6975 from sourcejedi/logind_pid_0_v2
Selectively revert "tree-wide: use pid_is_valid() at more places"
2017-10-04 21:33:52 +02:00
Lennart Poettering 130246d2e8 systemctl: make sure "reboot", "suspend" and friends are always asynchronous
Currently, "systemctl reboot" behaves differently in setups with and
without logind. If logind is used (which is probably the more common
case) the operation is asynchronous, and otherwise synchronous (though
subject to --no-block in this case). Let's clean this up, and always
expose the same behaviour, regardless if logind is used or not: let's
always make it asynchronous.

It might make sense to add a "--block" mode in a future PR that makes
these operations synchronous, but this requires non-trivial work in
logind, and is outside of the scope of this change.

See: #6479
2017-10-04 20:56:24 +02:00
Lennart Poettering 36b69c3131 logind: add Halt() and CanHalt() APIs
This adds new method calls Halt() and CanHalt() to the logind bus APIs.
They aren't overly useful (as the whole concept of halting isn't really
too useful), however they clean up one major asymmetry: currently, using
the "shutdown" legacy commands it is possibly to enqueue a "halt"
operation through logind, while logind officially doesn't actually
support this. Moreover, the path through "shutdown" currently ultimately
fails, since the referenced "halt" action isn't actually defined in
PolicyKit.

Finally, the current logic results in an unexpected asymmetry in
systemctl: "systemctl poweroff", "systemctl reboot" are currently
asynchronous (due to the logind involvement) while "systemctl halt"
isnt. Let's clean this up, and make all three APIs implemented by
logind natively, and all three hence asynchronous in "systemctl".

Moreover, let's add the missing PK action.

Fixes: #6957
2017-10-04 20:56:24 +02:00
Lennart Poettering 4aa1d31c89 Merge pull request #6974 from keszybz/clean-up-defines
Clean up define definitions
2017-10-04 19:25:30 +02:00
Alan Jenkins 72b3f82e17 systemctl: use pid_is_valid() where appropriate
This was the one valid site in commit
ee043777be.

The second part of this hunk, avoiding using `%m`
when we didn't actually have `errno` set, seems
like a nice enough cleanup to be worthwhile on
it's own.

Also use PID_FMT to improve the error message we print
(pid_t is signed).
2017-10-04 15:40:11 +01:00
Yu Watanabe 4c70109600 tree-wide: use IN_SET macro (#6977) 2017-10-04 16:01:32 +02:00
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Alan Jenkins 07b38ba51e Revert "tree-wide: use pid_is_valid() at more places"
This reverts commit ee043777be.

It broke almost everywhere it touched.  The places that
handn't been converted, were mostly followed by special
handling for the invalid PID `0`.  That explains why they
tested for `pid < 0` instead of `pid <= 0`.

I think that one was the first commit I reviewed, heh.
2017-10-03 12:43:24 +01:00
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
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