diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-16 10:39:57 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-17 09:13:35 +0100 |
commit | 9a5cedc319d56bbf3e65046e8e73ee94612f0fef (patch) | |
tree | c357edf4903b45a68b0e550b07213878739cfce9 /src/ac-power | |
parent | a974a6569e31665717661dbf223e5ab36a515fb8 (diff) | |
download | systemd-9a5cedc319d56bbf3e65046e8e73ee94612f0fef.tar.gz |
ac-power: define main through macro
I decided to use a separate definition for this because it's too easy to return
positive from functions which don't need this distinction and only return
negative on error and success otherwise.
Diffstat (limited to 'src/ac-power')
-rw-r--r-- | src/ac-power/ac-power.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/ac-power/ac-power.c b/src/ac-power/ac-power.c index 7ca72ef5f5..2d8cbb985f 100644 --- a/src/ac-power/ac-power.c +++ b/src/ac-power/ac-power.c @@ -63,7 +63,7 @@ static int parse_argv(int argc, char *argv[]) { return 1; } -int main(int argc, char *argv[]) { +static int run(int argc, char *argv[]) { int r; /* This is mostly intended to be used for scripts which want @@ -74,17 +74,16 @@ int main(int argc, char *argv[]) { r = parse_argv(argc, argv); if (r <= 0) - goto finish; + return r; r = on_ac_power(); - if (r < 0) { - log_error_errno(r, "Failed to read AC status: %m"); - goto finish; - } + if (r < 0) + return log_error_errno(r, "Failed to read AC status: %m"); if (arg_verbose) puts(yes_no(r)); -finish: - return r < 0 ? EXIT_FAILURE : !r; + return r == 0; } + +DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run); |