]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Call mac_selinux_close() from main func macros, convert user-sessions and test-udev
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Nov 2018 15:40:49 +0000 (16:40 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 21 Nov 2018 08:14:00 +0000 (09:14 +0100)
src/shared/main-func.h
src/test/test-udev.c
src/user-sessions/user-sessions.c

index a2b9bc09e00bccef6a60cbd12936938c1e9edcf8..ab6b272117d7dfd9463bfea9cae01c32a86bc576 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 
 #include "pager.h"
+#include "selinux-util.h"
 #include "spawn-ask-password-agent.h"
 #include "spawn-polkit-agent.h"
 #include "static-destruct.h"
@@ -15,6 +16,7 @@
                 static_destruct();                                      \
                 ask_password_agent_close();                             \
                 polkit_agent_close();                                   \
+                mac_selinux_finish();                                   \
                 pager_close();                                          \
                 return ret;                                             \
         }
index 49198f8633fcc3bd9bb55da3baa6579d6a7a27af..3d5bc3ac0b3a59fcb1f835631496d7d504724ec6 100644 (file)
@@ -14,6 +14,7 @@
 #include "device-private.h"
 #include "fs-util.h"
 #include "log.h"
+#include "main-func.h"
 #include "missing.h"
 #include "mkdir.h"
 #include "selinux-util.h"
@@ -53,7 +54,7 @@ static int fake_filesystems(void) {
         return 0;
 }
 
-int main(int argc, char *argv[]) {
+static int run(int argc, char *argv[]) {
         _cleanup_(udev_rules_unrefp) struct udev_rules *rules = NULL;
         _cleanup_(udev_event_freep) struct udev_event *event = NULL;
         _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
@@ -64,19 +65,20 @@ int main(int argc, char *argv[]) {
 
         if (!IN_SET(argc, 2, 3)) {
                 log_error("This program needs one or two arguments, %d given", argc - 1);
-                return EXIT_FAILURE;
+                return -EINVAL;
         }
 
-        if (fake_filesystems() < 0)
-                return EXIT_FAILURE;
+        r = fake_filesystems();
+        if (r < 0)
+                return r;
 
         if (argc == 2) {
                 if (!streq(argv[1], "check")) {
                         log_error("Unknown argument: %s", argv[1]);
-                        return EXIT_FAILURE;
+                        return -EINVAL;
                 }
 
-                return EXIT_SUCCESS;
+                return 0;
         }
 
         log_debug("version %s", PACKAGE_VERSION);
@@ -89,10 +91,8 @@ int main(int argc, char *argv[]) {
 
         const char *syspath = strjoina("/sys", devpath);
         r = device_new_from_synthetic_event(&dev, syspath, action);
-        if (r < 0) {
-                log_debug_errno(r, "Failed to open device '%s'", devpath);
-                goto out;
-        }
+        if (r < 0)
+                return log_debug_errno(r, "Failed to open device '%s'", devpath);
 
         assert_se(event = udev_event_new(dev, 0, NULL));
 
@@ -122,8 +122,8 @@ int main(int argc, char *argv[]) {
 
         udev_event_execute_rules(event, 3 * USEC_PER_SEC, NULL, rules);
         udev_event_execute_run(event, 3 * USEC_PER_SEC);
-out:
-        mac_selinux_finish();
 
-        return EXIT_SUCCESS;
+        return 0;
 }
+
+DEFINE_MAIN_FUNCTION(run);
index fa0829e3848cf197e46d0beb4ba948ef82ed7f0e..4f711c2ed62ccee4149925b92d78e3e74b12c86b 100644 (file)
@@ -6,17 +6,18 @@
 #include "fileio.h"
 #include "fileio-label.h"
 #include "fs-util.h"
+#include "main-func.h"
 #include "log.h"
 #include "selinux-util.h"
 #include "string-util.h"
 #include "util.h"
 
-int main(int argc, char*argv[]) {
+static int run(int argc, char*argv[]) {
         int r, k;
 
         if (argc != 2) {
                 log_error("This program requires one argument.");
-                return EXIT_FAILURE;
+                return -EINVAL;
         }
 
         log_setup_service();
@@ -28,16 +29,15 @@ int main(int argc, char*argv[]) {
         if (streq(argv[1], "start")) {
                 r = unlink_or_warn("/run/nologin");
                 k = unlink_or_warn("/etc/nologin");
-                if (k < 0 && r >= 0)
-                        r = k;
+                if (r < 0)
+                        return r;
+                return k;
 
         } else if (streq(argv[1], "stop"))
-                r = create_shutdown_run_nologin_or_warn();
-        else {
-                log_error("Unknown verb '%s'.", argv[1]);
-                r = -EINVAL;
-        }
+                return create_shutdown_run_nologin_or_warn();
 
-        mac_selinux_finish();
-        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+        log_error("Unknown verb '%s'.", argv[1]);
+        return -EINVAL;
 }
+
+DEFINE_MAIN_FUNCTION(run);