diff options
author | Lucas Werkmeister <mail@lucaswerkmeister.de> | 2016-10-30 15:43:01 +0100 |
---|---|---|
committer | Lucas Werkmeister <mail@lucaswerkmeister.de> | 2018-06-25 11:13:38 +0200 |
commit | e563e2534c074f3d10cb1eb9e9bb4eb623590587 (patch) | |
tree | d4ff3c045d3b5e3a531af979912c243129b9f50b /src/escape | |
parent | a26fec240862c7bc466f468490bae2395f263708 (diff) | |
download | systemd-e563e2534c074f3d10cb1eb9e9bb4eb623590587.tar.gz |
escape: support --unescape with --template
Diffstat (limited to 'src/escape')
-rw-r--r-- | src/escape/escape.c | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/src/escape/escape.c b/src/escape/escape.c index 371ddbe02b..3cf4a20d1e 100644 --- a/src/escape/escape.c +++ b/src/escape/escape.c @@ -119,8 +119,13 @@ static int parse_argv(int argc, char *argv[]) { return -EINVAL; } - if ((arg_template || arg_suffix) && arg_action != ACTION_ESCAPE) { - log_error("--suffix= and --template= are not compatible with --unescape or --mangle."); + if ((arg_template || arg_suffix) && arg_action == ACTION_MANGLE) { + log_error("--suffix= and --template= are not compatible with --mangle."); + return -EINVAL; + } + + if (arg_suffix && arg_action == ACTION_UNESCAPE) { + log_error("--suffix is not compatible with --unescape."); return -EINVAL; } @@ -189,17 +194,51 @@ int main(int argc, char *argv[]) { break; - case ACTION_UNESCAPE: + case ACTION_UNESCAPE: { + _cleanup_free_ char *name = NULL; + + if (arg_template) { + _cleanup_free_ char *template = NULL; + + r = unit_name_to_instance(*i, &name); + if (r < 0) { + log_error_errno(r, "Failed to extract instance: %m"); + goto finish; + } + if (isempty(name)) { + log_error("Unit %s is missing the instance name.", *i); + r = -EINVAL; + goto finish; + } + r = unit_name_template(*i, &template); + if (r < 0) { + log_error_errno(r, "Failed to extract template: %m"); + goto finish; + } + if (!streq(arg_template, template)) { + log_error("Unit %s template %s does not match specified template %s.", *i, template, arg_template); + r = -EINVAL; + goto finish; + } + } else { + name = strdup(*i); + if (!name) { + r = log_oom(); + goto finish; + } + } + if (arg_path) - r = unit_name_path_unescape(*i, &e); + r = unit_name_path_unescape(name, &e); else - r = unit_name_unescape(*i, &e); + r = unit_name_unescape(name, &e); if (r < 0) { log_error_errno(r, "Failed to unescape string: %m"); goto finish; } break; + } case ACTION_MANGLE: r = unit_name_mangle(*i, 0, &e); |