chiark / gitweb /
Introduce udev object cleanup functions
[elogind.git] / src / fsck / fsck.c
index f5d38ad261192dccd59355144fecf54655ac714e..96a79ddcdb6b0a3581919860eca0584d0620f167 100644 (file)
@@ -27,7 +27,6 @@
 #include <fcntl.h>
 #include <sys/file.h>
 
-#include <libudev.h>
 #include <dbus/dbus.h>
 
 #include "util.h"
 #include "special.h"
 #include "bus-errors.h"
 #include "virt.h"
+#include "fileio.h"
+#include "libudev.h"
+#include "udev-util.h"
 
 static bool arg_skip = false;
 static bool arg_force = false;
 static bool arg_show_progress = false;
 
-static void start_target(const char *target, bool isolate) {
+static void start_target(const char *target) {
         DBusMessage *m = NULL, *reply = NULL;
         DBusError error;
-        const char *mode, *basic_target = "basic.target";
+        const char *mode = "replace", *basic_target = "basic.target";
         DBusConnection *bus = NULL;
 
         assert(target);
@@ -55,11 +57,6 @@ static void start_target(const char *target, bool isolate) {
                 goto finish;
         }
 
-        if (isolate)
-                mode = "isolate";
-        else
-                mode = "replace";
-
         log_info("Running request %s/start/%s", target, mode);
 
         if (!(m = dbus_message_new_method_call("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartUnitReplace"))) {
@@ -255,8 +252,8 @@ int main(int argc, char *argv[]) {
         int i = 0, r = EXIT_FAILURE, q;
         pid_t pid;
         siginfo_t status;
-        struct udev *udev = NULL;
-        struct udev_device *udev_device = NULL;
+        _cleanup_udev_unref_ struct udev *udev = NULL;
+        _cleanup_udev_device_unref_ struct udev_device *udev_device = NULL;
         const char *device;
         bool root_directory;
         int progress_pipe[2] = { -1, -1 };
@@ -388,10 +385,10 @@ int main(int argc, char *argv[]) {
 
                 if (status.si_code == CLD_EXITED && (status.si_status & 2) && root_directory)
                         /* System should be rebooted. */
-                        start_target(SPECIAL_REBOOT_TARGET, false);
+                        start_target(SPECIAL_REBOOT_TARGET);
                 else if (status.si_code == CLD_EXITED && (status.si_status & 6))
                         /* Some other problem */
-                        start_target(SPECIAL_EMERGENCY_TARGET, true);
+                        start_target(SPECIAL_EMERGENCY_TARGET);
                 else {
                         r = EXIT_SUCCESS;
                         log_warning("Ignoring error.");
@@ -404,12 +401,6 @@ int main(int argc, char *argv[]) {
                 touch("/run/systemd/quotacheck");
 
 finish:
-        if (udev_device)
-                udev_device_unref(udev_device);
-
-        if (udev)
-                udev_unref(udev);
-
         close_pipe(progress_pipe);
 
         return r;