diff options
author | Dave Reisner | 2011-10-11 01:14:15 +0200 |
---|---|---|
committer | Karel Zak | 2011-10-11 11:03:45 +0200 |
commit | b16b56ec55507b6b83e0d35e3cefeb16367f3363 (patch) | |
tree | b73d0802c5a4b77057aca78aef11ec166047870b | |
parent | mountpoint: fallback on stat when /proc isn't mounted (diff) | |
download | kernel-qcow2-util-linux-b16b56ec55507b6b83e0d35e3cefeb16367f3363.tar.gz kernel-qcow2-util-linux-b16b56ec55507b6b83e0d35e3cefeb16367f3363.tar.xz kernel-qcow2-util-linux-b16b56ec55507b6b83e0d35e3cefeb16367f3363.zip |
mountpoint: refactor exit path
There's only one condition for which we declare success, but many for
failure. Initialize rc as failure and set to success on this single
condition. In all cases, jump to a label to exit instead of exiting
immediately. This will be used later on to ease cleanup of any heap
allocations.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | sys-utils/mountpoint.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/sys-utils/mountpoint.c b/sys-utils/mountpoint.c index 1182f7c3b..16c7c2271 100644 --- a/sys-utils/mountpoint.c +++ b/sys-utils/mountpoint.c @@ -116,7 +116,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) int main(int argc, char **argv) { - int c, fs_devno = 0, dev_devno = 0, rc = 0; + int c, fs_devno = 0, dev_devno = 0, rc = EXIT_FAILURE; char *spec; struct stat st; @@ -162,30 +162,36 @@ int main(int argc, char **argv) if (stat(spec, &st)) { if (!quiet) - err(EXIT_FAILURE, "%s", spec); - return EXIT_FAILURE; + warn("%s", spec); + goto finish; } - if (dev_devno) - rc = print_devno(spec, &st); - else { + + if (dev_devno) { + if (print_devno(spec, &st) == 0) + rc = EXIT_SUCCESS; + } else { dev_t src; if (!S_ISDIR(st.st_mode)) { if (!quiet) - errx(EXIT_FAILURE, _("%s: not a directory"), spec); - return EXIT_FAILURE; + warnx(_("%s: not a directory"), spec); + goto finish; } src = dir_to_device(spec); if (!src) { if (!quiet) printf(_("%s is not a mountpoint\n"), spec); - return EXIT_FAILURE; + goto finish; } + + rc = EXIT_SUCCESS; + if (fs_devno) printf("%u:%u\n", major(src), minor(src)); else if (!quiet) printf(_("%s is a mountpoint\n"), spec); } - return rc ? EXIT_FAILURE : EXIT_SUCCESS; +finish: + return rc; } |