]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shutdown/umount.c
shutdown: use "int" for log level type
[thirdparty/systemd.git] / src / shutdown / umount.c
index 7af0195aab83530247b6da40dae54a1089b84cd8..c75be39fefc88c9a0fcf61452107e179b12630e2 100644 (file)
@@ -5,13 +5,14 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <linux/dm-ioctl.h>
 #include <linux/loop.h>
 #include <string.h>
 #include <sys/mount.h>
 #include <sys/swap.h>
-
-/* This needs to be after sys/mount.h :( */
-#include <libmount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include "sd-device.h"
 
@@ -22,7 +23,7 @@
 #include "escape.h"
 #include "fd-util.h"
 #include "fstab-util.h"
-#include "linux-3.13/dm-ioctl.h"
+#include "libmount-util.h"
 #include "mount-setup.h"
 #include "mount-util.h"
 #include "mountpoint-util.h"
@@ -35,9 +36,6 @@
 #include "util.h"
 #include "virt.h"
 
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table*, mnt_free_table);
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter*, mnt_free_iter);
-
 static void mount_point_free(MountPoint **head, MountPoint *m) {
         assert(head);
         assert(m);
@@ -57,18 +55,13 @@ void mount_points_list_free(MountPoint **head) {
 }
 
 int mount_points_list_get(const char *mountinfo, MountPoint **head) {
-        _cleanup_(mnt_free_tablep) struct libmnt_table *t = NULL;
-        _cleanup_(mnt_free_iterp) struct libmnt_iter *i = NULL;
+        _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
+        _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
         int r;
 
         assert(head);
 
-        t = mnt_new_table();
-        i = mnt_new_iter(MNT_ITER_FORWARD);
-        if (!t || !i)
-                return log_oom();
-
-        r = mnt_table_parse_mtab(t, mountinfo);
+        r = libmount_parse(mountinfo, NULL, &table, &iter);
         if (r < 0)
                 return log_error_errno(r, "Failed to parse %s: %m", mountinfo);
 
@@ -76,13 +69,12 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
                 struct libmnt_fs *fs;
                 const char *path, *fstype;
                 _cleanup_free_ char *options = NULL;
-                _cleanup_free_ char *p = NULL;
                 unsigned long remount_flags = 0u;
                 _cleanup_free_ char *remount_options = NULL;
                 bool try_remount_ro;
-                MountPoint *m;
+                _cleanup_free_ MountPoint *m = NULL;
 
-                r = mnt_table_next_fs(t, i, &fs);
+                r = mnt_table_next_fs(table, iter, &fs);
                 if (r == 1)
                         break;
                 if (r < 0)
@@ -92,18 +84,15 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
                 if (!path)
                         continue;
 
-                if (cunescape(path, UNESCAPE_RELAX, &p) < 0)
-                        return log_oom();
-
                 fstype = mnt_fs_get_fstype(fs);
 
                 /* Combine the generic VFS options with the FS-specific
                  * options. Duplicates are not a problem here, because the only
                  * options that should come up twice are typically ro/rw, which
-                 * are turned into MS_RDONLY or the invertion of it.
+                 * are turned into MS_RDONLY or the inversion of it.
                  *
                  * Even if there are duplicates later in mount_option_mangle()
-                 * it shouldn't hurt anyways as they override each other.
+                 * they shouldn't hurt anyways as they override each other.
                  */
                 if (!strextend_with_separator(&options, ",",
                                               mnt_fs_get_vfs_options(fs),
@@ -121,9 +110,9 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
                  * and hence not worth spending time on. Also, in
                  * unprivileged containers we might lack the rights to
                  * unmount these things, hence don't bother. */
-                if (mount_point_is_api(p) ||
-                    mount_point_ignore(p) ||
-                    PATH_STARTSWITH_SET(p, "/dev", "/sys", "/proc"))
+                if (mount_point_is_api(path) ||
+                    mount_point_ignore(path) ||
+                    PATH_STARTSWITH_SET(path, "/dev", "/sys", "/proc"))
                         continue;
 
                 /* If we are in a container, don't attempt to
@@ -169,12 +158,15 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
                 if (!m)
                         return log_oom();
 
-                free_and_replace(m->path, p);
-                free_and_replace(m->remount_options, remount_options);
+                m->path = strdup(path);
+                if (!m->path)
+                        return log_oom();
+
+                m->remount_options = TAKE_PTR(remount_options);
                 m->remount_flags = remount_flags;
                 m->try_remount_ro = try_remount_ro;
 
-                LIST_PREPEND(mount_point, *head, m);
+                LIST_PREPEND(mount_point, *head, TAKE_PTR(m));
         }
 
         return 0;
@@ -198,10 +190,8 @@ int swap_list_get(const char *swaps, MountPoint **head) {
 
         for (;;) {
                 struct libmnt_fs *fs;
-
-                MountPoint *swap;
+                _cleanup_free_ MountPoint *swap = NULL;
                 const char *source;
-                _cleanup_free_ char *d = NULL;
 
                 r = mnt_table_next_fs(t, i, &fs);
                 if (r == 1)
@@ -213,16 +203,15 @@ int swap_list_get(const char *swaps, MountPoint **head) {
                 if (!source)
                         continue;
 
-                r = cunescape(source, UNESCAPE_RELAX, &d);
-                if (r < 0)
-                        return r;
-
                 swap = new0(MountPoint, 1);
                 if (!swap)
                         return -ENOMEM;
 
-                free_and_replace(swap->path, d);
-                LIST_PREPEND(mount_point, *head, swap);
+                swap->path = strdup(source);
+                if (!swap->path)
+                        return -ENOMEM;
+
+                LIST_PREPEND(mount_point, *head, TAKE_PTR(swap));
         }
 
         return 0;
@@ -396,7 +385,7 @@ static int remount_with_timeout(MountPoint *m, int umount_log_level) {
 
         assert(m);
 
-        /* Due to the possiblity of a remount operation hanging, we
+        /* Due to the possibility of a remount operation hanging, we
          * fork a child process and set a timeout. If the timeout
          * lapses, the assumption is that that particular remount
          * failed. */
@@ -434,7 +423,7 @@ static int umount_with_timeout(MountPoint *m, int umount_log_level) {
 
         assert(m);
 
-        /* Due to the possiblity of a umount operation hanging, we
+        /* Due to the possibility of a umount operation hanging, we
          * fork a child process and set a timeout. If the timeout
          * lapses, the assumption is that that particular umount
          * failed. */
@@ -492,7 +481,7 @@ static int mount_points_list_umount(MountPoint **head, bool *changed, int umount
                          * underlying mount. There's nothing we can do
                          * about it for the general case, but we can
                          * do something about it if it is aliased
-                         * somehwere else via a bind mount. If we
+                         * somewhere else via a bind mount. If we
                          * explicitly remount the super block of that
                          * alias read-only we hence should be
                          * relatively safe regarding keeping a dirty fs