diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-04-06 20:11:41 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-04-07 15:42:25 +0200 |
commit | 527b7a421ff3927d4f3f170b1b143452e88ae1dc (patch) | |
tree | cfb13e123c6dfd547fb005db63a480ca709b46da /src/core/umount.c | |
parent | 64f75d7a2898e0c0d2b66f93ddd34ffd345bb3c5 (diff) |
util: rework cunescape(), improve error handling
Change cunescape() to return a normal error code, so that we can
distuingish OOM errors from parse errors.
This also adds a flags parameter to control whether "relaxed" or normal
parsing shall be done. If set no parse failures are generated, and the
only reason why cunescape() can fail is OOM.
Diffstat (limited to 'src/core/umount.c')
-rw-r--r-- | src/core/umount.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/core/umount.c b/src/core/umount.c index ceee70fbea..bee267a5ad 100644 --- a/src/core/umount.c +++ b/src/core/umount.c @@ -62,6 +62,7 @@ static void mount_points_list_free(MountPoint **head) { static int mount_points_list_get(MountPoint **head) { _cleanup_fclose_ FILE *proc_self_mountinfo = NULL; unsigned int i; + int r; assert(head); @@ -97,9 +98,9 @@ static int mount_points_list_get(MountPoint **head) { continue; } - p = cunescape(path); - if (!p) - return -ENOMEM; + r = cunescape(path, UNESCAPE_RELAX, &p); + if (r < 0) + return r; /* Ignore mount points we can't unmount because they * are API or because we are keeping them open (like @@ -133,10 +134,12 @@ static int mount_points_list_get(MountPoint **head) { static int swap_list_get(MountPoint **head) { _cleanup_fclose_ FILE *proc_swaps = NULL; unsigned int i; + int r; assert(head); - if (!(proc_swaps = fopen("/proc/swaps", "re"))) + proc_swaps = fopen("/proc/swaps", "re"); + if (!proc_swaps) return (errno == ENOENT) ? 0 : -errno; (void) fscanf(proc_swaps, "%*s %*s %*s %*s %*s\n"); @@ -146,19 +149,19 @@ static int swap_list_get(MountPoint **head) { char *dev = NULL, *d; int k; - if ((k = fscanf(proc_swaps, - "%ms " /* device/file */ - "%*s " /* type of swap */ - "%*s " /* swap size */ - "%*s " /* used */ - "%*s\n", /* priority */ - &dev)) != 1) { + k = fscanf(proc_swaps, + "%ms " /* device/file */ + "%*s " /* type of swap */ + "%*s " /* swap size */ + "%*s " /* used */ + "%*s\n", /* priority */ + &dev); + if (k != 1) { if (k == EOF) break; log_warning("Failed to parse /proc/swaps:%u.", i); - free(dev); continue; } @@ -168,14 +171,13 @@ static int swap_list_get(MountPoint **head) { continue; } - d = cunescape(dev); + r = cunescape(dev, UNESCAPE_RELAX, &d); free(dev); + if (r < 0) + return r; - if (!d) { - return -ENOMEM; - } - - if (!(swap = new0(MountPoint, 1))) { + swap = new0(MountPoint, 1); + if (!swap) { free(d); return -ENOMEM; } |