version #2; -f flag, remove home_dir, redist per folder
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sun, 12 Apr 1987 06:38:46 +0000 (22:38 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sun, 12 Apr 1987 06:38:46 +0000 (22:38 -0800)
SCCS-vsn: libexec/bugfiler/Makefile 5.8
SCCS-vsn: libexec/bugfiler/bugfiler.c 5.7
SCCS-vsn: libexec/bugfiler/error.c 5.2
SCCS-vsn: libexec/bugfiler/gethead.c 5.2
SCCS-vsn: libexec/bugfiler/process.c 5.3
SCCS-vsn: libexec/bugfiler/redist.c 5.2
SCCS-vsn: libexec/bugfiler/reply.c 5.2

usr/src/libexec/bugfiler/Makefile
usr/src/libexec/bugfiler/bugfiler.c
usr/src/libexec/bugfiler/error.c
usr/src/libexec/bugfiler/gethead.c
usr/src/libexec/bugfiler/process.c
usr/src/libexec/bugfiler/redist.c
usr/src/libexec/bugfiler/reply.c

index 9ed5eb7..c176d28 100644 (file)
@@ -3,13 +3,14 @@
 # All rights reserved.  The Berkeley software License Agreement
 # specifies the terms and conditions for redistribution.
 #
 # All rights reserved.  The Berkeley software License Agreement
 # specifies the terms and conditions for redistribution.
 #
-#      @(#)Makefile    5.7 (Berkeley) %G%
+#      @(#)Makefile    5.8 (Berkeley) %G%
 #
 # Bug report processor and associated programs
 #
 
 CFLAGS = -O -I.
 DESTDIR=
 #
 # Bug report processor and associated programs
 #
 
 CFLAGS = -O -I.
 DESTDIR=
+SRCS=  bugfiler.c error.c gethead.c process.c redist.c reply.c
 OBJS=  bugfiler.o error.o gethead.o process.o redist.o reply.o
 
 all: bugfiler
 OBJS=  bugfiler.o error.o gethead.o process.o redist.o reply.o
 
 all: bugfiler
@@ -25,4 +26,10 @@ install: bugfiler sendbug.sh bugformat
 clean:
        rm -f ${OBJS} core bugfiler
 
 clean:
        rm -f ${OBJS} core bugfiler
 
+tags:
+       ctags ${SRCS}
+
+lint:
+       lint ${CFLAGS} -chapbx ${SRCS}
+
 ${OBJS}: bug.h
 ${OBJS}: bug.h
index 0c215b7..158b852 100644 (file)
@@ -11,7 +11,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)bugfiler.c 5.6 (Berkeley) 86/11/25";
+static char sccsid[] = "@(#)bugfiler.c 5.7 (Berkeley) 87/04/11";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -20,96 +20,93 @@ static char sccsid[] = "@(#)bugfiler.c      5.6 (Berkeley) 86/11/25";
  */
 #include <bug.h>
 #include <sys/time.h>
  */
 #include <bug.h>
 #include <sys/time.h>
-#include <stdio.h>
+#include <sys/file.h>
 #include <pwd.h>
 #include <pwd.h>
+#include <stdio.h>
 
 
-extern char    *optarg;                /* getopt arguments */
-extern int     optind;
-
-int    lfd;                            /* lock file descriptor */
-short  do_redist = YES;                /* redistribut BR */
 char   bfr[MAXBSIZE],                  /* general I/O buffer */
        tmpname[sizeof(TMP_BUG) + 5];   /* temp bug file */
 
 char   bfr[MAXBSIZE],                  /* general I/O buffer */
        tmpname[sizeof(TMP_BUG) + 5];   /* temp bug file */
 
