diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-06-05 21:35:15 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-06-05 21:35:23 +0200 |
commit | c3544e8d2c2d870a2aff0944aff4ab7824b9ae6b (patch) | |
tree | 2f1be25627cbdd94cb89e06de61aef2fd347ebce /src/core/umount.c | |
parent | 34b42c9694650d99529f81a0c6416e673c503d18 (diff) |
umount: modernizations
Diffstat (limited to 'src/core/umount.c')
-rw-r--r-- | src/core/umount.c | 65 |
1 files changed, 27 insertions, 38 deletions
diff --git a/src/core/umount.c b/src/core/umount.c index d1258f0f08..a30f6740fa 100644 --- a/src/core/umount.c +++ b/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) { |