summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-16 10:58:36 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-17 09:13:35 +0100
commit5f200747f6eb0da15e1ee4136ed6bafff2302a6a (patch)
treeac72b03fda3205ce1d76b5921158fd4234824048
parentbdab09849e60299392b37d99de8008b87b8b8a21 (diff)
downloadsystemd-5f200747f6eb0da15e1ee4136ed6bafff2302a6a.tar.gz
escape: define main through macro
-rw-r--r--src/escape/escape.c80
1 files changed, 30 insertions, 50 deletions
diff --git a/src/escape/escape.c b/src/escape/escape.c
index c5cb7897a9..181949d49e 100644
--- a/src/escape/escape.c
+++ b/src/escape/escape.c
@@ -163,7 +163,7 @@ static int parse_argv(int argc, char *argv[]) {
return 1;
}
-int main(int argc, char *argv[]) {
+static int run(int argc, char *argv[]) {
char **i;
int r;
@@ -172,7 +172,7 @@ int main(int argc, char *argv[]) {
r = parse_argv(argc, argv);
if (r <= 0)
- goto finish;
+ return r;
STRV_FOREACH(i, argv + optind) {
_cleanup_free_ char *e = NULL;
@@ -182,26 +182,20 @@ int main(int argc, char *argv[]) {
case ACTION_ESCAPE:
if (arg_path) {
r = unit_name_path_escape(*i, &e);
- if (r < 0) {
- log_error_errno(r, "Failed to escape string: %m");
- goto finish;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to escape string: %m");
} else {
e = unit_name_escape(*i);
- if (!e) {
- r = log_oom();
- goto finish;
- }
+ if (!e)
+ return log_oom();
}
if (arg_template) {
char *x;
r = unit_name_replace_instance(arg_template, e, &x);
- if (r < 0) {
- log_error_errno(r, "Failed to replace instance: %m");
- goto finish;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to replace instance: %m");
free(e);
e = x;
@@ -209,10 +203,8 @@ int main(int argc, char *argv[]) {
char *x;
x = strjoin(e, ".", arg_suffix);
- if (!x) {
- r = log_oom();
- goto finish;
- }
+ if (!x)
+ return log_oom();
free(e);
e = x;
@@ -227,51 +219,38 @@ int main(int argc, char *argv[]) {
_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;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to extract instance: %m");
+ if (isempty(name))
+ return log_error("Unit %s is missing the instance name.", *i);
+
r = unit_name_template(*i, &template);
- if (r < 0) {
- log_error_errno(r, "Failed to extract template: %m");
- goto finish;
- }
- if (arg_template && !streq(arg_template, template)) {
- log_error("Unit %s template %s does not match specified template %s.", *i, template, arg_template);
- r = -EINVAL;
- goto finish;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to extract template: %m");
+ if (arg_template && !streq(arg_template, template))
+ return log_error("Unit %s template %s does not match specified template %s.",
+ *i, template, arg_template);
} else {
name = strdup(*i);
- if (!name) {
- r = log_oom();
- goto finish;
- }
+ if (!name)
+ return log_oom();
}
if (arg_path)
r = unit_name_path_unescape(name, &e);
else
r = unit_name_unescape(name, &e);
+ if (r < 0)
+ return log_error_errno(r, "Failed to unescape string: %m");
- 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);
- if (r < 0) {
- log_error_errno(r, "Failed to mangle name: %m");
- goto finish;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to mangle name: %m");
+
break;
}
@@ -283,6 +262,7 @@ int main(int argc, char *argv[]) {
fputc('\n', stdout);
-finish:
- return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+ return 0;
}
+
+DEFINE_MAIN_FUNCTION(run);