home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / listserv5.31 / part01 / src / pqueue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-12  |  3.6 KB  |  112 lines

  1. /*
  2.   ----------------------------------------------------------------------------
  3.   |                    MAIL QUEUE PROCESSING ROUTINES                        |
  4.   |                                                                          |
  5.   |                             Version 1.0                                  |
  6.   |                                                                          |
  7.   |                (or, when Computer Science gets to you)                   |
  8.   |                                                                          |
  9.   |                    Written by Anastasios Kotsikonas                      |
  10.   |                           (tasos@cs.bu.edu)                              |
  11.   |                                                                          |
  12.   | AGREEMENT: This software can be used and distributed freely as long      |
  13.   | as you do not remove or alter the Copyright notice in the file defs.h;   |
  14.   | this notice is #define'd in the symbol VERSION. Although you may alter   |
  15.   | the code provided, you may not alter the functions create_header()       |
  16.   | and create_multi_recipient_header() in list.c and listserv.c.            |
  17.   | By using this software you are bound by this agreement.                  |
  18.   | This software comes with no warranties and cannot be sold for profit.    |
  19.   | The AGREEMENT and COPYRIGHT notices should be included in all source     |
  20.   | files when distributing this software.                                   |
  21.   | COPYRIGHT: Copyright (c) 1991, Anastasios C. Kotsikonas                  |
  22.   ----------------------------------------------------------------------------
  23.  
  24.   The 'system' mailmethod is used to attempt another delivery of the
  25.   specified file. If it cannot be done, the file is queued again.
  26. */
  27.  
  28. #include <stdio.h>
  29. #include <unistd.h>
  30. #include <sys/types.h>
  31. #include <sys/stat.h>
  32. #include <fcntl.h>
  33. #include <signal.h>
  34. #include "defs.h"
  35. #include "struct.h"
  36. #include "global.h"
  37. #include "pqueue.h"
  38.  
  39. extern BOOLEAN sysmail (char *);
  40.  
  41. void   main (int, char **, char **);
  42. void   usage (void);
  43. void   gexit (void);
  44.  
  45. void main (int argc, char **argv, char **envp)
  46. {
  47.   char msg [MAX_LINE], *options = "eD";
  48.   int c;
  49.   FILE *f;
  50.   struct stat stat_buf;
  51.   extern char *optarg;
  52.   extern int optopt, optind;
  53.  
  54.   while ((c = getopt (argc, argv, options)) != EOF)
  55.     switch ((char) c) {
  56.     case 'e': tty_echo = TRUE; break;
  57.     case 'D': debug = TRUE; break;
  58.     case '?':
  59.     default:
  60.       usage ();
  61.   }
  62.   if (argc < 2)
  63.     fprintf (stderr, "pqueue: filename(s) missing.\n"),
  64.     exit (3);
  65. #ifndef _MINIX
  66.   if (lockf (open (PQUEUE_LOCK_FILE, O_RDWR), F_TLOCK, 0))
  67.     fprintf (stderr, "pqueue: Unable to lock %s. Aborting.\n",
  68.          PQUEUE_LOCK_FILE),
  69.     exit (2);
  70. #endif
  71.   init_signals();
  72.   catch_signals();
  73.   if ((report = fopen (REPORT_PQUEUE, "a")) == NULL)
  74.     fprintf (stderr, "pqueue: Could not open %s\n", REPORT_PQUEUE),
  75.     exit (1);
  76.   if ((f = fopen (PID_PQUEUE, "w")) != NULL)
  77.     fprintf (f, "%d", getpid()),
  78.     fclose (f);
  79.   signal (SIGINT, gexit);
  80.   while (--argc >= optind) { /* main loop */
  81.     if (stat (argv [argc], &stat_buf))
  82.       sprintf (msg, "\nmain(): Could not stat %s", argv [argc]),
  83.       report_progress (report, msg, TRUE),
  84.       exit (1);
  85.     if (sysmail (argv [argc]))
  86.       if (unlink (argv [argc]))
  87.     sprintf (msg, "\nmain(): Could not unlink file %s", argv [argc]),
  88.      report_progress (report, msg, TRUE),
  89.     exit (1);
  90.   }
  91.   fclose (report);
  92.   gexit ();
  93. }
  94.  
  95. void usage ()
  96. {
  97.   fprintf (stderr, "Usage: pqueue [-e] [-D] <files>\n\
  98. -e: Echo reports to the screen.\n\
  99. -D: Turn debug on.\n");
  100.   exit (3);
  101. }
  102.  
  103. /*
  104.   Graceful exit. Remove pid file.
  105. */
  106.  
  107. void gexit ()
  108. {
  109.   unlink (PID_PQUEUE);
  110.   exit (0);
  111. }
  112.