summaryrefslogtreecommitdiffstats
path: root/src/systemctl/systemctl-edit.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:40 +0000
commitfc53809803cd2bc2434e312b19a18fa36776da12 (patch)
treeb4b43bd6538f51965ce32856e9c053d0f90919c8 /src/systemctl/systemctl-edit.c
parentAdding upstream version 255.5. (diff)
downloadsystemd-fc53809803cd2bc2434e312b19a18fa36776da12.tar.xz
systemd-fc53809803cd2bc2434e312b19a18fa36776da12.zip
Adding upstream version 256.upstream/256
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/systemctl/systemctl-edit.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c
index 367afa2..15398f8 100644
--- a/src/systemctl/systemctl-edit.c
+++ b/src/systemctl/systemctl-edit.c
@@ -14,8 +14,8 @@
#include "terminal-util.h"
int verb_cat(int argc, char *argv[], void *userdata) {
- _cleanup_hashmap_free_ Hashmap *cached_name_map = NULL, *cached_id_map = NULL;
- _cleanup_(lookup_paths_free) LookupPaths lp = {};
+ _cleanup_hashmap_free_ Hashmap *cached_id_map = NULL, *cached_name_map = NULL;
+ _cleanup_(lookup_paths_done) LookupPaths lp = {};
_cleanup_strv_free_ char **names = NULL;
sd_bus *bus;
bool first = true;
@@ -50,7 +50,7 @@ int verb_cat(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *fragment_path = NULL;
_cleanup_strv_free_ char **dropin_paths = NULL;
- r = unit_find_paths(bus, *name, &lp, false, &cached_name_map, &cached_id_map, &fragment_path, &dropin_paths);
+ r = unit_find_paths(bus, *name, &lp, false, &cached_id_map, &cached_name_map, &fragment_path, &dropin_paths);
if (r == -ERFKILL) {
printf("%s# Unit %s is masked%s.\n",
ansi_highlight_magenta(),
@@ -197,8 +197,8 @@ static int find_paths_to_edit(
EditFileContext *context,
char **names) {
- _cleanup_hashmap_free_ Hashmap *cached_name_map = NULL, *cached_id_map = NULL;
- _cleanup_(lookup_paths_free) LookupPaths lp = {};
+ _cleanup_hashmap_free_ Hashmap *cached_id_map = NULL, *cached_name_map = NULL;
+ _cleanup_(lookup_paths_done) LookupPaths lp = {};
_cleanup_free_ char *drop_in_alloc = NULL, *suffix = NULL;
const char *drop_in;
int r;
@@ -233,13 +233,13 @@ static int find_paths_to_edit(
_cleanup_free_ char *path = NULL;
_cleanup_strv_free_ char **unit_paths = NULL;
- r = unit_find_paths(bus, *name, &lp, /* force_client_side= */ false, &cached_name_map, &cached_id_map, &path, &unit_paths);
+ r = unit_find_paths(bus, *name, &lp, /* force_client_side= */ false, &cached_id_map, &cached_name_map, &path, &unit_paths);
if (r == -EKEYREJECTED) {
/* If loading of the unit failed server side complete, then the server won't tell us
* the unit file path. In that case, find the file client side. */
log_debug_errno(r, "Unit '%s' was not loaded correctly, retrying client-side.", *name);
- r = unit_find_paths(bus, *name, &lp, /* force_client_side= */ true, &cached_name_map, &cached_id_map, &path, &unit_paths);
+ r = unit_find_paths(bus, *name, &lp, /* force_client_side= */ true, &cached_id_map, &cached_name_map, &path, &unit_paths);
}
if (r == -ERFKILL)
return log_error_errno(r, "Unit '%s' masked, cannot edit.", *name);
@@ -247,13 +247,12 @@ static int find_paths_to_edit(
return r; /* Already logged by unit_find_paths() */
if (!path) {
- if (!arg_force) {
- log_info("Run 'systemctl edit%s --force --full %s' to create a new unit.",
- arg_runtime_scope == RUNTIME_SCOPE_GLOBAL ? " --global" :
- arg_runtime_scope == RUNTIME_SCOPE_USER ? " --user" : "",
- *name);
- return -ENOENT;
- }
+ if (!arg_force)
+ return log_info_errno(SYNTHETIC_ERRNO(ENOENT),
+ "Run 'systemctl edit%s --force --full %s' to create a new unit.",
+ arg_runtime_scope == RUNTIME_SCOPE_GLOBAL ? " --global" :
+ arg_runtime_scope == RUNTIME_SCOPE_USER ? " --user" : "",
+ *name);
/* Create a new unit from scratch */
r = unit_file_create_new(
@@ -317,12 +316,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 +342,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)