diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-10-22 19:54:29 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-10-24 23:03:49 +0200 |
commit | 0f03c2a4c093e3d44f4072144827e943c05c8904 (patch) | |
tree | 70232d1b14b4dfcd82983894d13963e2ca9f4fec /src/nspawn/nspawn.c | |
parent | 0f4743651081b5367ab06f238827ddfd4da74e74 (diff) |
path-util: unify how we process paths specified on the command line
Let's introduce a common function that makes relative paths absolute and
warns about any errors while doing so.
Diffstat (limited to 'src/nspawn/nspawn.c')
-rw-r--r-- | src/nspawn/nspawn.c | 41 |
1 files changed, 8 insertions, 33 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 056b4ce5f3..1a2e4b184b 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -276,28 +276,6 @@ static int custom_mounts_prepare(void) { return 0; } -static int set_sanitized_path(char **b, const char *path) { - char *p; - int r; - - assert(b); - assert(path); - - p = canonicalize_file_name(path); - if (!p) { - if (errno != ENOENT) - return -errno; - - r = path_make_absolute_cwd(path, &p); - if (r < 0) - return r; - } - - free(*b); - *b = path_kill_slashes(p); - return 0; -} - static int detect_unified_cgroup_hierarchy(void) { const char *e; int r; @@ -417,24 +395,21 @@ static int parse_argv(int argc, char *argv[]) { return version(); case 'D': - r = set_sanitized_path(&arg_directory, optarg); + r = parse_path_argument_and_warn(optarg, false, &arg_directory); if (r < 0) - return log_error_errno(r, "Invalid root directory: %m"); - + return r; break; case ARG_TEMPLATE: - r = set_sanitized_path(&arg_template, optarg); + r = parse_path_argument_and_warn(optarg, false, &arg_template); if (r < 0) - return log_error_errno(r, "Invalid template directory: %m"); - + return r; break; case 'i': - r = set_sanitized_path(&arg_image, optarg); + r = parse_path_argument_and_warn(optarg, false, &arg_image); if (r < 0) - return log_error_errno(r, "Invalid image path: %m"); - + return r; break; case 'x': @@ -2323,9 +2298,9 @@ static int determine_names(void) { } if (i->type == IMAGE_RAW) - r = set_sanitized_path(&arg_image, i->path); + r = free_and_strdup(&arg_image, i->path); else - r = set_sanitized_path(&arg_directory, i->path); + r = free_and_strdup(&arg_directory, i->path); if (r < 0) return log_error_errno(r, "Invalid image directory: %m"); |