tmpdir: Introduce option for verbose reporting, for diagnosing problems.
authorMark Wooding <mdw@chiark.greenend.org.uk>
Sun, 13 Apr 2008 14:41:53 +0000 (15:41 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 13 Apr 2008 16:31:58 +0000 (17:31 +0100)
This steals the `-v' option, which morphs into `-C', for `check'.

tmpdir.1
tmpdir.c

index c6286d8..71f8544 100644 (file)
--- a/tmpdir.1
+++ b/tmpdir.1
@@ -4,8 +4,8 @@
 tmpdir \- choose, or check a choice of, temporary directory
 .SH SYNOPSIS
 .B tmpdir
-.RB [ \-bc ]
-.RB [ \-v
+.RB [ \-bcv ]
+.RB [ \-C
 .IR dir ]
 .SH USAGE
 The
@@ -71,7 +71,10 @@ examine the user's shell and decide which syntax to use based on that.
 .B "\-c, \-\-cshell"
 Output an assignment using C shell syntax.
 .TP
-.BI "\-v, --verify " dir
+.B "-v, \-\-verbose"
+Report problems to standard error.  Repeat for more verbosity.
+.TP
+.BI "\-C, --check " dir
 Don't try to find a temporary directory; just see whether
 .I dir
 is secure, and exit successfully if it is (and unsuccessfully if it
index 137127a..8e704e6 100644 (file)
--- a/tmpdir.c
+++ b/tmpdir.c
@@ -225,6 +225,13 @@ static char *goodtmp(void)
   return (0);
 }
 
+/* --- @report@ --- */
+
+static void report(unsigned what, int verbose,
+                  const char *p, const char *msg,
+                  void *arg)
+  { moan("%s", msg); }
+
 /* --- @usage@ --- */
 
 static void usage(FILE *fp)
@@ -257,7 +264,8 @@ Options supported:\n\
 \n\
 -b, --bourne           Output a `TMPDIR' setting for Bourne shell users.\n\
 -c, --cshell           Output a `TMPDIR' setting for C shell users.\n\
--v, --verify PATH      Check whether PATH is good, setting exit status.\n\
+-v, --verbose          Report problems to standard error.\n\
+-C, --check PATH       Check whether PATH is good, setting exit status.\n\
 \n\
 The default action is to examine the caller's shell and output a suitable\n\
 setting for that shell type.\n\
@@ -291,9 +299,9 @@ int main(int argc, char *argv[])
 
   ego(argv[0]);
   me = getuid();
-  cp.cp_what = CP_WRWORLD | CP_WRGRP | CP_WROTHUSR | CP_STICKYOK;
+  cp.cp_what = CP_WRWORLD | CP_WRGRP | CP_WROTHUSR | CP_STICKYOK | CP_REPORT;
   cp.cp_verbose = 0;
-  cp.cp_report = 0;
+  cp.cp_report = report;
   checkpath_setids(&cp);
   pw = getpwuid(me);
   if (!pw)
@@ -308,10 +316,12 @@ int main(int argc, char *argv[])
       { "usage",       0,              0,      'u' },
       { "bourne",      0,              0,      'b' },
       { "cshell",      0,              0,      'c' },
-      { "verify",      OPTF_ARGREQ,    0,      'v' },
+      { "check",       OPTF_ARGREQ,    0,      'C' },
+      { "verify",      OPTF_ARGREQ,    0,      'C' },
+      { "verbose",     0,              0,      'v' },
       { 0,             0,              0,      0 }
     };
-    int i = mdwopt(argc, argv, "hVu bcv:", opts, 0, 0, 0);
+    int i = mdwopt(argc, argv, "hVu bcvc:", opts, 0, 0, 0);
 
     if (i < 0)
       break;
@@ -331,9 +341,12 @@ int main(int argc, char *argv[])
       case 'c':
        shell = sh_csh;
        break;
-      case 'v':
+      case 'C':
        return (!fullcheck(optarg));
        break;
+      case 'v':
+       cp.cp_verbose++;
+       break;
       default:
        duff = 1;
        break;