systemd/0001-umount-modernizations.patch

120 lines
4.3 KiB
Diff
Raw Normal View History

From c3544e8d2c2d870a2aff0944aff4ab7824b9ae6b Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Thu, 5 Jun 2014 21:35:15 +0200
Subject: [PATCH] umount: modernizations
---
src/core/umount.c | 65 ++++++++++++++++++++++-------------------------------
1 file changed, 27 insertions(+), 38 deletions(-)
diff --git src/core/umount.c src/core/umount.c
index d1258f0..a30f674 100644
--- src/core/umount.c
+++ src/core/umount.c
@@ -61,52 +61,46 @@ static void mount_points_list_free(MountPoint **head) {
}
static int mount_points_list_get(MountPoint **head) {
- FILE *proc_self_mountinfo;
- char *path, *p;
+ _cleanup_fclose_ FILE *proc_self_mountinfo = NULL;
unsigned int i;
- int r;
assert(head);
- if (!(proc_self_mountinfo = fopen("/proc/self/mountinfo", "re")))
+ proc_self_mountinfo = fopen("/proc/self/mountinfo", "re");
+ if (!proc_self_mountinfo)
return -errno;
for (i = 1;; i++) {
- int k;
+ _cleanup_free_ char *path = NULL;
+ char *p = NULL;
MountPoint *m;
+ int k;
- path = p = NULL;
-
- if ((k = fscanf(proc_self_mountinfo,
- "%*s " /* (1) mount id */
- "%*s " /* (2) parent id */
- "%*s " /* (3) major:minor */
- "%*s " /* (4) root */
- "%ms " /* (5) mount point */
- "%*s" /* (6) mount options */
- "%*[^-]" /* (7) optional fields */
- "- " /* (8) separator */
- "%*s " /* (9) file system type */
- "%*s" /* (10) mount source */
- "%*s" /* (11) mount options 2 */
- "%*[^\n]", /* some rubbish at the end */
- &path)) != 1) {
+ k = fscanf(proc_self_mountinfo,
+ "%*s " /* (1) mount id */
+ "%*s " /* (2) parent id */
+ "%*s " /* (3) major:minor */
+ "%*s " /* (4) root */
+ "%ms " /* (5) mount point */
+ "%*s" /* (6) mount options */
+ "%*[^-]" /* (7) optional fields */
+ "- " /* (8) separator */
+ "%*s " /* (9) file system type */
+ "%*s" /* (10) mount source */
+ "%*s" /* (11) mount options 2 */
+ "%*[^\n]", /* some rubbish at the end */
+ &path);
+ if (k != 1) {
if (k == EOF)
break;
log_warning("Failed to parse /proc/self/mountinfo:%u.", i);
-
- free(path);
continue;
}
p = cunescape(path);
- free(path);
-
- if (!p) {
- r = -ENOMEM;
- goto finish;
- }
+ if (!p)
+ return -ENOMEM;
/* Ignore mount points we can't unmount because they
* are API or because we are keeping them open (like
@@ -118,22 +112,17 @@ static int mount_points_list_get(MountPoint **head) {
continue;
}
- if (!(m = new0(MountPoint, 1))) {
+ m = new0(MountPoint, 1);
+ if (!m) {
free(p);
- r = -ENOMEM;
- goto finish;
+ return -ENOMEM;
}
m->path = p;
LIST_PREPEND(mount_point, *head, m);
}
- r = 0;
-
-finish:
- fclose(proc_self_mountinfo);
-
- return r;
+ return 0;
}
static int swap_list_get(MountPoint **head) {
--
1.7.9.2