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*13015Seric SCCSID(@(#)queue.c 3.75 06/11/83 (no queueing)); 95182Seric # else QUEUE 104632Seric 11*13015Seric SCCSID(@(#)queue.c 3.75 06/11/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; 5410173Seric MAILER nullmailer; 554632Seric 565037Seric /* 575037Seric ** Create control file. 585037Seric */ 594632Seric 607812Seric tf = newstr(queuename(e, 't')); 617812Seric tfp = fopen(tf, "w"); 627812Seric if (tfp == NULL) 634632Seric { 647812Seric syserr("queueup: cannot create temp file %s", tf); 654632Seric return; 664632Seric } 679048Seric (void) chmod(tf, FileMode); 684632Seric 694632Seric # ifdef DEBUG 707677Seric if (tTd(40, 1)) 717812Seric printf("queueing in %s\n", tf); 724632Seric # endif DEBUG 734632Seric 744632Seric /* 756980Seric ** If there is no data file yet, create one. 766980Seric */ 776980Seric 786980Seric if (e->e_df == NULL) 796980Seric { 806980Seric register FILE *dfp; 819389Seric extern putbody(); 826980Seric 837812Seric e->e_df = newstr(queuename(e, 'd')); 846980Seric dfp = fopen(e->e_df, "w"); 856980Seric if (dfp == NULL) 866980Seric { 876980Seric syserr("queueup: cannot create %s", e->e_df); 887812Seric (void) fclose(tfp); 896980Seric return; 906980Seric } 919048Seric (void) chmod(e->e_df, FileMode); 9210173Seric (*e->e_putbody)(dfp, ProgMailer, e); 937009Seric (void) fclose(dfp); 949389Seric e->e_putbody = putbody; 956980Seric } 966980Seric 976980Seric /* 984632Seric ** Output future work requests. 999377Seric ** Priority should be first, since it is read by orderq. 1004632Seric */ 1014632Seric 1029377Seric /* output message priority */ 1039377Seric fprintf(tfp, "P%ld\n", e->e_msgpriority); 1049377Seric 1059630Seric /* output creation time */ 1069630Seric fprintf(tfp, "T%ld\n", e->e_ctime); 1079630Seric 1084632Seric /* output name of data file */ 1097812Seric fprintf(tfp, "D%s\n", e->e_df); 1104632Seric 11110108Seric /* message from envelope, if it exists */ 11210108Seric if (e->e_message != NULL) 11310108Seric fprintf(tfp, "M%s\n", e->e_message); 11410108Seric 1154632Seric /* output name of sender */ 1167812Seric fprintf(tfp, "S%s\n", e->e_from.q_paddr); 1174632Seric 1184632Seric /* output list of recipient addresses */ 1196980Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 1204632Seric { 1217763Seric if (queueall ? !bitset(QDONTSEND, q->q_flags) : 1227763Seric bitset(QQUEUEUP, q->q_flags)) 1238245Seric { 1247812Seric fprintf(tfp, "R%s\n", q->q_paddr); 1259377Seric if (announce) 1269377Seric { 1279377Seric e->e_to = q->q_paddr; 1289377Seric message(Arpa_Info, "queued"); 1299377Seric if (LogLevel > 4) 1309377Seric logdelivery("queued"); 1319377Seric e->e_to = NULL; 1329377Seric } 1339387Seric #ifdef DEBUG 1349387Seric if (tTd(40, 1)) 1359387Seric { 1369387Seric printf("queueing "); 1379387Seric printaddr(q, FALSE); 1389387Seric } 1399387Seric #endif DEBUG 1408245Seric } 1414632Seric } 1424632Seric 1439377Seric /* 1449377Seric ** Output headers for this message. 1459377Seric ** Expand macros completely here. Queue run will deal with 1469377Seric ** everything as absolute headers. 1479377Seric ** All headers that must be relative to the recipient 1489377Seric ** can be cracked later. 14910173Seric ** We set up a "null mailer" -- i.e., a mailer that will have 15010173Seric ** no effect on the addresses as they are output. 1519377Seric */ 1529377Seric 15310686Seric bzero((char *) &nullmailer, sizeof nullmailer); 15410173Seric nullmailer.m_r_rwset = nullmailer.m_s_rwset = -1; 15510349Seric nullmailer.m_eol = "\n"; 15610173Seric 1579377Seric define('g', "$f", e); 1586980Seric for (h = e->e_header; h != NULL; h = h->h_link) 1594632Seric { 16010686Seric extern bool bitzerop(); 16110686Seric 16212015Seric /* don't output null headers */ 1634632Seric if (h->h_value == NULL || h->h_value[0] == '\0') 1644632Seric continue; 16512015Seric 16612015Seric /* don't output resent headers on non-resent messages */ 16712015Seric if (bitset(H_RESENT, h->h_flags) && !bitset(EF_RESENT, e->e_flags)) 16812015Seric continue; 16912015Seric 17012015Seric /* output this header */ 1717812Seric fprintf(tfp, "H"); 17212015Seric 17312015Seric /* if conditional, output the set of conditions */ 17410686Seric if (!bitzerop(h->h_mflags) && bitset(H_CHECK|H_ACHECK, h->h_flags)) 17510686Seric { 17610686Seric int j; 17710686Seric 17810686Seric putc('?', tfp); 17910686Seric for (j = '\0'; j <= '\177'; j++) 18010686Seric if (bitnset(j, h->h_mflags)) 18110686Seric putc(j, tfp); 18210686Seric putc('?', tfp); 18310686Seric } 18412015Seric 18512015Seric /* output the header: expand macros, convert addresses */ 1867763Seric if (bitset(H_DEFAULT, h->h_flags)) 1877763Seric { 1887763Seric (void) expand(h->h_value, buf, &buf[sizeof buf], e); 1898236Seric fprintf(tfp, "%s: %s\n", h->h_field, buf); 1907763Seric } 1918245Seric else if (bitset(H_FROM|H_RCPT, h->h_flags)) 1929348Seric { 1939348Seric commaize(h, h->h_value, tfp, bitset(EF_OLDSTYLE, e->e_flags), 19410173Seric &nullmailer); 1959348Seric } 1967763Seric else 1978245Seric fprintf(tfp, "%s: %s\n", h->h_field, h->h_value); 1984632Seric } 1994632Seric 2004632Seric /* 2014632Seric ** Clean up. 2024632Seric */ 2034632Seric 2047812Seric (void) fclose(tfp); 2057812Seric qf = queuename(e, 'q'); 2069377Seric holdsigs(); 2077812Seric (void) unlink(qf); 2087812Seric if (link(tf, qf) < 0) 2097812Seric syserr("cannot link(%s, %s), df=%s", tf, qf, e->e_df); 2106980Seric else 2117812Seric (void) unlink(tf); 2129377Seric rlsesigs(); 2137391Seric 2147677Seric # ifdef LOG 2157677Seric /* save log info */ 2167878Seric if (LogLevel > 15) 2177878Seric syslog(LOG_DEBUG, "%s: queueup, qf=%s, df=%s\n", e->e_id, qf, e->e_df); 2187677Seric # endif LOG 2194632Seric } 2204632Seric /* 2214632Seric ** RUNQUEUE -- run the jobs in the queue. 2224632Seric ** 2234632Seric ** Gets the stuff out of the queue in some presumably logical 2244632Seric ** order and processes them. 2254632Seric ** 2264632Seric ** Parameters: 2274632Seric ** none. 2284632Seric ** 2294632Seric ** Returns: 2304632Seric ** none. 2314632Seric ** 2324632Seric ** Side Effects: 2334632Seric ** runs things in the mail queue. 2344632Seric */ 2354632Seric 2364639Seric runqueue(forkflag) 2374639Seric bool forkflag; 2384632Seric { 2397466Seric /* 2407466Seric ** See if we want to go off and do other useful work. 2417466Seric */ 2424639Seric 2434639Seric if (forkflag) 2444639Seric { 2457943Seric int pid; 2467943Seric 2477943Seric pid = dofork(); 2487943Seric if (pid != 0) 2494639Seric { 2507943Seric /* parent -- pick up intermediate zombie */ 2519377Seric (void) waitfor(pid); 2527690Seric if (QueueIntvl != 0) 2539348Seric (void) setevent(QueueIntvl, runqueue, TRUE); 2544639Seric return; 2554639Seric } 2567943Seric /* child -- double fork */ 2577943Seric if (fork() != 0) 2587943Seric exit(EX_OK); 2594639Seric } 2607876Seric # ifdef LOG 2617876Seric if (LogLevel > 11) 2627943Seric syslog(LOG_DEBUG, "runqueue %s, pid=%d", QueueDir, getpid()); 2637876Seric # endif LOG 2644639Seric 2657466Seric /* 26610205Seric ** Release any resources used by the daemon code. 26710205Seric */ 26810205Seric 26910205Seric # ifdef DAEMON 27010205Seric clrdaemon(); 27110205Seric # endif DAEMON 27210205Seric 27310205Seric /* 2747466Seric ** Start making passes through the queue. 2757466Seric ** First, read and sort the entire queue. 2767466Seric ** Then, process the work in that order. 2777466Seric ** But if you take too long, start over. 2787466Seric */ 2797466Seric 2807943Seric /* order the existing work requests */ 28110070Seric (void) orderq(); 2827690Seric 2837943Seric /* process them once at a time */ 2847943Seric while (WorkQ != NULL) 2854639Seric { 2867943Seric WORK *w = WorkQ; 2877881Seric 2887943Seric WorkQ = WorkQ->w_next; 2897943Seric dowork(w); 2907943Seric free(w->w_name); 2917943Seric free((char *) w); 2924639Seric } 2937943Seric finis(); 2944634Seric } 2954634Seric /* 2964632Seric ** ORDERQ -- order the work queue. 2974632Seric ** 2984632Seric ** Parameters: 2994632Seric ** none. 3004632Seric ** 3014632Seric ** Returns: 30210121Seric ** The number of request in the queue (not necessarily 30310121Seric ** the number of requests in WorkQ however). 3044632Seric ** 3054632Seric ** Side Effects: 3064632Seric ** Sets WorkQ to the queue of available work, in order. 3074632Seric */ 3084632Seric 3094632Seric # define WLSIZE 120 /* max size of worklist per sort */ 3104632Seric 3114632Seric orderq() 3124632Seric { 3136625Sglickman register struct direct *d; 3144632Seric register WORK *w; 3154632Seric register WORK **wp; /* parent of w */ 3166625Sglickman DIR *f; 3174632Seric register int i; 31810121Seric WORK wlist[WLSIZE+1]; 31910070Seric int wn = -1; 3204632Seric extern workcmpf(); 3214632Seric 3224632Seric /* clear out old WorkQ */ 3234632Seric for (w = WorkQ; w != NULL; ) 3244632Seric { 3254632Seric register WORK *nw = w->w_next; 3264632Seric 3274632Seric WorkQ = nw; 3284632Seric free(w->w_name); 3294632Seric free((char *) w); 3304632Seric w = nw; 3314632Seric } 3324632Seric 3334632Seric /* open the queue directory */ 3348148Seric f = opendir("."); 3354632Seric if (f == NULL) 3364632Seric { 3378148Seric syserr("orderq: cannot open \"%s\" as \".\"", QueueDir); 33810070Seric return (0); 3394632Seric } 3404632Seric 3414632Seric /* 3424632Seric ** Read the work directory. 3434632Seric */ 3444632Seric 34510070Seric while ((d = readdir(f)) != NULL) 3464632Seric { 3479377Seric FILE *cf; 3484632Seric char lbuf[MAXNAME]; 3494632Seric 3504632Seric /* is this an interesting entry? */ 3517812Seric if (d->d_name[0] != 'q' || d->d_name[1] != 'f') 3524632Seric continue; 3534632Seric 35410070Seric /* yes -- open control file (if not too many files) */ 35510070Seric if (++wn >= WLSIZE) 35610070Seric continue; 3578148Seric cf = fopen(d->d_name, "r"); 3584632Seric if (cf == NULL) 3594632Seric { 3607055Seric /* this may be some random person sending hir msgs */ 3617055Seric /* syserr("orderq: cannot open %s", cbuf); */ 36210090Seric #ifdef DEBUG 36310090Seric if (tTd(41, 2)) 36410090Seric printf("orderq: cannot open %s (%d)\n", 36510090Seric d->d_name, errno); 36610090Seric #endif DEBUG 3677055Seric errno = 0; 36810090Seric wn--; 3694632Seric continue; 3704632Seric } 3718148Seric wlist[wn].w_name = newstr(d->d_name); 3724632Seric 3734632Seric /* extract useful information */ 3744632Seric while (fgets(lbuf, sizeof lbuf, cf) != NULL) 3754632Seric { 3769377Seric if (lbuf[0] == 'P') 3774632Seric { 3785037Seric (void) sscanf(&lbuf[1], "%ld", &wlist[wn].w_pri); 3794632Seric break; 3804632Seric } 3814632Seric } 3824632Seric (void) fclose(cf); 3834632Seric } 3846625Sglickman (void) closedir(f); 38510090Seric wn++; 3864632Seric 3874632Seric /* 3884632Seric ** Sort the work directory. 3894632Seric */ 3904632Seric 39110121Seric qsort(wlist, min(wn, WLSIZE), sizeof *wlist, workcmpf); 3924632Seric 3934632Seric /* 3944632Seric ** Convert the work list into canonical form. 3959377Seric ** Should be turning it into a list of envelopes here perhaps. 3964632Seric */ 3974632Seric 3984632Seric wp = &WorkQ; 39910121Seric for (i = min(wn, WLSIZE); --i >= 0; ) 4004632Seric { 4014632Seric w = (WORK *) xalloc(sizeof *w); 4024632Seric w->w_name = wlist[i].w_name; 4034632Seric w->w_pri = wlist[i].w_pri; 4044632Seric w->w_next = NULL; 4054632Seric *wp = w; 4064632Seric wp = &w->w_next; 4074632Seric } 4084632Seric 4094632Seric # ifdef DEBUG 4107677Seric if (tTd(40, 1)) 4114632Seric { 4124632Seric for (w = WorkQ; w != NULL; w = w->w_next) 4135037Seric printf("%32s: pri=%ld\n", w->w_name, w->w_pri); 4144632Seric } 4154632Seric # endif DEBUG 41610070Seric 41710090Seric return (wn); 4184632Seric } 4194632Seric /* 4207677Seric ** WORKCMPF -- compare function for ordering work. 4214632Seric ** 4224632Seric ** Parameters: 4234632Seric ** a -- the first argument. 4244632Seric ** b -- the second argument. 4254632Seric ** 4264632Seric ** Returns: 42710121Seric ** 1 if a < b 4284632Seric ** 0 if a == b 42910121Seric ** -1 if a > b 4304632Seric ** 4314632Seric ** Side Effects: 4324632Seric ** none. 4334632Seric */ 4344632Seric 4354632Seric workcmpf(a, b) 4365037Seric register WORK *a; 4375037Seric register WORK *b; 4384632Seric { 4395037Seric if (a->w_pri == b->w_pri) 4404632Seric return (0); 4415037Seric else if (a->w_pri > b->w_pri) 44210121Seric return (-1); 44310121Seric else 4444632Seric return (1); 4454632Seric } 4464632Seric /* 4474632Seric ** DOWORK -- do a work request. 4484632Seric ** 4494632Seric ** Parameters: 4504632Seric ** w -- the work request to be satisfied. 4514632Seric ** 4524632Seric ** Returns: 4534632Seric ** none. 4544632Seric ** 4554632Seric ** Side Effects: 4564632Seric ** The work request is satisfied if possible. 4574632Seric */ 4584632Seric 4594632Seric dowork(w) 4604632Seric register WORK *w; 4614632Seric { 4624632Seric register int i; 4634632Seric 4644632Seric # ifdef DEBUG 4657677Seric if (tTd(40, 1)) 4665037Seric printf("dowork: %s pri %ld\n", w->w_name, w->w_pri); 4674632Seric # endif DEBUG 4684632Seric 4694632Seric /* 4704632Seric ** Fork for work. 4714632Seric */ 4724632Seric 4734632Seric i = fork(); 4744632Seric if (i < 0) 4754632Seric { 4764632Seric syserr("dowork: cannot fork"); 4774632Seric return; 4784632Seric } 4794632Seric 4804632Seric if (i == 0) 4814632Seric { 4824632Seric /* 4834632Seric ** CHILD 4848148Seric ** Lock the control file to avoid duplicate deliveries. 4858148Seric ** Then run the file as though we had just read it. 4867350Seric ** We save an idea of the temporary name so we 4877350Seric ** can recover on interrupt. 4884632Seric */ 4894632Seric 4907763Seric /* set basic modes, etc. */ 4917356Seric (void) alarm(0); 49210195Seric closexscript(CurEnv); 4939338Seric CurEnv->e_flags &= ~EF_FATALERRS; 4944632Seric QueueRun = TRUE; 4959377Seric ErrorMode = EM_MAIL; 4968148Seric CurEnv->e_id = &w->w_name[2]; 4977876Seric # ifdef LOG 4987876Seric if (LogLevel > 11) 4997881Seric syslog(LOG_DEBUG, "%s: dowork, pid=%d", CurEnv->e_id, 5007881Seric getpid()); 5017876Seric # endif LOG 5027763Seric 5037763Seric /* don't use the headers from sendmail.cf... */ 5047763Seric CurEnv->e_header = NULL; 5057763Seric 5067763Seric /* create the link to the control file during processing */ 5077812Seric if (link(w->w_name, queuename(CurEnv, 'l')) < 0) 5086980Seric { 5097812Seric /* being processed by another queuer */ 5107881Seric # ifdef LOG 5117881Seric if (LogLevel > 4) 5127881Seric syslog(LOG_DEBUG, "%s: locked", CurEnv->e_id); 5137881Seric # endif LOG 5146980Seric exit(EX_OK); 5156980Seric } 5166980Seric 5176980Seric /* do basic system initialization */ 5184632Seric initsys(); 5196980Seric 5206980Seric /* read the queue control file */ 5219630Seric readqf(CurEnv, TRUE); 5229338Seric CurEnv->e_flags |= EF_INQUEUE; 5239377Seric eatheader(CurEnv); 5246980Seric 5256980Seric /* do the delivery */ 5269338Seric if (!bitset(EF_FATALERRS, CurEnv->e_flags)) 5279282Seric sendall(CurEnv, SM_DELIVER); 5286980Seric 5296980Seric /* finish up and exit */ 5304632Seric finis(); 5314632Seric } 5324632Seric 5334632Seric /* 5344632Seric ** Parent -- pick up results. 5354632Seric */ 5364632Seric 5374632Seric errno = 0; 5389377Seric (void) waitfor(i); 5394632Seric } 5404632Seric /* 5414632Seric ** READQF -- read queue file and set up environment. 5424632Seric ** 5434632Seric ** Parameters: 5449377Seric ** e -- the envelope of the job to run. 5459630Seric ** full -- if set, read in all information. Otherwise just 5469630Seric ** read in info needed for a queue print. 5474632Seric ** 5484632Seric ** Returns: 5494632Seric ** none. 5504632Seric ** 5514632Seric ** Side Effects: 5524632Seric ** cf is read and created as the current job, as though 5534632Seric ** we had been invoked by argument. 5544632Seric */ 5554632Seric 5569630Seric readqf(e, full) 5579377Seric register ENVELOPE *e; 5589630Seric bool full; 5594632Seric { 5604632Seric register FILE *f; 5617785Seric char buf[MAXFIELD]; 5629348Seric extern char *fgetfolded(); 5639377Seric register char *p; 5644632Seric 5654632Seric /* 5664632Seric ** Open the file created by queueup. 5674632Seric */ 5684632Seric 5699377Seric p = queuename(e, 'q'); 5709377Seric f = fopen(p, "r"); 5714632Seric if (f == NULL) 5724632Seric { 5739377Seric syserr("readqf: no control file %s", p); 5744632Seric return; 5754632Seric } 5769377Seric FileName = p; 5779377Seric LineNumber = 0; 5784632Seric 5794632Seric /* 5804632Seric ** Read and process the file. 5814632Seric */ 5824632Seric 5839630Seric if (Verbose && full) 5849377Seric printf("\nRunning %s\n", e->e_id); 5857785Seric while (fgetfolded(buf, sizeof buf, f) != NULL) 5864632Seric { 5874632Seric switch (buf[0]) 5884632Seric { 5894632Seric case 'R': /* specify recipient */ 5909618Seric sendtolist(&buf[1], (ADDRESS *) NULL, &e->e_sendqueue); 5914632Seric break; 5924632Seric 5934632Seric case 'H': /* header */ 5949630Seric if (full) 5959630Seric (void) chompheader(&buf[1], FALSE); 5964632Seric break; 5974632Seric 59810108Seric case 'M': /* message */ 59910108Seric e->e_message = newstr(&buf[1]); 60010108Seric break; 60110108Seric 6024632Seric case 'S': /* sender */ 6034634Seric setsender(newstr(&buf[1])); 6044632Seric break; 6054632Seric 6064632Seric case 'D': /* data file name */ 6079630Seric if (!full) 6089630Seric break; 6099377Seric e->e_df = newstr(&buf[1]); 6109544Seric e->e_dfp = fopen(e->e_df, "r"); 6119544Seric if (e->e_dfp == NULL) 6129377Seric syserr("readqf: cannot open %s", e->e_df); 6134632Seric break; 6144632Seric 6157860Seric case 'T': /* init time */ 6169377Seric (void) sscanf(&buf[1], "%ld", &e->e_ctime); 6174632Seric break; 6184632Seric 6194634Seric case 'P': /* message priority */ 6209377Seric (void) sscanf(&buf[1], "%ld", &e->e_msgpriority); 6215037Seric 6225037Seric /* make sure that big things get sent eventually */ 6239377Seric e->e_msgpriority -= WKTIMEFACT; 6244634Seric break; 6254634Seric 6264632Seric default: 6279377Seric syserr("readqf(%s): bad line \"%s\"", e->e_id, buf); 6284632Seric break; 6294632Seric } 6304632Seric } 6319377Seric 6329377Seric FileName = NULL; 6334632Seric } 6344632Seric /* 6359630Seric ** PRINTQUEUE -- print out a representation of the mail queue 6369630Seric ** 6379630Seric ** Parameters: 6389630Seric ** none. 6399630Seric ** 6409630Seric ** Returns: 6419630Seric ** none. 6429630Seric ** 6439630Seric ** Side Effects: 6449630Seric ** Prints a listing of the mail queue on the standard output. 6459630Seric */ 6465182Seric 6479630Seric printqueue() 6489630Seric { 6499630Seric register WORK *w; 6509630Seric FILE *f; 65110070Seric int nrequests; 6529630Seric char buf[MAXLINE]; 6539630Seric 6549630Seric /* 6559630Seric ** Read and order the queue. 6569630Seric */ 6579630Seric 65810070Seric nrequests = orderq(); 6599630Seric 6609630Seric /* 6619630Seric ** Print the work list that we have read. 6629630Seric */ 6639630Seric 6649630Seric /* first see if there is anything */ 66510070Seric if (nrequests <= 0) 6669630Seric { 66710070Seric printf("Mail queue is empty\n"); 6689630Seric return; 6699630Seric } 6709630Seric 67110096Seric printf("\t\tMail Queue (%d request%s", nrequests, nrequests == 1 ? "" : "s"); 67210070Seric if (nrequests > WLSIZE) 67310070Seric printf(", only %d printed", WLSIZE); 67410070Seric printf(")\n--QID-- --Size-- -----Q-Time----- ------------Sender/Recipient------------\n"); 6759630Seric for (w = WorkQ; w != NULL; w = w->w_next) 6769630Seric { 6779630Seric struct stat st; 67810070Seric auto time_t submittime = 0; 67910070Seric long dfsize = -1; 68010108Seric char lf[20]; 68110108Seric char message[MAXLINE]; 6829630Seric 6839630Seric printf("%7s", w->w_name + 2); 68410070Seric strcpy(lf, w->w_name); 68510070Seric lf[0] = 'l'; 68610070Seric if (stat(lf, &st) >= 0) 68710070Seric printf("*"); 68810070Seric else 68910070Seric printf(" "); 69010070Seric errno = 0; 6919630Seric f = fopen(w->w_name, "r"); 6929630Seric if (f == NULL) 6939630Seric { 6949630Seric printf(" (finished)\n"); 69510070Seric errno = 0; 6969630Seric continue; 6979630Seric } 69810108Seric message[0] = '\0'; 6999630Seric while (fgets(buf, sizeof buf, f) != NULL) 7009630Seric { 7019630Seric fixcrlf(buf, TRUE); 7029630Seric switch (buf[0]) 7039630Seric { 70410108Seric case 'M': /* error message */ 70510108Seric strcpy(message, &buf[1]); 70610108Seric break; 70710108Seric 7089630Seric case 'S': /* sender name */ 709*13015Seric printf("%8ld %.16s %.45s", dfsize, 71012517Seric ctime(&submittime), &buf[1]); 71110108Seric if (message[0] != '\0') 71212517Seric printf("\n\t\t\t\t (%.43s)", message); 7139630Seric break; 7149630Seric 7159630Seric case 'R': /* recipient name */ 71612517Seric printf("\n\t\t\t\t %.45s", &buf[1]); 7179630Seric break; 7189630Seric 7199630Seric case 'T': /* creation time */ 72010070Seric sscanf(&buf[1], "%ld", &submittime); 7219630Seric break; 72210070Seric 72310070Seric case 'D': /* data file name */ 72410070Seric if (stat(&buf[1], &st) >= 0) 72510070Seric dfsize = st.st_size; 72610070Seric break; 7279630Seric } 7289630Seric } 72910070Seric if (submittime == (time_t) 0) 73010070Seric printf(" (no control file)"); 7319630Seric printf("\n"); 7329630Seric fclose(f); 7339630Seric } 7349630Seric } 7359630Seric 7365182Seric # endif QUEUE 737