14632Seric # include "sendmail.h" 24632Seric # include <sys/stat.h> 38348Seric # include <dir.h> 44634Seric # include <signal.h> 54632Seric # include <errno.h> 64632Seric 75182Seric # ifndef QUEUE 8*10070Seric SCCSID(@(#)queue.c 3.61 01/02/83 (no queueing)); 95182Seric # else QUEUE 104632Seric 11*10070Seric SCCSID(@(#)queue.c 3.61 01/02/83); 125182Seric 134632Seric /* 149377Seric ** Work queue. 159377Seric */ 169377Seric 179377Seric struct work 189377Seric { 199377Seric char *w_name; /* name of control file */ 209377Seric long w_pri; /* priority of message, see below */ 219377Seric struct work *w_next; /* next in queue */ 229377Seric }; 239377Seric 249377Seric typedef struct work WORK; 259377Seric 269377Seric WORK *WorkQ; /* queue of things to be done */ 279377Seric /* 284632Seric ** QUEUEUP -- queue a message up for future transmission. 294632Seric ** 304632Seric ** Parameters: 316980Seric ** e -- the envelope to queue up. 326999Seric ** queueall -- if TRUE, queue all addresses, rather than 336999Seric ** just those with the QQUEUEUP flag set. 349377Seric ** announce -- if TRUE, tell when you are queueing up. 354632Seric ** 364632Seric ** Returns: 374632Seric ** none. 384632Seric ** 394632Seric ** Side Effects: 409377Seric ** The current request are saved in a control file. 414632Seric */ 424632Seric 439377Seric queueup(e, queueall, announce) 446980Seric register ENVELOPE *e; 456999Seric bool queueall; 469377Seric bool announce; 474632Seric { 487812Seric char *tf; 497812Seric char *qf; 507763Seric char buf[MAXLINE]; 517812Seric register FILE *tfp; 524632Seric register HDR *h; 535007Seric register ADDRESS *q; 544632Seric 555037Seric /* 565037Seric ** Create control file. 575037Seric */ 584632Seric 597812Seric tf = newstr(queuename(e, 't')); 607812Seric tfp = fopen(tf, "w"); 617812Seric if (tfp == NULL) 624632Seric { 637812Seric syserr("queueup: cannot create temp file %s", tf); 644632Seric return; 654632Seric } 669048Seric (void) chmod(tf, FileMode); 674632Seric 684632Seric # ifdef DEBUG 697677Seric if (tTd(40, 1)) 707812Seric printf("queueing in %s\n", tf); 714632Seric # endif DEBUG 724632Seric 734632Seric /* 746980Seric ** If there is no data file yet, create one. 756980Seric */ 766980Seric 776980Seric if (e->e_df == NULL) 786980Seric { 796980Seric register FILE *dfp; 809389Seric extern putbody(); 816980Seric 827812Seric e->e_df = newstr(queuename(e, 'd')); 836980Seric dfp = fopen(e->e_df, "w"); 846980Seric if (dfp == NULL) 856980Seric { 866980Seric syserr("queueup: cannot create %s", e->e_df); 877812Seric (void) fclose(tfp); 886980Seric return; 896980Seric } 909048Seric (void) chmod(e->e_df, FileMode); 9110066Seric (*e->e_putbody)(dfp, ProgMailer, FALSE, e, FALSE); 927009Seric (void) fclose(dfp); 939389Seric e->e_putbody = putbody; 946980Seric } 956980Seric 966980Seric /* 974632Seric ** Output future work requests. 989377Seric ** Priority should be first, since it is read by orderq. 994632Seric */ 1004632Seric 1019377Seric /* output message priority */ 1029377Seric fprintf(tfp, "P%ld\n", e->e_msgpriority); 1039377Seric 1049630Seric /* output creation time */ 1059630Seric fprintf(tfp, "T%ld\n", e->e_ctime); 1069630Seric 1074632Seric /* output name of data file */ 1087812Seric fprintf(tfp, "D%s\n", e->e_df); 1094632Seric 1104632Seric /* output name of sender */ 1117812Seric fprintf(tfp, "S%s\n", e->e_from.q_paddr); 1124632Seric 1134632Seric /* output list of recipient addresses */ 1146980Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 1154632Seric { 1167763Seric if (queueall ? !bitset(QDONTSEND, q->q_flags) : 1177763Seric bitset(QQUEUEUP, q->q_flags)) 1188245Seric { 1197812Seric fprintf(tfp, "R%s\n", q->q_paddr); 1209377Seric if (announce) 1219377Seric { 1229377Seric e->e_to = q->q_paddr; 1239377Seric message(Arpa_Info, "queued"); 1249377Seric if (LogLevel > 4) 1259377Seric logdelivery("queued"); 1269377Seric e->e_to = NULL; 1279377Seric } 1289387Seric #ifdef DEBUG 1299387Seric if (tTd(40, 1)) 1309387Seric { 1319387Seric printf("queueing "); 1329387Seric printaddr(q, FALSE); 1339387Seric } 1349387Seric #endif DEBUG 1358245Seric } 1364632Seric } 1374632Seric 1389377Seric /* 1399377Seric ** Output headers for this message. 1409377Seric ** Expand macros completely here. Queue run will deal with 1419377Seric ** everything as absolute headers. 1429377Seric ** All headers that must be relative to the recipient 1439377Seric ** can be cracked later. 1449377Seric */ 1459377Seric 1469377Seric define('g', "$f", e); 1476980Seric for (h = e->e_header; h != NULL; h = h->h_link) 1484632Seric { 1494632Seric if (h->h_value == NULL || h->h_value[0] == '\0') 1504632Seric continue; 1517812Seric fprintf(tfp, "H"); 1524632Seric if (h->h_mflags != 0 && bitset(H_CHECK|H_ACHECK, h->h_flags)) 1537812Seric mfdecode(h->h_mflags, tfp); 1547763Seric if (bitset(H_DEFAULT, h->h_flags)) 1557763Seric { 1567763Seric (void) expand(h->h_value, buf, &buf[sizeof buf], e); 1578236Seric fprintf(tfp, "%s: %s\n", h->h_field, buf); 1587763Seric } 1598245Seric else if (bitset(H_FROM|H_RCPT, h->h_flags)) 1609348Seric { 1619348Seric commaize(h, h->h_value, tfp, bitset(EF_OLDSTYLE, e->e_flags), 16210066Seric (MAILER *) NULL, FALSE); 1639348Seric } 1647763Seric else 1658245Seric fprintf(tfp, "%s: %s\n", h->h_field, h->h_value); 1664632Seric } 1674632Seric 1684632Seric /* 1694632Seric ** Clean up. 1704632Seric */ 1714632Seric 1727812Seric (void) fclose(tfp); 1737812Seric qf = queuename(e, 'q'); 1749377Seric holdsigs(); 1757812Seric (void) unlink(qf); 1767812Seric if (link(tf, qf) < 0) 1777812Seric syserr("cannot link(%s, %s), df=%s", tf, qf, e->e_df); 1786980Seric else 1797812Seric (void) unlink(tf); 1809377Seric rlsesigs(); 1817391Seric 1827677Seric # ifdef LOG 1837677Seric /* save log info */ 1847878Seric if (LogLevel > 15) 1857878Seric syslog(LOG_DEBUG, "%s: queueup, qf=%s, df=%s\n", e->e_id, qf, e->e_df); 1867677Seric # endif LOG 1874632Seric } 1884632Seric /* 1894632Seric ** RUNQUEUE -- run the jobs in the queue. 1904632Seric ** 1914632Seric ** Gets the stuff out of the queue in some presumably logical 1924632Seric ** order and processes them. 1934632Seric ** 1944632Seric ** Parameters: 1954632Seric ** none. 1964632Seric ** 1974632Seric ** Returns: 1984632Seric ** none. 1994632Seric ** 2004632Seric ** Side Effects: 2014632Seric ** runs things in the mail queue. 2024632Seric */ 2034632Seric 2044639Seric runqueue(forkflag) 2054639Seric bool forkflag; 2064632Seric { 2077466Seric /* 2087466Seric ** See if we want to go off and do other useful work. 2097466Seric */ 2104639Seric 2114639Seric if (forkflag) 2124639Seric { 2137943Seric int pid; 2147943Seric 2157943Seric pid = dofork(); 2167943Seric if (pid != 0) 2174639Seric { 2187943Seric /* parent -- pick up intermediate zombie */ 2199377Seric (void) waitfor(pid); 2207690Seric if (QueueIntvl != 0) 2219348Seric (void) setevent(QueueIntvl, runqueue, TRUE); 2224639Seric return; 2234639Seric } 2247943Seric /* child -- double fork */ 2257943Seric if (fork() != 0) 2267943Seric exit(EX_OK); 2274639Seric } 2287876Seric # ifdef LOG 2297876Seric if (LogLevel > 11) 2307943Seric syslog(LOG_DEBUG, "runqueue %s, pid=%d", QueueDir, getpid()); 2317876Seric # endif LOG 2324639Seric 2337466Seric /* 2347466Seric ** Start making passes through the queue. 2357466Seric ** First, read and sort the entire queue. 2367466Seric ** Then, process the work in that order. 2377466Seric ** But if you take too long, start over. 2387466Seric */ 2397466Seric 2407943Seric /* order the existing work requests */ 241*10070Seric (void) orderq(); 2427690Seric 2437943Seric /* process them once at a time */ 2447943Seric while (WorkQ != NULL) 2454639Seric { 2467943Seric WORK *w = WorkQ; 2477881Seric 2487943Seric WorkQ = WorkQ->w_next; 2497943Seric dowork(w); 2507943Seric free(w->w_name); 2517943Seric free((char *) w); 2524639Seric } 2537943Seric finis(); 2544634Seric } 2554634Seric /* 2564632Seric ** ORDERQ -- order the work queue. 2574632Seric ** 2584632Seric ** Parameters: 2594632Seric ** none. 2604632Seric ** 2614632Seric ** Returns: 2624632Seric ** none. 2634632Seric ** 2644632Seric ** Side Effects: 2654632Seric ** Sets WorkQ to the queue of available work, in order. 2664632Seric */ 2674632Seric 2684632Seric # define WLSIZE 120 /* max size of worklist per sort */ 2694632Seric 2704632Seric orderq() 2714632Seric { 2726625Sglickman register struct direct *d; 2734632Seric register WORK *w; 2744632Seric register WORK **wp; /* parent of w */ 2756625Sglickman DIR *f; 2764632Seric register int i; 2774632Seric WORK wlist[WLSIZE]; 278*10070Seric int wn = -1; 2794632Seric extern workcmpf(); 2804632Seric 2814632Seric /* clear out old WorkQ */ 2824632Seric for (w = WorkQ; w != NULL; ) 2834632Seric { 2844632Seric register WORK *nw = w->w_next; 2854632Seric 2864632Seric WorkQ = nw; 2874632Seric free(w->w_name); 2884632Seric free((char *) w); 2894632Seric w = nw; 2904632Seric } 2914632Seric 2924632Seric /* open the queue directory */ 2938148Seric f = opendir("."); 2944632Seric if (f == NULL) 2954632Seric { 2968148Seric syserr("orderq: cannot open \"%s\" as \".\"", QueueDir); 297*10070Seric return (0); 2984632Seric } 2994632Seric 3004632Seric /* 3014632Seric ** Read the work directory. 3024632Seric */ 3034632Seric 304*10070Seric while ((d = readdir(f)) != NULL) 3054632Seric { 3069377Seric FILE *cf; 3074632Seric char lbuf[MAXNAME]; 3084632Seric 3094632Seric /* is this an interesting entry? */ 3107812Seric if (d->d_name[0] != 'q' || d->d_name[1] != 'f') 3114632Seric continue; 3124632Seric 313*10070Seric /* yes -- open control file (if not too many files) */ 314*10070Seric if (++wn >= WLSIZE) 315*10070Seric continue; 3168148Seric cf = fopen(d->d_name, "r"); 3174632Seric if (cf == NULL) 3184632Seric { 3197055Seric /* this may be some random person sending hir msgs */ 3207055Seric /* syserr("orderq: cannot open %s", cbuf); */ 3217055Seric errno = 0; 3224632Seric continue; 3234632Seric } 3248148Seric wlist[wn].w_name = newstr(d->d_name); 3254632Seric 3264632Seric /* extract useful information */ 3274632Seric while (fgets(lbuf, sizeof lbuf, cf) != NULL) 3284632Seric { 3299377Seric if (lbuf[0] == 'P') 3304632Seric { 3315037Seric (void) sscanf(&lbuf[1], "%ld", &wlist[wn].w_pri); 3324632Seric break; 3334632Seric } 3344632Seric } 3354632Seric (void) fclose(cf); 3364632Seric } 3376625Sglickman (void) closedir(f); 3384632Seric 3394632Seric /* 3404632Seric ** Sort the work directory. 3414632Seric */ 3424632Seric 3434632Seric qsort(wlist, wn, sizeof *wlist, workcmpf); 3444632Seric 3454632Seric /* 3464632Seric ** Convert the work list into canonical form. 3479377Seric ** Should be turning it into a list of envelopes here perhaps. 3484632Seric */ 3494632Seric 3504632Seric wp = &WorkQ; 3514632Seric for (i = 0; i < wn; i++) 3524632Seric { 3534632Seric w = (WORK *) xalloc(sizeof *w); 3544632Seric w->w_name = wlist[i].w_name; 3554632Seric w->w_pri = wlist[i].w_pri; 3564632Seric w->w_next = NULL; 3574632Seric *wp = w; 3584632Seric wp = &w->w_next; 3594632Seric } 3604632Seric 3614632Seric # ifdef DEBUG 3627677Seric if (tTd(40, 1)) 3634632Seric { 3644632Seric for (w = WorkQ; w != NULL; w = w->w_next) 3655037Seric printf("%32s: pri=%ld\n", w->w_name, w->w_pri); 3664632Seric } 3674632Seric # endif DEBUG 368*10070Seric 369*10070Seric return (wn + 1); 3704632Seric } 3714632Seric /* 3727677Seric ** WORKCMPF -- compare function for ordering work. 3734632Seric ** 3744632Seric ** Parameters: 3754632Seric ** a -- the first argument. 3764632Seric ** b -- the second argument. 3774632Seric ** 3784632Seric ** Returns: 3794632Seric ** -1 if a < b 3804632Seric ** 0 if a == b 3814632Seric ** 1 if a > b 3824632Seric ** 3834632Seric ** Side Effects: 3844632Seric ** none. 3854632Seric */ 3864632Seric 3874632Seric # define PRIFACT 1800 /* bytes each priority point is worth */ 3884632Seric 3894632Seric workcmpf(a, b) 3905037Seric register WORK *a; 3915037Seric register WORK *b; 3924632Seric { 3935037Seric if (a->w_pri == b->w_pri) 3944632Seric return (0); 3955037Seric else if (a->w_pri > b->w_pri) 3964632Seric return (1); 3974632Seric else 3984632Seric return (-1); 3994632Seric } 4004632Seric /* 4014632Seric ** DOWORK -- do a work request. 4024632Seric ** 4034632Seric ** Parameters: 4044632Seric ** w -- the work request to be satisfied. 4054632Seric ** 4064632Seric ** Returns: 4074632Seric ** none. 4084632Seric ** 4094632Seric ** Side Effects: 4104632Seric ** The work request is satisfied if possible. 4114632Seric */ 4124632Seric 4134632Seric dowork(w) 4144632Seric register WORK *w; 4154632Seric { 4164632Seric register int i; 4174632Seric 4184632Seric # ifdef DEBUG 4197677Seric if (tTd(40, 1)) 4205037Seric printf("dowork: %s pri %ld\n", w->w_name, w->w_pri); 4214632Seric # endif DEBUG 4224632Seric 4234632Seric /* 4244632Seric ** Fork for work. 4254632Seric */ 4264632Seric 4274632Seric i = fork(); 4284632Seric if (i < 0) 4294632Seric { 4304632Seric syserr("dowork: cannot fork"); 4314632Seric return; 4324632Seric } 4334632Seric 4344632Seric if (i == 0) 4354632Seric { 4364632Seric /* 4374632Seric ** CHILD 4388148Seric ** Lock the control file to avoid duplicate deliveries. 4398148Seric ** Then run the file as though we had just read it. 4407350Seric ** We save an idea of the temporary name so we 4417350Seric ** can recover on interrupt. 4424632Seric */ 4434632Seric 4447763Seric /* set basic modes, etc. */ 4457356Seric (void) alarm(0); 4469338Seric CurEnv->e_flags &= ~EF_FATALERRS; 4474632Seric QueueRun = TRUE; 4489387Seric SendMode = SM_DELIVER; 4499377Seric ErrorMode = EM_MAIL; 4508148Seric CurEnv->e_id = &w->w_name[2]; 4517876Seric # ifdef LOG 4527876Seric if (LogLevel > 11) 4537881Seric syslog(LOG_DEBUG, "%s: dowork, pid=%d", CurEnv->e_id, 4547881Seric getpid()); 4557876Seric # endif LOG 4567763Seric 4577763Seric /* don't use the headers from sendmail.cf... */ 4587763Seric CurEnv->e_header = NULL; 4599348Seric (void) chompheader("from: $q", TRUE); 4607763Seric 4617763Seric /* create the link to the control file during processing */ 4627812Seric if (link(w->w_name, queuename(CurEnv, 'l')) < 0) 4636980Seric { 4647812Seric /* being processed by another queuer */ 4657881Seric # ifdef LOG 4667881Seric if (LogLevel > 4) 4677881Seric syslog(LOG_DEBUG, "%s: locked", CurEnv->e_id); 4687881Seric # endif LOG 4696980Seric exit(EX_OK); 4706980Seric } 4716980Seric 4726980Seric /* do basic system initialization */ 4734632Seric initsys(); 4746980Seric 4756980Seric /* read the queue control file */ 4769630Seric readqf(CurEnv, TRUE); 4779338Seric CurEnv->e_flags |= EF_INQUEUE; 4789377Seric eatheader(CurEnv); 4796980Seric 4806980Seric /* do the delivery */ 4819338Seric if (!bitset(EF_FATALERRS, CurEnv->e_flags)) 4829282Seric sendall(CurEnv, SM_DELIVER); 4836980Seric 4846980Seric /* if still not sent, perhaps we should time out.... */ 4854634Seric # ifdef DEBUG 4867677Seric if (tTd(40, 3)) 4877886Seric printf("curtime=%ld, TimeOut=%ld\n", curtime(), 4887860Seric CurEnv->e_ctime + TimeOut); 4894634Seric # endif DEBUG 4909338Seric if (curtime() > CurEnv->e_ctime + TimeOut) 4919338Seric CurEnv->e_flags |= EF_TIMEOUT; 4926980Seric 4936980Seric /* finish up and exit */ 4944632Seric finis(); 4954632Seric } 4964632Seric 4974632Seric /* 4984632Seric ** Parent -- pick up results. 4994632Seric */ 5004632Seric 5014632Seric errno = 0; 5029377Seric (void) waitfor(i); 5034632Seric } 5044632Seric /* 5054632Seric ** READQF -- read queue file and set up environment. 5064632Seric ** 5074632Seric ** Parameters: 5089377Seric ** e -- the envelope of the job to run. 5099630Seric ** full -- if set, read in all information. Otherwise just 5109630Seric ** read in info needed for a queue print. 5114632Seric ** 5124632Seric ** Returns: 5134632Seric ** none. 5144632Seric ** 5154632Seric ** Side Effects: 5164632Seric ** cf is read and created as the current job, as though 5174632Seric ** we had been invoked by argument. 5184632Seric */ 5194632Seric 5209630Seric readqf(e, full) 5219377Seric register ENVELOPE *e; 5229630Seric bool full; 5234632Seric { 5244632Seric register FILE *f; 5257785Seric char buf[MAXFIELD]; 5269348Seric extern char *fgetfolded(); 5279377Seric register char *p; 5284632Seric 5294632Seric /* 5304632Seric ** Open the file created by queueup. 5314632Seric */ 5324632Seric 5339377Seric p = queuename(e, 'q'); 5349377Seric f = fopen(p, "r"); 5354632Seric if (f == NULL) 5364632Seric { 5379377Seric syserr("readqf: no control file %s", p); 5384632Seric return; 5394632Seric } 5409377Seric FileName = p; 5419377Seric LineNumber = 0; 5424632Seric 5434632Seric /* 5444632Seric ** Read and process the file. 5454632Seric */ 5464632Seric 5479630Seric if (Verbose && full) 5489377Seric printf("\nRunning %s\n", e->e_id); 5497785Seric while (fgetfolded(buf, sizeof buf, f) != NULL) 5504632Seric { 5514632Seric switch (buf[0]) 5524632Seric { 5534632Seric case 'R': /* specify recipient */ 5549618Seric sendtolist(&buf[1], (ADDRESS *) NULL, &e->e_sendqueue); 5554632Seric break; 5564632Seric 5574632Seric case 'H': /* header */ 5589630Seric if (full) 5599630Seric (void) chompheader(&buf[1], FALSE); 5604632Seric break; 5614632Seric 5624632Seric case 'S': /* sender */ 5634634Seric setsender(newstr(&buf[1])); 5644632Seric break; 5654632Seric 5664632Seric case 'D': /* data file name */ 5679630Seric if (!full) 5689630Seric break; 5699377Seric e->e_df = newstr(&buf[1]); 5709544Seric e->e_dfp = fopen(e->e_df, "r"); 5719544Seric if (e->e_dfp == NULL) 5729377Seric syserr("readqf: cannot open %s", e->e_df); 5734632Seric break; 5744632Seric 5757860Seric case 'T': /* init time */ 5769377Seric (void) sscanf(&buf[1], "%ld", &e->e_ctime); 5774632Seric break; 5784632Seric 5794634Seric case 'P': /* message priority */ 5809377Seric (void) sscanf(&buf[1], "%ld", &e->e_msgpriority); 5815037Seric 5825037Seric /* make sure that big things get sent eventually */ 5839377Seric e->e_msgpriority -= WKTIMEFACT; 5844634Seric break; 5854634Seric 5865902Seric case 'M': /* define macro */ 5879630Seric if (full) 5889630Seric define(buf[1], newstr(&buf[2]), e); 5895902Seric break; 5905902Seric 5914632Seric default: 5929377Seric syserr("readqf(%s): bad line \"%s\"", e->e_id, buf); 5934632Seric break; 5944632Seric } 5954632Seric } 5969377Seric 5979377Seric FileName = NULL; 5984632Seric } 5994632Seric /* 6004632Seric ** TIMEOUT -- process timeout on queue file. 6014632Seric ** 6024632Seric ** Parameters: 6039338Seric ** e -- the envelope that timed out. 6044632Seric ** 6054632Seric ** Returns: 6064632Seric ** none. 6074632Seric ** 6084632Seric ** Side Effects: 6094632Seric ** Returns a message to the sender saying that this 6104632Seric ** message has timed out. 6114632Seric */ 6124632Seric 6139338Seric timeout(e) 6149338Seric register ENVELOPE *e; 6154632Seric { 6167369Seric char buf[MAXLINE]; 6177860Seric extern char *pintvl(); 6187369Seric 6194634Seric # ifdef DEBUG 6207677Seric if (tTd(40, 3)) 6219338Seric printf("timeout(%s)\n", e->e_id); 6224634Seric # endif DEBUG 6239338Seric e->e_to = NULL; 6246991Seric message(Arpa_Info, "Message has timed out"); 6254634Seric 6264634Seric /* return message to sender */ 6277860Seric (void) sprintf(buf, "Cannot send mail for %s", pintvl(TimeOut, FALSE)); 6289338Seric (void) returntosender(buf, &e->e_from, TRUE); 6294634Seric 6304634Seric /* arrange to remove files from queue */ 6319338Seric e->e_flags |= EF_CLRQUEUE; 6324632Seric } 6339630Seric /* 6349630Seric ** PRINTQUEUE -- print out a representation of the mail queue 6359630Seric ** 6369630Seric ** Parameters: 6379630Seric ** none. 6389630Seric ** 6399630Seric ** Returns: 6409630Seric ** none. 6419630Seric ** 6429630Seric ** Side Effects: 6439630Seric ** Prints a listing of the mail queue on the standard output. 6449630Seric */ 6455182Seric 6469630Seric printqueue() 6479630Seric { 6489630Seric register WORK *w; 6499630Seric FILE *f; 650*10070Seric int nrequests; 6519630Seric char buf[MAXLINE]; 6529630Seric 6539630Seric /* 6549630Seric ** Read and order the queue. 6559630Seric */ 6569630Seric 657*10070Seric nrequests = orderq(); 6589630Seric 6599630Seric /* 6609630Seric ** Print the work list that we have read. 6619630Seric */ 6629630Seric 6639630Seric /* first see if there is anything */ 664*10070Seric if (nrequests <= 0) 6659630Seric { 666*10070Seric printf("Mail queue is empty\n"); 6679630Seric return; 6689630Seric } 6699630Seric 670*10070Seric printf("\t\tMail Queue (%d requests", nrequests); 671*10070Seric if (nrequests > WLSIZE) 672*10070Seric printf(", only %d printed", WLSIZE); 673*10070Seric printf(")\n--QID-- --Size-- -----Q-Time----- ------------Sender/Recipient------------\n"); 6749630Seric for (w = WorkQ; w != NULL; w = w->w_next) 6759630Seric { 6769630Seric struct stat st; 677*10070Seric char lf[20]; 678*10070Seric auto time_t submittime = 0; 679*10070Seric long dfsize = -1; 6809630Seric 6819630Seric printf("%7s", w->w_name + 2); 682*10070Seric strcpy(lf, w->w_name); 683*10070Seric lf[0] = 'l'; 684*10070Seric if (stat(lf, &st) >= 0) 685*10070Seric printf("*"); 686*10070Seric else 687*10070Seric printf(" "); 688*10070Seric errno = 0; 6899630Seric f = fopen(w->w_name, "r"); 6909630Seric if (f == NULL) 6919630Seric { 6929630Seric printf(" (finished)\n"); 693*10070Seric errno = 0; 6949630Seric continue; 6959630Seric } 6969630Seric while (fgets(buf, sizeof buf, f) != NULL) 6979630Seric { 6989630Seric fixcrlf(buf, TRUE); 6999630Seric switch (buf[0]) 7009630Seric { 7019630Seric case 'S': /* sender name */ 702*10070Seric printf("%8d %.16s %.40s", dfsize, 703*10070Seric ctime(&submittime), &buf[1]); 7049630Seric break; 7059630Seric 7069630Seric case 'R': /* recipient name */ 707*10070Seric printf("\n\t\t\t\t %.40s", &buf[1]); 7089630Seric break; 7099630Seric 7109630Seric case 'T': /* creation time */ 711*10070Seric sscanf(&buf[1], "%ld", &submittime); 7129630Seric break; 713*10070Seric 714*10070Seric case 'D': /* data file name */ 715*10070Seric if (stat(&buf[1], &st) >= 0) 716*10070Seric dfsize = st.st_size; 717*10070Seric break; 7189630Seric } 7199630Seric } 720*10070Seric if (submittime == (time_t) 0) 721*10070Seric printf(" (no control file)"); 7229630Seric printf("\n"); 7239630Seric fclose(f); 7249630Seric } 7259630Seric } 7269630Seric 7275182Seric # endif QUEUE 728