summaryrefslogtreecommitdiff
path: root/src/systemctl
diff options
context:
space:
mode:
authorDoug Christman <douglaschristman@gmail.com>2016-06-24 02:00:35 -0400
committerMartin Pitt <martin.pitt@ubuntu.com>2016-06-24 08:00:35 +0200
commit39c38ce17c3a15f7b709536a6d7f1f7e093ac450 (patch)
treeadac9ba09b9974bdd11e836d99513e351093d0fd /src/systemctl
parentceeddf79b8464469a5307a1030862c7c4fe289e9 (diff)
systemctl: Create new unit files with "edit --force" (#3584)
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 38b5a7e082..0a8e60c195 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2499,7 +2499,7 @@ static int unit_find_paths(
r = 1;
}
- if (r == 0)
+ if (r == 0 && !arg_force)
log_error("No files found for %s.", unit_name);
return r;
@@ -6070,7 +6070,7 @@ static int create_edit_temp_file(const char *new_path, const char *original_path
return log_error_errno(r, "Failed to create temporary file \"%s\": %m", t);
} else if (r < 0)
- return log_error_errno(r, "Failed to copy \"%s\" to \"%s\": %m", original_path, t);
+ return log_error_errno(r, "Failed to create temporary file for \"%s\": %m", new_path);
*ret_tmp_fn = t;
t = NULL;
@@ -6114,9 +6114,10 @@ static int get_file_to_edit(
return 0;
}
-static int unit_file_create_dropin(
+static int unit_file_create_new(
const LookupPaths *paths,
const char *unit_name,
+ const char *suffix,
char **ret_new_path,
char **ret_tmp_path) {
@@ -6127,7 +6128,7 @@ static int unit_file_create_dropin(
assert(ret_new_path);
assert(ret_tmp_path);
- ending = strjoina(unit_name, ".d/override.conf");
+ ending = strjoina(unit_name, suffix);
r = get_file_to_edit(paths, ending, &tmp_new_path);
if (r < 0)
return r;
@@ -6180,7 +6181,6 @@ static int unit_file_create_copy(
r = create_edit_temp_file(tmp_new_path, fragment_path, &tmp_tmp_path);
if (r < 0) {
- log_error_errno(r, "Failed to create temporary file for \"%s\": %m", tmp_new_path);
free(tmp_new_path);
return r;
}
@@ -6291,18 +6291,26 @@ static int find_paths_to_edit(sd_bus *bus, char **names, char ***paths) {
r = unit_find_paths(bus, *name, &lp, &path, NULL);
if (r < 0)
return r;
- else if (r == 0)
- return -ENOENT;
- else if (!path) {
- // FIXME: support units with path==NULL (no FragmentPath)
- log_error("No fragment exists for %s.", *name);
- return -ENOENT;
+ else if (!arg_force) {
+ if (r == 0) {
+ log_error("Run 'systemctl edit --force %s' to create a new unit.", *name);
+ return -ENOENT;
+ } else if (!path) {
+ // FIXME: support units with path==NULL (no FragmentPath)
+ log_error("No fragment exists for %s.", *name);
+ return -ENOENT;
+ }
+ }
+
+ if (path) {
+ if (arg_full)
+ r = unit_file_create_copy(&lp, *name, path, &new_path, &tmp_path);
+ else
+ r = unit_file_create_new(&lp, *name, ".d/override.conf", &new_path, &tmp_path);
+ } else {
+ r = unit_file_create_new(&lp, *name, NULL, &new_path, &tmp_path);
}
- if (arg_full)
- r = unit_file_create_copy(&lp, *name, path, &new_path, &tmp_path);
- else
- r = unit_file_create_dropin(&lp, *name, &new_path, &tmp_path);
if (r < 0)
return r;