1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 02:21:44 +03:00

import: define mains through macro

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-11-16 12:25:43 +01:00
parent 3c79f0b3ce
commit 5272ae42ce
4 changed files with 25 additions and 35 deletions

View File

@ -269,7 +269,6 @@ static int parse_argv(int argc, char *argv[]) {
} }
static int export_main(int argc, char *argv[]) { static int export_main(int argc, char *argv[]) {
static const Verb verbs[] = { static const Verb verbs[] = {
{ "help", VERB_ANY, VERB_ANY, 0, help }, { "help", VERB_ANY, VERB_ANY, 0, help },
{ "tar", 2, 3, 0, export_tar }, { "tar", 2, 3, 0, export_tar },
@ -280,7 +279,7 @@ static int export_main(int argc, char *argv[]) {
return dispatch_verb(argc, argv, verbs, NULL); return dispatch_verb(argc, argv, verbs, NULL);
} }
int main(int argc, char *argv[]) { static int run(int argc, char *argv[]) {
int r; int r;
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
@ -289,12 +288,11 @@ int main(int argc, char *argv[]) {
r = parse_argv(argc, argv); r = parse_argv(argc, argv);
if (r <= 0) if (r <= 0)
goto finish; return r;
(void) ignore_signals(SIGPIPE, -1); (void) ignore_signals(SIGPIPE, -1);
r = export_main(argc, argv); return export_main(argc, argv);
finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} }
DEFINE_MAIN_FUNCTION(run);

View File

@ -292,7 +292,6 @@ static int parse_argv(int argc, char *argv[]) {
} }
static int import_main(int argc, char *argv[]) { static int import_main(int argc, char *argv[]) {
static const Verb verbs[] = { static const Verb verbs[] = {
{ "help", VERB_ANY, VERB_ANY, 0, help }, { "help", VERB_ANY, VERB_ANY, 0, help },
{ "tar", 2, 3, 0, import_tar }, { "tar", 2, 3, 0, import_tar },
@ -303,7 +302,7 @@ static int import_main(int argc, char *argv[]) {
return dispatch_verb(argc, argv, verbs, NULL); return dispatch_verb(argc, argv, verbs, NULL);
} }
int main(int argc, char *argv[]) { static int run(int argc, char *argv[]) {
int r; int r;
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
@ -312,12 +311,11 @@ int main(int argc, char *argv[]) {
r = parse_argv(argc, argv); r = parse_argv(argc, argv);
if (r <= 0) if (r <= 0)
goto finish; return 0;
(void) ignore_signals(SIGPIPE, -1); (void) ignore_signals(SIGPIPE, -1);
r = import_main(argc, argv); return import_main(argc, argv);
finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} }
DEFINE_MAIN_FUNCTION(run);

View File

@ -1113,7 +1113,7 @@ static int manager_run(Manager *m) {
m); m);
} }
int main(int argc, char *argv[]) { static int run(int argc, char *argv[]) {
_cleanup_(manager_unrefp) Manager *m = NULL; _cleanup_(manager_unrefp) Manager *m = NULL;
int r; int r;
@ -1125,28 +1125,24 @@ int main(int argc, char *argv[]) {
if (argc != 1) { if (argc != 1) {
log_error("This program takes no arguments."); log_error("This program takes no arguments.");
r = -EINVAL; return -EINVAL;
goto finish;
} }
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD, -1) >= 0); assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD, -1) >= 0);
r = manager_new(&m); r = manager_new(&m);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to allocate manager object: %m"); return log_error_errno(r, "Failed to allocate manager object: %m");
goto finish;
}
r = manager_add_bus_objects(m); r = manager_add_bus_objects(m);
if (r < 0) if (r < 0)
goto finish; return r;
r = manager_run(m); r = manager_run(m);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to run event loop: %m"); return log_error_errno(r, "Failed to run event loop: %m");
goto finish;
}
finish: return 0;
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} }
DEFINE_MAIN_FUNCTION(run);

View File

@ -304,7 +304,6 @@ static int parse_argv(int argc, char *argv[]) {
} }
static int pull_main(int argc, char *argv[]) { static int pull_main(int argc, char *argv[]) {
static const Verb verbs[] = { static const Verb verbs[] = {
{ "help", VERB_ANY, VERB_ANY, 0, help }, { "help", VERB_ANY, VERB_ANY, 0, help },
{ "tar", 2, 3, 0, pull_tar }, { "tar", 2, 3, 0, pull_tar },
@ -315,7 +314,7 @@ static int pull_main(int argc, char *argv[]) {
return dispatch_verb(argc, argv, verbs, NULL); return dispatch_verb(argc, argv, verbs, NULL);
} }
int main(int argc, char *argv[]) { static int run(int argc, char *argv[]) {
int r; int r;
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
@ -324,12 +323,11 @@ int main(int argc, char *argv[]) {
r = parse_argv(argc, argv); r = parse_argv(argc, argv);
if (r <= 0) if (r <= 0)
goto finish; return r;
(void) ignore_signals(SIGPIPE, -1); (void) ignore_signals(SIGPIPE, -1);
r = pull_main(argc, argv); return pull_main(argc, argv);
finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} }
DEFINE_MAIN_FUNCTION(run);