Commit graph

1022 commits

Author SHA1 Message Date
Lennart Poettering ee4296496f systemctl: more SYNTHETIC_ERRNO() conversion 2019-03-27 12:37:37 +01:00
Lennart Poettering c45e5fb877 systemctl: replace switch statement by table of structures 2019-03-27 12:37:37 +01:00
Zbigniew Jędrzejewski-Szmek 2771aaf571 systemctl: define less stuff when !HAVE_SYSV_COMPAT
We'd translate our action to sysv runlevel action, only to discard the result
in talk_initctl(). Let's just ifdef the whole thing away.

Fixes #12103.
2019-03-26 19:06:48 +01:00
Lennart Poettering 1d52a931c6 systemctl: move --failed close to --state= in help text 2019-03-25 15:25:58 +01:00
Lennart Poettering 8e54300425 systemctl: underline sections in help text
Taking inspiration from the recent commit that added that to nspawn's
help text.
2019-03-25 15:25:58 +01:00
Lennart Poettering 3bfa8668b0 systemctl: use structured initialization 2019-03-25 15:25:57 +01:00
Lennart Poettering 2f50e59f2b systemctl: use SYNTHETIC_ERRNO everywhere 2019-03-25 15:23:08 +01:00
Lennart Poettering 63a3b3cb70 systemctl: split out some SysV compat stuff into its own C file
systemctl.c is way to large already. Let's split out some stuff out that
is easy to split out.
2019-03-25 15:23:08 +01:00
Lennart Poettering 16b4623620
Merge pull request #11602 from vesajaaskelainen/dbus-reboot-with-parameters
dbus-manager: Add RebootWithParameters d-bus method
2019-03-22 21:07:47 +01:00
Vesa Jääskeläinen 77defcf538 systemctl: restore "systemctl reboot ARG" functionality
Commit d85515edcf changed logic how reboot is
executed. That commit changed behavior to use emergency action reboot code path
to perform the reboot.

This inadvertently broke rebooting with argument:
$ systemctl reboot custom-reason

Restore original behavior so that if reboot service unit similar to
systemd-reboot.service is executed it is possible to override reboot reason
with "systemctl reboot ARG".

When "systemctl reboot ARG" is executed ARG is placed in file
/run/systemd/reboot-param and reboot is issued using logind's Reboot
dbus-service.

If RebootArgument is specified in systemd-reboot.service it takes precedence
over what systemctl sets.

Fixes: #11828
2019-03-22 17:38:54 +02:00
Lennart Poettering 8d1ee64829 systemctl: make a copy of the "verb" from argv[] before forking off a child 2019-03-21 18:10:06 +01:00
Lennart Poettering 290cb8e883 systemctl: tiny optimization 2019-03-21 18:10:06 +01:00
Lennart Poettering b1dffbb91b systemctl: add missing OOM check 2019-03-21 18:10:06 +01:00
Lennart Poettering 3483460cb8 systemctl: document argv[] array 2019-03-21 18:10:06 +01:00
Lennart Poettering d86e4c979a systemctl: use saved_argv where we can
No need to have another variable where we keep the original argv[].
Let's juse reuse the one DEFINE_MAIN_FUNCTION() stores for us anyway.
2019-03-21 18:10:06 +01:00
Zbigniew Jędrzejewski-Szmek 9dd6ccf7c0
Merge pull request #12014 from poettering/systemctl-exit-fix
systemctl fallback error propagation fix
2019-03-21 17:37:09 +01:00
Lennart Poettering 2e13c0c354 systemctl: start_unit() returns > 0 on error, let's catch that properly
Let's make sure we fall back correctly to initctl when start_unit()
returns an error > 0.

Fixes: #11546
2019-03-20 15:05:27 +01:00
Lennart Poettering 9dccc6d3ae systemctl: use strv_consume() where we can 2019-03-20 14:53:07 +01:00
Lennart Poettering 61ff45db95 systemctl: port to static destructors 2019-03-20 14:53:07 +01:00
Lennart Poettering 25b1d72dcc bus-unit-util: split out code that shows a unit's process tree
The code is complex enough to deserve its own .c file. Let's split this
out.
2019-03-13 17:41:41 +01:00
Lennart Poettering e45c81b8bc shared: split out code to wait for jobs to complet into its own source file
It's complex enough and quite a few functions. Let's hence split this
out.

No code change, just some rearranging of source files.
2019-03-13 17:39:24 +01:00
Lennart Poettering aee7082fbd systemctl: drop unnecessary {} 2019-03-13 17:38:43 +01:00
Lennart Poettering 96e895efaf systemctl: use strv_consume() where appropriate 2019-03-13 17:38:43 +01:00
Lennart Poettering fb1ac50e4e systemctl: minimize scope of 'p' 2019-03-13 17:38:43 +01:00
Lennart Poettering 9a1996455e systemctl: refactor code to watch unit ActiveState a bit
let's split out one function, to make this reusable
2019-03-13 17:38:43 +01:00
Lennart Poettering cc5957dca0 bootspec: don't log in boot_entries_load_config_auto() about no ESP
Let's do it in the caller instead. That way, logind can stay silent
about it.

