From: Mark Wooding Date: Sun, 13 Apr 2008 14:41:53 +0000 (+0100) Subject: tmpdir: Introduce option for verbose reporting, for diagnosing problems. X-Git-Tag: 1.2.0~1^2~1 X-Git-Url: https://git.distorted.org.uk/~mdw/checkpath/commitdiff_plain/3d62246fb045a0674c43e65fd5eea5e5bfa5a42d tmpdir: Introduce option for verbose reporting, for diagnosing problems. This steals the `-v' option, which morphs into `-C', for `check'. --- diff --git a/tmpdir.1 b/tmpdir.1 index c6286d8..71f8544 100644 --- 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 diff --git a/tmpdir.c b/tmpdir.c index 137127a..8e704e6 100644 --- 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;