chiark / gitweb /
systemctl: rework halt/reboot/poweroff/kexec/exit logic around --force
[elogind.git] / src / umount.c
index 79fbba73244e8b33d3d58620583e90f3132ba86e..44bed611ea7482e53ddeed993a5001c32853277e 100644 (file)
@@ -227,16 +227,27 @@ static int loopback_list_get(MountPoint **loopback_list_head) {
 
         udev_list_entry_foreach(item, first) {
                 MountPoint *lb;
+                struct udev_device *d;
                 char *loop;
+                const char *dn;
 
-                loop = cunescape(udev_list_entry_get_name(item));
-                if (!loop) {
+                if (!(d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item)))) {
                         r = -ENOMEM;
                         goto finish;
                 }
 
-                lb = mount_point_alloc(loop);
-                if (!lb) {
+                if ((dn = udev_device_get_devnode(d))) {
+                        loop = strdup(dn);
+                        udev_device_unref(d);
+
+                        if (!loop) {
+                                r = -ENOMEM;
+                                goto finish;
+                        }
+                } else
+                        udev_device_unref(d);
+
+                if (!(lb = mount_point_alloc(loop))) {
                         free(loop);
                         r = -ENOMEM;
                         goto finish;
@@ -251,30 +262,23 @@ finish:
         if (e)
                 udev_enumerate_unref(e);
 
-        free(udev);
+        if (udev)
+                udev_unref(udev);
+
         return r;
 }
 
 static int delete_loopback(const char *device) {
         int fd, r;
 
-        if ((fd = open(device, O_RDONLY|O_CLOEXEC)) < 0) {
-                if (errno == ENOENT) {
-                        log_debug("Loop device %s does not exist.", device);
-                        errno = 0;
-                        return 0;
-                }
+        if ((fd = open(device, O_RDONLY|O_CLOEXEC)) < 0)
                 return -errno;
-        }
 
-        ioctl(fd, LOOP_CLR_FD, 0);
-        r = errno;
+        r = ioctl(fd, LOOP_CLR_FD, 0);
         close_nointr_nofail(fd);
 
-        if (r == ENXIO) /* not bound, so no error */
-                r = 0;
-        errno = r;
-        return -errno;
+        /* ENXIO: not bound, so no error */
+        return (r >= 0 || errno == ENXIO) ? 0 : -errno;
 }
 
 static int mount_points_list_umount(MountPoint **mount_point_list_head) {
@@ -289,7 +293,7 @@ static int mount_points_list_umount(MountPoint **mount_point_list_head) {
                 if (umount2(mp->path, MNT_FORCE) == 0)
                         mount_point_remove_and_free(mp, mount_point_list_head);
                 else {
-                        log_debug("Could not unmount %s: %m", mp->path);
+                        log_warning("Could not unmount %s: %m", mp->path);
                         failed++;
                 }
         }
@@ -306,7 +310,7 @@ static int mount_points_list_remount_read_only(MountPoint **mount_point_list_hea
                 if (mount(NULL, mp->path, NULL, MS_MGC_VAL|MS_REMOUNT|MS_RDONLY, NULL) == 0)
                         mount_point_remove_and_free(mp, mount_point_list_head);
                 else {
-                        log_debug("Could not remount as read-only %s: %m", mp->path);
+                        log_warning("Could not remount as read-only %s: %m", mp->path);
                         failed++;
                 }
         }
@@ -322,7 +326,7 @@ static int swap_points_list_off(MountPoint **swap_list_head) {
                 if (swapoff(swap->path) == 0)
                         mount_point_remove_and_free(swap, swap_list_head);
                 else {
-                        log_debug("Could not swapoff %s: %m", swap->path);
+                        log_warning("Could not deactivate swap %s: %m", swap->path);
                         failed++;
                 }
         }
@@ -338,7 +342,7 @@ static int loopback_points_list_detach(MountPoint **loopback_list_head) {
                 if (delete_loopback(loopback->path) == 0)
                         mount_point_remove_and_free(loopback, loopback_list_head);
                 else {
-                        log_debug("Could not delete loopback %s: %m", loopback->path);
+                        log_warning("Could not delete loopback %s: %m", loopback->path);
                         failed++;
                 }
         }