Fixes: #11950
2019-03-13 17:06:24 +01:00
Lennart Poettering 760877e90c util: split out sorting related calls to new sort-util.[ch] 2019-03-13 12:16:43 +01:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +01:00
Lennart Poettering 97af80c5a7 systemctl: add support for booting into boot menu/entry
(This also removes support for booting into the EFI firmware setup
without logind. That's because otherwise the non-EFI fallback logind
implements can't work.)

Fixes: #9896
2019-03-05 16:52:46 +01:00
Lennart Poettering 38bd74d67e bootspec: get rid of find_default_boot_entry() entirely
Now only two operations are left. Let's just move this into the caller,
since it should make things simpler, clearer and shorter, in particular
as there's only a single user for this.
2019-03-05 16:50:58 +01:00
Lennart Poettering 5b1da1ba6d bootspec: simplify find_default_boot_entry()
If the only caller passes NULL for the two paths, let's remove the
parameter altogether.
2019-03-05 16:50:58 +01:00
Lennart Poettering c943e95f89 systemctl: let's FORK_WAIT where we can 2019-03-05 16:50:58 +01:00
Lennart Poettering 0f88d82979 systemctl: when something is not supported use EOPNOTSUPP 2019-03-05 16:50:58 +01:00
Lennart Poettering 78c38fe79c systemctl: be careful with boot loader entries lacking a 'linux' line
A boot loader entry might not have a 'linux' line, but an 'efi' line or
something else. Let's handle that case nicely.
2019-03-05 16:50:58 +01:00
Lennart Poettering 7800322ca5 bootspec: move log msg from systemctl.c to bootspec.c
find_default_boot_entry() is only used by systemctl.c, and currently
handles one log message in the caller instead of the callee. Let's
simplify that and move it over, too
2019-03-05 16:50:58 +01:00
Yu Watanabe 305a285092 systemctl: format LogExtraFields= in 'show' command 2019-03-04 23:45:07 +09:00
Yu Watanabe 4c787df72f systemctl: format BindPaths= or TemporaryFileSystems= in 'show' command 2019-03-04 23:45:07 +09:00
Yu Watanabe 04749e4003 systemctl: print RestrictAddressFamilies= in 'show' command 2019-03-04 23:45:07 +09:00
Yu Watanabe 48d3358db1 systemctl: show nothing if no LoadError= 2019-03-04 23:45:07 +09:00
Yu Watanabe 9c1f946566 systemctl: show IPAddressAllow= and IPAddressDeny= in 'show' command 2019-03-04 23:45:07 +09:00
Yu Watanabe 4a22071201 systemctl: show SuccessExitStatus= and friends 2019-03-04 23:35:56 +09:00
Yu Watanabe 8e066ef316 systemctl: use streq() if arguments must be non-NULL 2019-03-04 23:35:56 +09:00
Yu Watanabe a3ddd4571d systemctl: do not show negative values in {Success,Failure}ActionExitStatus= 2019-03-04 23:35:56 +09:00
Yu Watanabe 102b021460 bus-util: drop unnecessary re-formatting 2019-03-04 23:35:46 +09:00
INSUN PYO c7bb2fec78 systemctl: show SELinuxContext=, AppArmorProfile= and SmackProcessLabel=
Run: systemctl show -a dbus.service | grep -E "SELinuxContext|AppArmorProfile|SmackProcessLabel"

Before patch:
  SELinuxContext=[unprintable]
  AppArmorProfile=[unprintable]
  SmackProcessLabel=[unprintable]

After patch:
  SELinuxContext=[""|"value of context"]
  AppArmorProfile=[""|"value of context"]
  SmackProcessLabel=[""|"value of context"]
2019-03-04 15:27:30 +01:00
Lennart Poettering a2f8664e9a bootspec: load entries from both the ESP and XBOOTLDR partitions
Let's simply search in both.
2019-03-01 12:41:32 +01:00
Lennart Poettering 9fc32cd9b3 systemctl: add missing OOM checks 2019-03-01 12:41:32 +01:00
Lennart Poettering 8a1ef3bf8d systemctl: use SYNTHETIC_ERRNO() where appropriate 2019-03-01 12:41:32 +01:00
Lennart Poettering 947fbaea8b systemctl: drop arg_esp_path variable from systemctl
It's not set ever (and there's no real need to make it settable, since
users can as well set $SYSTEMD_ESP_PATH to configure this.
2019-03-01 12:41:32 +01:00
Lennart Poettering 43b736a84b bootspec: store 'root' field in each bootspec entry we load
This 'root' field contains the root path of the partition we found the
snippet in. The 'kernel', 'initrd', 'efi', … fields are relative to this
path.

This becomes particularly useful later when we add support for loading
snippets from both the ESP and XBOOTLDR, but already simplifies the code
for us a bit in systemctl.
2019-03-01 12:41:32 +01:00
Lennart Poettering b2238e380e test,systemctl,nspawn: use "const char*" instead of "char*" as iterator for FOREACH_STRING()
The macro iterates through literal strings (i.e. constant strings),
hence it's more correct to have the iterator const too.
2019-01-16 12:29:30 +01:00
Lennart Poettering e4abfc77c4
Merge pull request #11197 from keszybz/various-fixups
Various fixups
2018-12-18 14:35:00 +01:00
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