1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-15 05:57:26 +03:00

umount: modernizations

This commit is contained in:
Lennart Poettering 2014-06-05 21:35:15 +02:00
parent 34b42c9694
commit c3544e8d2c

View File

@ -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) {