-main(argc,argv)
-int    argc;
-char   **argv;
+main(argc, argv)
+       int     argc;
+       char    **argv;
 {
 {
+       extern char     *optarg;        /* getopt arguments */
        register struct passwd  *pwd;   /* bugs password entry */
        register int    ch;             /* getopts char */
        register struct passwd  *pwd;   /* bugs password entry */
        register int    ch;             /* getopts char */
-       register short  do_ack = YES;   /* acknowledge bug report */
+       int     do_ack,                 /* acknowledge bug report */
+               do_redist;              /* redistribut BR */
+       char    *argfolder,             /* folder name provided */
+               *strcpy();
        struct passwd   *getpwnam();
 
        struct passwd   *getpwnam();
 
-       while ((ch = getopt(argc,argv,"ar")) != EOF)
+       do_ack = do_redist = YES;
+       argfolder = NULL;
+       while ((ch = getopt(argc, argv, "af:r")) != EOF)
                switch((char)ch) {
                switch((char)ch) {
-                       case 'a':
-                               do_ack = NO;
-                               break;
-                       case 'r':
-                               do_redist = NO;
-                               break;
-                       case '?':
-                       default:
-                               error("usage: bugfiler [-ar] [maildir]",CHN);
+               case 'a':
+                       do_ack = NO;
+                       break;
+               case 'f':
+                       argfolder = optarg;
+                       break;
+               case 'r':
+                       do_redist = NO;
+                       break;
+               case '?':
+               default:
+                       error("usage: bugfiler [-ar] [-f folder]", CHN);
                }
 
        if (!(pwd = getpwnam(BUGS_ID)))
                }
 
        if (!(pwd = getpwnam(BUGS_ID)))
-               error("bugs person %s is unknown",BUGS_ID);
+               error("can't find bugs login.", BUGS_ID);
 
 
-       argv += optind;
-       if (*argv) {            /* change to argument directory */
-               if (chdir(*argv))
-                       error("can't move to %s.",*argv);
-       }                       /* change to bugs home directory */
-       else if (chdir(pwd->pw_dir))
-               error("can't move to %s.",pwd->pw_dir);
+       if (chdir(pwd->pw_dir))         /* change to bugs home directory */
+               error("can't chdir to %s.", pwd->pw_dir);
 
 
-       if (setreuid(0,pwd->pw_uid))
-               error("can't set id to %s.",BUGS_ID);
+       if (setreuid(0, pwd->pw_uid))
+               error("can't set id to %s.", BUGS_ID);
 
 
-       umask(2);               /* everything is 664 */
-       seterr();
-       logit();
-       make_copy();
+       (void)umask(2);                 /* everything is 664 */
+       seterr();                       /* redirect to log file */
+       logit();                        /* log report arrival */
+       make_copy();                    /* save copy in case */
+       gethead(do_redist);
 
 
-       if (access(LOCK_FILE,R_OK) || (lfd = open(LOCK_FILE,O_RDONLY,0)) < 0)
-               error("can't read lock file %s.",LOCK_FILE);
+       if (argfolder)                  /* specific folder requested */
+               (void)strcpy(dir, argfolder);
 
 
-       gethead();
        process();
 
        process();
 
-       if (setuid(0,0))
-               error("can't set id to root.",CHN);
-
+       if (setuid(0, 0))
+               error("can't set id to root.", CHN);
        if (do_ack)
                reply();
        if (do_redist)
                redist();
        if (do_ack)
                reply();
        if (do_redist)
                redist();
-
-       unlink(tmpname);
+       (void)unlink(tmpname);
        exit(OK);
 }
 
 /*
  * make_copy --
        exit(OK);
 }
 
 /*
  * make_copy --
- *     make a copy of the bug report
+ *     make a copy of bug report in error folder
  */
 static
 make_copy()
 {
        register int    cnt,                    /* read return value */
                        tfd;                    /* temp file descriptor */
  */
 static
 make_copy()
 {
        register int    cnt,                    /* read return value */
                        tfd;                    /* temp file descriptor */
-       char    *mktemp(), *strcpy();
-
-       /* use O_EXCL, since may not be able to get a lock file */
-       for (cnt = 0;cnt < 20;++cnt)
-               if ((tfd = open(mktemp(strcpy(tmpname,TMP_BUG)),O_WRONLY | O_CREAT | O_EXCL,0664)) >= 0) {
-                       while ((cnt = read(fileno(stdin),bfr,sizeof(bfr))) != ERR && cnt)
-                               write(tfd,bfr,cnt);
-                       close(tfd);
-                       return;
-               }
-       error("unable to make copy using %s.\n",tmpname);
+       char    *strcpy();
+
+       (void)strcpy(tmpname, TMP_BUG);
+       if (tfd = mkstemp(tmpname)) {
+               while ((cnt = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && cnt)
+                       write(tfd, bfr, cnt);
+               (void)close(tfd);
+               return;
+       }
+       error("can't make copy using %s.\n", tmpname);
 }
 
 /*
 }
 
 /*
@@ -120,10 +117,9 @@ static
 logit()
 {
        struct timeval  tp;
 logit()
 {
        struct timeval  tp;
-       struct timezone tzp;
        char    *ctime();
 
        char    *ctime();
 
-       if (gettimeofday(&tp,&tzp))
-               error("unable to get time of day.",CHN);
-       fprintf(stderr,"\n>>> BUGFILER <<<\n\t%s",ctime(&tp.tv_sec));
+       if (gettimeofday(&tp, (struct timezone *)NULL))
+               error("can't get time of day.", CHN);
+       fprintf(stderr, "\n>>> BUGFILER <<<\n\t%s", ctime(&tp.tv_sec));
 }
 }
index 69f6095..ac61d3c 100644 (file)
@@ -8,14 +8,9 @@
 static char sccsid[] = "@(#)error.c    5.1 (Berkeley) 86/11/25";
 #endif not lint
 
 static char sccsid[] = "@(#)error.c    5.1 (Berkeley) 86/11/25";
 #endif not lint
 
+#include <bug.h>
 #include <syslog.h>
 #include <stdio.h>
 #include <syslog.h>
 #include <stdio.h>
-#include <bug.h>
-
-extern char    *distf,                         /* redist temp file */
-               tmpname[];                      /* temporary file used */
-
-short  made_dist;                              /* if dist file made */
 
 static short   err_redir;                      /* stderr redirected */
 
 
 static short   err_redir;                      /* stderr redirected */
 
@@ -25,8 +20,8 @@ static short  err_redir;                      /* stderr redirected */
  */
 seterr()
 {
  */
 seterr()
 {
-       if (!freopen(ERROR_FILE,"a",stderr))
-               error("unable to open error file %s.\n",ERROR_FILE);
+       if (!freopen(ERROR_FILE, "a", stderr))
+               error("can't open error file %s.\n", ERROR_FILE);
        err_redir = YES;
 }
 
        err_redir = YES;
 }
 
@@ -34,28 +29,26 @@ seterr()
  * error --
  *     write errors to log file and die
  */
  * error --
  *     write errors to log file and die
  */
-error(fmt,arg)
-register char  *fmt,
-               *arg;
+error(fmt, arg)
+       register char   *fmt,
+                       *arg;
 {
        static char     logmsg[MAXLINELEN];     /* syslog message */
        char    *strcpy(), *strcat();
 
        if (err_redir) {
                /* don't combine these, "fmt" may not require "arg" */
 {
        static char     logmsg[MAXLINELEN];     /* syslog message */
        char    *strcpy(), *strcat();
 
        if (err_redir) {
                /* don't combine these, "fmt" may not require "arg" */
-               fputc('\t',stderr);
-               fprintf(stderr,fmt,arg);
-               fprintf(stderr,"\n\ttemporary file is %s.\n",tmpname);
+               fputc('\t', stderr);
+               fprintf(stderr, fmt, arg);
+               fprintf(stderr, "\n\ttemporary file is %s.\n", tmpname);
        }
        else {
        }
        else {
-               strcat(strcpy(logmsg,"bugfiler: "),fmt);
-               syslog(LOG_ERR,logmsg,arg);
+               sprintf(logmsg, "bugfiler: %s", fmt);
+               syslog(LOG_ERR, logmsg, arg);
        }
        }
-       if (made_dist)          /* unlink redist file if necessary */
-               unlink(distf);
 #ifdef METOO
        exit(ERR);
 #ifdef METOO
        exit(ERR);
-#else !METOO
+#else
        exit(OK);
        exit(OK);
-#endif METOO
+#endif
 }
 }
index 3b92581..cef12a0 100644 (file)
@@ -5,12 +5,11 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)gethead.c  5.1 (Berkeley) 86/11/25";
+static char sccsid[] = "@(#)gethead.c  5.2 (Berkeley) 87/04/11";
 #endif not lint
 
 #include <bug.h>
 #include <sys/stat.h>
 #endif not lint
 
 #include <bug.h>
 #include <sys/stat.h>
-#include <sys/dir.h>
 #include <stdio.h>
 
 static int     chk1();
 #include <stdio.h>
 
 static int     chk1();
@@ -29,50 +28,51 @@ HEADER      mailhead[] = {                          /* mail headers */
        { ERR, }
 };
 
        { ERR, }
 };
 
-extern short   do_redist,              /* if redistributing report */
-               made_dist;              /* if dist file needs removing */
-extern char    tmpname[];              /* temp bug report file */
-
-char   *distf = TMP_FILE,              /* redist temp file */
-       dir[MAXNAMLEN],                 /* subject and folder */
+FILE   *dfp;                           /* distf file pointer */
+char   dir[MAXNAMLEN],                 /* subject and folder */
        folder[MAXNAMLEN];
 
 /*
  * gethead --
  *     read mail and bug headers from bug report, construct redist headers
  */
        folder[MAXNAMLEN];
 
 /*
  * gethead --
  *     read mail and bug headers from bug report, construct redist headers
  */
-gethead()
+gethead(redist)
+       int     redist;
 {
        register HEADER *hp;            /* mail header pointer */
 {
        register HEADER *hp;            /* mail header pointer */
-       register FILE   *dfp;           /* distf file pointer */
-       char    *strcpy(), *malloc(), *mktemp();
+       char    *strcpy(), *malloc();
+
+       if (redist) {
+               int     fd;
+               char    *distf;
 
 
-       if (do_redist && (!mktemp(distf) || !(dfp = fopen(distf,"w"))))
-               error("unable to create redistribution file %s.",distf);
-       made_dist = YES;
-       if (!freopen(tmpname,"r",stdin))
-               error("unable to read temporary bug file %s.",tmpname);
+               distf = "/tmp/BUG_XXXXXX";
+               if (!(fd = mkstemp(distf)) || !(dfp = fdopen(fd, "w+")))
+                       error("can't create redistribution file %s.", distf);
+               /* disappear after last reference is closed */
+               (void)unlink(distf);
+       }
+       if (!freopen(tmpname, "r", stdin))
+               error("can't read temporary bug file %s.", tmpname);
 
 
-       while (fgets(bfr,sizeof(bfr),stdin)) {
-               for (hp = mailhead;hp->found != ERR;++hp)
+       while (fgets(bfr, sizeof(bfr), stdin)) {
+               for (hp = mailhead; hp->found != ERR; ++hp)
                        if (!hp->found)
                        if (!hp->found)
-                               if (!strncmp(hp->tag,bfr,hp->len)) {
+                               if (!strncmp(hp->tag, bfr, hp->len)) {
                                        if (hp->valid && !((*(hp->valid))(bfr)))
                                                break;
                                        if (!(hp->line = malloc((u_int)(strlen(bfr) + 1))))
                                        if (hp->valid && !((*(hp->valid))(bfr)))
                                                break;
                                        if (!(hp->line = malloc((u_int)(strlen(bfr) + 1))))
-                                               error("unable to allocate space for header search.",CHN);
-                                       strcpy(hp->line,bfr);
+                                               error("malloc failed.", CHN);
+                                       (void)strcpy(hp->line, bfr);
                                        hp->found = YES;
                                        break;
                                }
                                        hp->found = YES;
                                        break;
                                }
-               if ((hp->found == ERR || hp->redist) && do_redist)
-                       fputs(bfr,dfp);
+               if ((hp->found == ERR || hp->redist) && redist)
+                       fputs(bfr, dfp);
        }
 
        if (!mailhead[INDX_TAG].found)
        }
 
        if (!mailhead[INDX_TAG].found)
-               error("no readable \"Index:\" header in bug report.",CHN);
-       if (do_redist)
-               fclose(dfp);
+               error("no readable \"Index:\" header in bug report.", CHN);
 }
 
 /*
 }
 
 /*
@@ -81,23 +81,20 @@ gethead()
  */
 static
 chk1(line)
  */
 static
 chk1(line)
-char   *line;
+       char    *line;
 {
        register char   *C;             /* tmp pointer */
        struct stat     sbuf;           /* existence check */
        char    *index();
 
 {
        register char   *C;             /* tmp pointer */
        struct stat     sbuf;           /* existence check */
        char    *index();
 
-       if (sscanf(line," Index: %s %s ",folder,dir) != 2)
+       if (sscanf(line, " Index: %s %s ", folder, dir) != 2)
                return(NO);
                return(NO);
-
-       /* backward compatible, deal with "bin/from.c" */
-       if (C = index(folder,'/')) {
+       if (C = index(folder, '/')) {   /* deal with "bin/from.c" */
                if (C == folder)
                        return(NO);
                *C = EOS;
        }
                if (C == folder)
                        return(NO);
                *C = EOS;
        }
-
-       if (stat(dir,&sbuf) || (sbuf.st_mode & S_IFMT) != S_IFDIR)
+       if (stat(dir, &sbuf) || (sbuf.st_mode & S_IFMT) != S_IFDIR)
                return(NO);
        return(YES);
 }
                return(NO);
        return(YES);
 }
index 8a60051..73fc9b7 100644 (file)
@@ -5,55 +5,51 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)process.c  5.2 (Berkeley) 87/01/28";
+static char sccsid[] = "@(#)process.c  5.3 (Berkeley) 87/04/11";
 #endif not lint
 
 #include <bug.h>
 #include <sys/file.h>
 #endif not lint
 
 #include <bug.h>
 #include <sys/file.h>
-#include <sys/dir.h>
 #include <sys/time.h>
 #include <stdio.h>
 #include <sys/time.h>
 #include <stdio.h>
-
-extern HEADER  mailhead[];                     /* mail headers */
-extern int     lfd;                            /* lock file descriptor */
-extern char    dir[],                          /* directory */
-               folder[];                       /* sub-directory */
+#include <ctype.h>
 
 char   pfile[MAXPATHLEN];                      /* permanent file name */
 
 /*
  * process --
 
 char   pfile[MAXPATHLEN];                      /* permanent file name */
 
 /*
  * process --
- *     process a bug report
+ *     copy report to permanent file,
+ *     update summary file.
  */
 process()
 {
        register int    rval;                   /* read return value */
        struct timeval  tp;                     /* time of day */
  */
 process()
 {
        register int    rval;                   /* read return value */
        struct timeval  tp;                     /* time of day */
-       struct timezone tzp;
+       int     lfd;                            /* lock file descriptor */
        char    *ctime();
 
        char    *ctime();
 
-       /* copy report to permanent file */
-       sprintf(pfile,"%s/%s/%d",dir,folder,getnext());
-       fprintf(stderr,"\t%s\n",pfile);
-       if (!(freopen(pfile,"w",stdout)))
-               error("unable to create permanent bug file %s.",pfile);
+       if (access(LOCK_FILE, R_OK) || (lfd = open(LOCK_FILE, O_RDONLY, 0)) < 0)
+               error("can't find lock file %s.", LOCK_FILE);
+       if (flock(lfd, LOCK_EX))
+               error("can't get lock.", CHN);
+       sprintf(pfile, "%s/%s/%d", dir, folder, getnext());
+       fprintf(stderr, "\t%s\n", pfile);
+       if (!(freopen(pfile, "w", stdout)))
+               error("can't create %s.", pfile);
        rewind(stdin);
        rewind(stdin);
-       while ((rval = read(fileno(stdin),bfr,sizeof(bfr))) != ERR && rval)
-               write(fileno(stdout),bfr,rval);
-       REL_LOCK;
+       while ((rval = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && rval)
+               if (write(fileno(stdout), bfr, rval) != rval)
+                       error("write to %s failed.", pfile);
 
        /* append information to the summary file */
 
        /* append information to the summary file */
-       sprintf(bfr,"%s/%s",dir,SUMMARY_FILE);
-       GET_LOCK;
-       if (!(freopen(bfr,"a",stdout)))
-               error("unable to append to summary file %s.",bfr);
-       else {
-               if (gettimeofday(&tp,&tzp))
-                       error("unable to get time of day.",CHN);
-               printf("\n%s\t\t%s\t%s\t%s\tOwner: Bugs Bunny\n\tComment: Received\n",pfile,ctime(&tp.tv_sec),mailhead[INDX_TAG].line,mailhead[SUBJ_TAG].found ? mailhead[SUBJ_TAG].line : "Subject:\n");
-       }
-       REL_LOCK;
-       fclose(stdout);
+       sprintf(bfr, "%s/%s", dir, SUMMARY_FILE);
+       if (!(freopen(bfr, "a", stdout)))
+               error("can't append to summary file %s.", bfr);
+       if (gettimeofday(&tp, (struct timezone *)NULL))
+               error("can't get time of day.", CHN);
+       printf("\n%s\t\t%s\t%s\t%s\tOwner: Bugs Bunny\n\tComment: Received\n", pfile, ctime(&tp.tv_sec), mailhead[INDX_TAG].line, mailhead[SUBJ_TAG].found ? mailhead[SUBJ_TAG].line : "Subject:\n");
+       (void)flock(lfd, LOCK_UN);
+       (void)fclose(stdout);
 }
 
 /*
 }
 
 /*
@@ -65,16 +61,22 @@ getnext()
 {
        register struct direct  *d;             /* directory structure */
        register DIR    *dirp;                  /* directory pointer */
 {
        register struct direct  *d;             /* directory structure */
        register DIR    *dirp;                  /* directory pointer */
-       register int    n;                      /* number values */
+       register int    highval,
+                       newval;
+       register char   *C;
 
 
-       GET_LOCK;
-       sprintf(bfr,"%s/%s",dir,folder);
-       if (!(dirp = opendir(bfr))) {
-               REL_LOCK;
-               error("unable to read folder directory %s.",bfr);
-       }
-       for (n = 0;d = readdir(dirp);)
-               n = MAX(n,atoi(d->d_name));
+       sprintf(bfr, "%s/%s", dir, folder);
+       if (!(dirp = opendir(bfr)))
+               error("can't read folder directory %s.", bfr);
+       for (highval = 0;d = readdir(dirp);)
+               for (C = d->d_name;;++C)
+                       if (!*C) {
+                               if ((newval = atoi(d->d_name)) > highval)
+                                       highval = newval;
+                               break;
+                       }
+                       else if (!isdigit(*C))
+                               break;
        closedir(dirp);
        closedir(dirp);
-       return(++n);
+       return(++highval);
 }
 }
index 45f8f8e..1dc49c4 100644 (file)
@@ -5,18 +5,13 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)redist.c   5.1 (Berkeley) 86/11/25";
+static char sccsid[] = "@(#)redist.c   5.2 (Berkeley) 87/04/11";
 #endif not lint
 
 #include <sys/file.h>
 #include <stdio.h>
 #include <bug.h>
 
 #endif not lint
 
 #include <sys/file.h>
 #include <stdio.h>
 #include <bug.h>
 
-extern HEADER  mailhead[];                     /* mail headers */
-extern char    *distf,                         /* redist temp file */
-               pfile[],                        /* permanent bug file */
-               folder[];                       /* system name */
-
 /*
  * redist --
  *     Redistribute a bug report to those people indicated in the
 /*
  * redist --
  *     Redistribute a bug report to those people indicated in the
@@ -24,64 +19,63 @@ extern char *distf,                         /* redist temp file */
  */
 redist()
 {
  */
 redist()
 {
-       register char   *C1,            /* traveling chars */
+       extern FILE     *dfp;           /* dist file fp */
+       extern char     pfile[];        /* permanent bug file */
+       register char   *C1,
                        *C2;
                        *C2;
-       register int    first = YES;    /* if first blank line */
-       FILE    *pf,                    /* pipe pointer */
-               *dfp,                   /* dist file fp */
+       register int    first;          /* if first blank line */
+       FILE    *pf,
                *popen();
                *popen();
-       char    *index(), *mktemp();
+       char    *index();
 
 
-       if (!freopen(DIST_FILE,"r",stdin))
+       sprintf(bfr, "%s/%s", dir, DIST_FILE);
+       if (!freopen(bfr, "r", stdin))
                return;
                return;
-
        for (;;) {                      /* get first part of entry */
                if (!gets(bfr))
                        return;
        for (;;) {                      /* get first part of entry */
                if (!gets(bfr))
                        return;
-               if (*bfr == COMMENT || *bfr == ' ' || *bfr == '\t' || !(C1 = index(bfr,':')))
+               if (*bfr == COMMENT || *bfr == ' ' || *bfr == '\t' || !(C1 = index(bfr, ':')))
                        continue;
                *C1 = EOS;
                        continue;
                *C1 = EOS;
-               if (!strcmp(bfr,folder))
+               if (!strcmp(bfr, folder))
                        break;
        }
        for (++C1;*C1 && (*C1 == ' ' || *C1 == '\t');++C1);
        if (!*C1)                       /* if empty */
                return;
 
                        break;
        }
        for (++C1;*C1 && (*C1 == ' ' || *C1 == '\t');++C1);
        if (!*C1)                       /* if empty */
                return;
 
-       if (!(pf = popen(MAIL_CMD,"w")))
-               error("sendmail pipe failed.",CHN);
+       if (!(pf = popen(MAIL_CMD, "w")))
+               error("sendmail pipe failed.", CHN);
 
 
-       fprintf(pf,"Reply-To: %s\n",BUGS_HOME);
+       fprintf(pf, "Reply-To: %s\n", BUGS_HOME);
        if (mailhead[SUBJ_TAG].found)
        if (mailhead[SUBJ_TAG].found)
-               fprintf(pf,"%s",mailhead[SUBJ_TAG].line);
+               fprintf(pf, "%s", mailhead[SUBJ_TAG].line);
        else
        else
-               fputs("Subject: Untitled Bug Report\n",pf);
-       fputs("Resent-To: ",pf);
+               fputs("Subject: Untitled Bug Report\n", pf);
+       fputs("Resent-To: ", pf);
 
        /*
         * write out first entry, then succeeding entries
         * backward compatible, handles back slashes at end of line
         */
        for (;;) {
 
        /*
         * write out first entry, then succeeding entries
         * backward compatible, handles back slashes at end of line
         */
        for (;;) {
-               if (C2 = index(C1,'\\'))
+               if (C2 = index(C1, '\\'))
                        *C2 = EOS;
                        *C2 = EOS;
-               fputs(C1,pf);
+               fputs(C1, pf);
                if (!gets(bfr) || (*bfr != ' ' && *bfr != '\t'))
                        break;
                for (C1 = bfr;*C1 && (*C1 == ' ' || *C1 == '\t');++C1);
        }
                if (!gets(bfr) || (*bfr != ' ' && *bfr != '\t'))
                        break;
                for (C1 = bfr;*C1 && (*C1 == ' ' || *C1 == '\t');++C1);
        }
-       fputs("\n",pf);
+       putc('\n', pf);
 
 
-       if (!(dfp = fopen(distf,"r")))
-               error("unable to read temporary file %s.",distf);
-       while (fgets(bfr,sizeof(bfr),dfp))
+       rewind(dfp);
+       for (first = YES;fgets(bfr, sizeof(bfr), dfp);)
                if (*bfr == '\n' && first) {
                        first = NO;
                if (*bfr == '\n' && first) {
                        first = NO;
-                       fprintf(pf,"\n%sReference: %s\n",mailhead[INDX_TAG].line,pfile);
+                       fprintf(pf, "\n%sReference: %s\n", mailhead[INDX_TAG].line, pfile);
                }
                else
                }
                else
-                       fputs(bfr,pf);
-       fclose(dfp);
-       pclose(pf);
-       unlink(distf);
+                       fputs(bfr, pf);
+       (void)pclose(pf);
+       (void)fclose(dfp);
 }
 }
index 041b954..0417a74 100644 (file)
@@ -5,18 +5,16 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)reply.c    5.1 (Berkeley) 86/11/25";
+static char sccsid[] = "@(#)reply.c    5.2 (Berkeley) 87/04/11";
 #endif not lint
 
 #include <bug.h>
 #include <sys/file.h>
 #include <stdio.h>
 
 #endif not lint
 
 #include <bug.h>
 #include <sys/file.h>
 #include <stdio.h>
 
