changeset 1671:05c8de3f64fd

Cleanup mountpoint and remove it from the pending README.
author Rob Landley <rob@landley.net>
date Sun, 25 Jan 2015 13:11:58 -0600
parents 31dded5e0e09
children d7e2523e7109
files toys/other/mountpoint.c toys/pending/README
diffstat 2 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/toys/other/mountpoint.c	Thu Jan 22 16:29:34 2015 -0600
+++ b/toys/other/mountpoint.c	Sun Jan 25 13:11:58 2015 -0600
@@ -19,31 +19,33 @@
 #define FOR_mountpoint
 #include "toys.h"
 
+static void die(char *gripe)
+{
+  if (!(toys.optflags & FLAG_q)) printf("%s: not a %s\n", *toys.optargs, gripe);
+
+  toys.exitval++;
+  xexit();
+}
+
 void mountpoint_main(void)
 {
   struct stat st1, st2;
   char *arg = *toys.optargs;
   int quiet = toys.optflags & FLAG_q;
 
-  toys.exitval = 1;
-  if (((toys.optflags & FLAG_x) ? lstat : stat)(arg, &st1))
-    perror_exit("%s", arg);
+  if (lstat(arg, &st1)) perror_exit("%s", arg);
 
   if (toys.optflags & FLAG_x) {
     if (S_ISBLK(st1.st_mode)) {
       if (!quiet) printf("%u:%u\n", major(st1.st_rdev), minor(st1.st_rdev));
-      toys.exitval = 0;
+
       return;
     }
-    if (!quiet) printf("%s: not a block device\n", arg);
-    return;
+    die("block device");
   }
 
-  // Ignore the fact a file can be a mountpoint for --bind mounts.
-  if (!S_ISDIR(st1.st_mode)) {
-    if (!quiet) printf("%s: not a directory\n", arg);
-    return;
-  }
+  // TODO: Ignore the fact a file can be a mountpoint for --bind mounts.
+  if (!S_ISDIR(st1.st_mode)) die("directory");
 
   arg = xmprintf("%s/..", arg);
   xstat(arg, &st2);
--- a/toys/pending/README	Thu Jan 22 16:29:34 2015 -0600
+++ b/toys/pending/README	Sun Jan 25 13:11:58 2015 -0600
@@ -12,7 +12,6 @@
 The following commands predate the pending directory, and are awaiting
 cleanup but don't live here:
 
-  vmstat, login, du, vconfig, mountpoint, chroot, cut, touch,
-  modinfo, expand, xargs
+  vmstat, login, du, vconfig, chroot, cut, touch, modinfo, expand, xargs
 
   lib/password.c