]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/ac-power/ac-power.c
Merge pull request #17549 from yuwata/tiny-fixes
[thirdparty/systemd.git] / src / ac-power / ac-power.c
index f446442ebbdaed6332496e9d10eee28e44289e78..9fabdb9e9f1d690adb4915a69f086cb3eb09867f 100644 (file)
@@ -1,12 +1,8 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-  This file is part of systemd.
-
-  Copyright 2010 Lennart Poettering
-***/
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <getopt.h>
 
+#include "main-func.h"
 #include "util.h"
 
 static bool arg_verbose = false;
@@ -60,15 +56,15 @@ static int parse_argv(int argc, char *argv[]) {
                         assert_not_reached("Unhandled option");
                 }
 
-        if (optind < argc) {
-                log_error("%s takes no arguments.", program_invocation_short_name);
-                return -EINVAL;
-        }
+        if (optind < argc)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "%s takes no arguments.",
+                                       program_invocation_short_name);
 
         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
@@ -79,17 +75,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);