-extern HEADER  mailhead[];                     /* mail headers */
-
 /*
  * reply --
 /*
  * reply --
- *     tell the user we got their bug report
+ *     tell the user we got their silly little bug report
  */
 reply()
 {
  */
 reply()
 {
@@ -26,7 +24,7 @@ reply()
                        rval;                   /* return value */
        FILE    *pf,                            /* pipe pointer */
                *popen();
                        rval;                   /* return value */
        FILE    *pf,                            /* pipe pointer */
                *popen();
-       char    *mktemp(), *strcpy(), *index();
+       char    *index();
 
        if (mailhead[RPLY_TAG].found) {
                for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
 
        if (mailhead[RPLY_TAG].found) {
                for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
@@ -46,7 +44,7 @@ reply()
        return;
 
        /* if it's a foo <XXX>, get the XXX, else get foo (first string) */
        return;
 
        /* if it's a foo <XXX>, get the XXX, else get foo (first string) */
-gotone:        if (to = index(C,'<'))
+gotone:        if (to = index(C, '<'))
                for (C = ++to;*C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
        else {
                to = C;
                for (C = ++to;*C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
        else {
                to = C;
@@ -54,26 +52,25 @@ gotone:     if (to = index(C,'<'))
        }
        *C = EOS;
 
        }
        *C = EOS;
 
-       if (!(pf = popen(MAIL_CMD,"w")))
-               error("sendmail pipe failed.",CHN);
+       if (!(pf = popen(MAIL_CMD, "w")))
+               error("sendmail pipe failed.", CHN);
 
 
-       fprintf(pf,"Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n",BUGS_HOME,BUGS_HOME,to);
+       fprintf(pf, "Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n", BUGS_HOME, BUGS_HOME, to);
        if (mailhead[SUBJ_TAG].found)
        if (mailhead[SUBJ_TAG].found)
-               fprintf(pf,"Subject: Re:%s",mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
+               fprintf(pf, "Subject: Re:%s", mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
        else
        else
-               fputs("Subject: Bug report acknowledgement.\n",pf);
+               fputs("Subject: Bug report acknowledgement.\n", pf);
        if (mailhead[DATE_TAG].found)
        if (mailhead[DATE_TAG].found)
-               fprintf(pf,"In-Acknowledgement-Of: Your message of %s",mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
+               fprintf(pf, "In-Acknowledgement-Of: Your message of %s", mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
        if (mailhead[MSG_TAG].found)
        if (mailhead[MSG_TAG].found)
-               fprintf(pf,"\t\t%s",mailhead[MSG_TAG].line);
-       putc('\n',pf);
+               fprintf(pf, "\t\t%s", mailhead[MSG_TAG].line);
+       putc('\n', pf);
        fflush(pf);
 
        fflush(pf);
 
-       if ((afd = open(ACK_FILE,O_RDONLY,0)) >= 0) {
-               while ((rval = read(afd,bfr,sizeof(bfr))) != ERR && rval)
-                       write(fileno(pf),bfr,rval);
-               close(afd);
+       if ((afd = open(ACK_FILE, O_RDONLY, 0)) >= 0) {
+               while ((rval = read(afd, bfr, sizeof(bfr))) != ERR && rval)
+                       (void)write(fileno(pf), bfr, rval);
+               (void)close(afd);
        }
        }
-
        pclose(pf);
 }
        pclose(pf);
 }