Date: Thu, 10 Jun 1999 23:40:12 +0200 From: Sheldon Hearn <sheldonh@uunet.co.za> To: Tim Vanderhoek <vanderh@ecf.utoronto.ca> Cc: "Ronald F. Guilmette" <rfg@monkeys.com>, freebsd-bugs@FreeBSD.ORG Subject: Re: bin/11987: vacation(1) documentation and error logging both suck Message-ID: <81562.929050812@axl.noc.iafrica.com> In-Reply-To: Your message of "Thu, 10 Jun 1999 16:32:01 -0400." <19990610163201.A1147@mad>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 10 Jun 1999 16:32:01 -0400, Tim Vanderhoek wrote: > Anyways, I'll reopen the PR and assign it to myself in a moment. I > can't promise you that I'll get to it anytime soon... [...] > Sheldon, since your the PR-guy of the moment... Suggestions? :-) Yeah, give this untested patch a try. It ought to be backward compatible with our existing vacation. See the manpage for details. Now since you reopened the PR and assigned it to yourself, I _do_ expect feedback, y'hear? And you too, Mr Guilmette. Especially after that impressive argument on vacation being the only end-user toy to report errors to syslog(3). Now _that_ made it sound special enough to work on. ;-) Ciao, Sheldon. Index: usr.bin/vacation/vacation.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/vacation/vacation.1,v retrieving revision 1.6 diff -u -d -r1.6 vacation.1 --- vacation.1 1997/02/22 19:57:38 1.6 +++ vacation.1 1999/06/10 21:29:26 @@ -40,11 +40,14 @@ .Nd return ``I am not here'' indication .Sh SYNOPSIS .Nm vacation +.Op Fl d .Fl i .Op Fl r Ar interval .Nm vacation +.Op Fl d .Fl l .Nm vacation +.Op Fl d .Op Fl a Ar alias .Ar login .Sh DESCRIPTION @@ -71,6 +74,11 @@ .Ar alias in the same manner as those received for the user's login name. +.It Fl d +Enable debugging mode. If possible, errors are logged to the file +.Pa .vacation.log +in the user's home directory. Some errors (such as invocation errors) +will be written to the standard output. .It Fl i Initialize the vacation database files. It should be used before you modify your @@ -155,16 +163,24 @@ .Dq From line automatically. .Pp -Fatal errors, such as calling +If the +.Fl d +option is not specified, fatal errors, such as calling .Nm vacation with incorrect arguments, or with non-existent .Ar login Ns Ar s , are logged in the system log file, using .Xr syslog 3 . +.Sh DIAGNOSTICS +The +.Nm +utility exits 0 on success, and >0 if an error occurs. .Sh FILES .Bl -tag -width "vacation.dirxxx" -compact .It Pa ~/.vacation.db database file +.It Pa ~/.vacation.log +debugging log .It Pa ~/.vacation.msg message to send .El Index: usr.bin/vacation/vacation.c =================================================================== RCS file: /home/ncvs/src/usr.bin/vacation/vacation.c,v retrieving revision 1.13 diff -u -d -r1.13 vacation.c --- vacation.c 1998/10/13 14:52:32 1.13 +++ vacation.c 1999/06/10 21:38:25 @@ -62,6 +62,7 @@ #include <unistd.h> #include <stdio.h> #include <ctype.h> +#include <stdarg.h> #include <stdlib.h> #include <string.h> #include <paths.h> @@ -78,6 +79,7 @@ #define MAXLINE 1024 /* max line from mail header */ #define VDB ".vacation.db" /* dbm's database */ #define VMSG ".vacation.msg" /* vacation message */ +#define LOGFILE ".vacation.log" /* debugging logfile */ typedef struct alias { struct alias *next; @@ -88,6 +90,8 @@ DB *db; char from[MAXLINE]; +FILE *logfp = NULL; +void (*msglog)(int, const char *, ...) = &syslog; static int isdelim __P((int)); static int junkmail __P((void)); @@ -99,6 +103,7 @@ static void setinterval __P((time_t)); static void setreply __P((void)); static void usage __P((void)); +static void flog __P((int, const char *, ...)); int main(argc, argv) @@ -114,7 +119,7 @@ opterr = iflag = lflag = 0; interval = -1; - while ((ch = getopt(argc, argv, "a:Iilr:")) != -1) + while ((ch = getopt(argc, argv, "a:dIilr:")) != -1) switch((char)ch) { case 'a': /* alias */ if (!(cur = (ALIAS *)malloc((u_int)sizeof(ALIAS)))) @@ -123,6 +128,9 @@ cur->next = names; names = cur; break; + case 'd': /* debug mode */ + msglog = &flog; + break; case 'I': /* backward compatible */ case 'i': /* init the database */ iflag = 1; @@ -150,25 +158,28 @@ if (!iflag && !lflag) usage(); if (!(pw = getpwuid(getuid()))) { - syslog(LOG_ERR, + msglog(LOG_ERR, "vacation: no such user uid %u.\n", getuid()); exit(1); } } else if (!(pw = getpwnam(*argv))) { - syslog(LOG_ERR, "vacation: no such user %s.\n", *argv); + msglog(LOG_ERR, "vacation: no such user %s.\n", *argv); exit(1); } if (chdir(pw->pw_dir)) { - syslog(LOG_NOTICE, + msglog(LOG_NOTICE, "vacation: no such directory %s.\n", pw->pw_dir); exit(1); } + if (msglog == &flog && !(logfp = fopen(LOGFILE, "a+"))) + printf("vacation: %s: %s\n", LOGFILE, strerror(errno)); + db = dbopen(VDB, O_CREAT|O_RDWR | (iflag ? O_TRUNC : 0), S_IRUSR|S_IWUSR, DB_HASH, NULL); if (!db) { - syslog(LOG_NOTICE, "vacation: %s: %s\n", VDB, strerror(errno)); + msglog(LOG_NOTICE, "vacation: %s: %s\n", VDB, strerror(errno)); exit(1); } @@ -263,7 +274,7 @@ if (!tome) exit(0); if (!*from) { - syslog(LOG_NOTICE, "vacation: no initial \"From\" line.\n"); + msglog(LOG_NOTICE, "vacation: no initial \"From\" line.\n"); exit(1); } } @@ -410,16 +421,16 @@ mfp = fopen(VMSG, "r"); if (mfp == NULL) { - syslog(LOG_NOTICE, "vacation: no ~%s/%s file.\n", myname, VMSG); + msglog(LOG_NOTICE, "vacation: no ~%s/%s file.\n", myname, VMSG); exit(1); } if (pipe(pvect) < 0) { - syslog(LOG_ERR, "vacation: pipe: %s", strerror(errno)); + msglog(LOG_ERR, "vacation: pipe: %s", strerror(errno)); exit(1); } i = fork(); if (i < 0) { - syslog(LOG_ERR, "vacation: fork: %s", strerror(errno)); + msglog(LOG_ERR, "vacation: fork: %s", strerror(errno)); exit(1); } if (i == 0) { @@ -428,7 +439,7 @@ close(pvect[1]); close(fileno(mfp)); execl(_PATH_SENDMAIL, "sendmail", "-f", myname, "--", from, NULL); - syslog(LOG_ERR, "vacation: can't exec %s: %s", + msglog(LOG_ERR, "vacation: can't exec %s: %s", _PATH_SENDMAIL, strerror(errno)); _exit(1); } @@ -444,7 +455,7 @@ static void usage() { - syslog(LOG_NOTICE, "uid %u: usage: vacation [-i [-rinterval]] [-l] [-a alias] login\n", + msglog(LOG_NOTICE, "uid %u: usage: vacation [-d] [-i [-rinterval]] [-l] [-a alias] login\n", getuid()); exit(1); } @@ -485,4 +496,22 @@ if (c == '_' || c == '-' || c == '.') return(0); return(1); +} + +/* + * Append a message to a logfile in the user's home directory for ease + * of debugging. + */ +static void +flog(int i, const char *fmt, ...) +{ + va_list ap; + + i = 0; /* Printing syslog priority not implemented */ + va_start(ap, fmt); + if (logfp) + fprintf(logfp, fmt, ap); + else + vfprintf(stderr, fmt, ap); + va_end(ap); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?81562.929050812>