diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-12-06 22:28:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-06 22:28:02 +0100 |
commit | 34f4fcb59f24db46661d412909ab1c7d08b02766 (patch) | |
tree | e7b7be3dc3015f4a9d139714db1fe5d77b009949 /src/systemctl | |
parent | Merge pull request #30085 from YHNdnzj/networkctl-edit-runtime (diff) | |
parent | TEST-26: add test for systemctl edit --stdin (diff) | |
download | systemd-34f4fcb59f24db46661d412909ab1c7d08b02766.tar.xz systemd-34f4fcb59f24db46661d412909ab1c7d08b02766.zip |
Merge pull request #30302 from keszybz/systemd-edit-stdin
systemctl edit --stdin
Diffstat (limited to 'src/systemctl')
-rw-r--r-- | src/systemctl/systemctl-edit.c | 7 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 11 | ||||
-rw-r--r-- | src/systemctl/systemctl.h | 1 |
3 files changed, 17 insertions, 2 deletions
diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index 367afa20f7..d967b1649e 100644 --- a/src/systemctl/systemctl-edit.c +++ b/src/systemctl/systemctl-edit.c @@ -317,12 +317,13 @@ int verb_edit(int argc, char *argv[], void *userdata) { .marker_end = DROPIN_MARKER_END, .remove_parent = !arg_full, .overwrite_with_origin = true, + .stdin = arg_stdin, }; _cleanup_strv_free_ char **names = NULL; sd_bus *bus; int r; - if (!on_tty()) + if (!on_tty() && !arg_stdin) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Cannot edit units if not on a tty."); if (arg_transport != BUS_TRANSPORT_LOCAL) @@ -342,6 +343,10 @@ int verb_edit(int argc, char *argv[], void *userdata) { if (strv_isempty(names)) return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "No units matched the specified patterns."); + if (arg_stdin && arg_full && strv_length(names) != 1) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "With 'edit --stdin --full', exactly one unit for editing must be specified."); + STRV_FOREACH(tmp, names) { r = unit_is_masked(bus, *tmp); if (r < 0) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 0fa672eb90..d278d74789 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -103,6 +103,7 @@ bool arg_kill_value_set = false; char *arg_root = NULL; char *arg_image = NULL; usec_t arg_when = 0; +bool arg_stdin = false; const char *arg_reboot_argument = NULL; enum action arg_action = ACTION_SYSTEMCTL; BusTransport arg_transport = BUS_TRANSPORT_LOCAL; @@ -337,6 +338,7 @@ static int systemctl_help(void) { " --drop-in=NAME Edit unit files using the specified drop-in file name\n" " --when=TIME Schedule halt/power-off/reboot/kexec action after\n" " a certain timestamp\n" + " --stdin Read contents of edited file from stdin\n" "\nSee the %2$s for details.\n", program_invocation_short_name, link, @@ -463,6 +465,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { ARG_NO_WARN, ARG_DROP_IN, ARG_WHEN, + ARG_STDIN, }; static const struct option options[] = { @@ -529,6 +532,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { { "marked", no_argument, NULL, ARG_MARKED }, { "drop-in", required_argument, NULL, ARG_DROP_IN }, { "when", required_argument, NULL, ARG_WHEN }, + { "stdin", no_argument, NULL, ARG_STDIN }, {} }; @@ -1019,6 +1023,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) { break; + case ARG_STDIN: + arg_stdin = true; + break; + case '.': /* Output an error mimicking getopt, and print a hint afterwards */ log_error("%s: invalid option -- '.'", program_invocation_name); @@ -1069,7 +1077,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) { } if (arg_image && arg_root) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Please specify either --root= or --image=, the combination of both is not supported."); + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Please specify either --root= or --image=, the combination of both is not supported."); return 1; } diff --git a/src/systemctl/systemctl.h b/src/systemctl/systemctl.h index a42fc36a2e..17dcfb4048 100644 --- a/src/systemctl/systemctl.h +++ b/src/systemctl/systemctl.h @@ -84,6 +84,7 @@ extern int arg_kill_value; extern bool arg_kill_value_set; extern char *arg_root; extern usec_t arg_when; +extern bool arg_stdin; extern const char *arg_reboot_argument; extern enum action arg_action; extern BusTransport arg_transport; |