diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-12-02 16:25:15 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-12-05 18:47:19 +0100 |
commit | 329050c5e2c7e9561699f87b5edb72edd0d54c96 (patch) | |
tree | ab988f2bdfca93855b95a42791510b5e59ffb6e3 /src/systemctl/systemctl-edit.c | |
parent | systemctl: add message when edit is aborted (diff) | |
download | systemd-329050c5e2c7e9561699f87b5edb72edd0d54c96.tar.xz systemd-329050c5e2c7e9561699f87b5edb72edd0d54c96.zip |
systemctl: add "edit --stdin"
This is a fancy wrapper around "cat <<EOF", but:
- the user doesn't need to figure out the file name,
- parent directories are created automatically,
- daemon-reload is implied,
so it's a convenient way to create units or drop-ins.
Closes https://github.com/systemd/systemd/issues/21862.
Diffstat (limited to 'src/systemctl/systemctl-edit.c')
-rw-r--r-- | src/systemctl/systemctl-edit.c | 7 |
1 files changed, 6 insertions, 1 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) |