expand path of systemctl link argument (#6186)
systemctl link is the only systemctl verb that takes a filename (and not a unit name) as argument use path_strv_make_absolute_cwd to expand the provided filename in order to make it easier to use from the command line keep the absolute pathname requirement when --root is used [zj: add explicit error messages for the cases of --root and plain filename instead of skipping normalization and just relying on systemd to refuse to link non-absolute arguments. This allows us to make the error message more informative.]
This commit is contained in:
parent
e1bc3004ab
commit
decd79829a
|
@ -6033,6 +6033,34 @@ static int mangle_names(char **original_names, char ***mangled_names) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int normalize_filenames(char **names) {
|
||||||
|
char **u;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
STRV_FOREACH(u, names)
|
||||||
|
if (!path_is_absolute(*u)) {
|
||||||
|
char* normalized_path;
|
||||||
|
|
||||||
|
if (!isempty(arg_root)) {
|
||||||
|
log_error("Non-absolute paths are not allowed when --root is used: %s", *u);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strchr(*u,'/')) {
|
||||||
|
log_error("Link argument does contain at least one directory separator: %s", *u);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = path_make_absolute_cwd(*u, &normalized_path);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
free_and_replace(*u, normalized_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int normalize_names(char **names, bool warn_if_path) {
|
static int normalize_names(char **names, bool warn_if_path) {
|
||||||
char **u;
|
char **u;
|
||||||
bool was_path = false;
|
bool was_path = false;
|
||||||
|
@ -6129,6 +6157,12 @@ static int enable_unit(int argc, char *argv[], void *userdata) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (streq(verb, "link")) {
|
||||||
|
r = normalize_filenames(names);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
if (install_client_side()) {
|
if (install_client_side()) {
|
||||||
UnitFileFlags flags;
|
UnitFileFlags flags;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue