1: 
   2: #include "remind.h"
   3: char *notemp    = "Unable to create /rmd/rmdtemp. Remind is dead.";
   4: 
   5: enqueue()
   6: {
   7:     register int slptime = 0;
   8:     register i;
   9:     register FILE *pf;
  10:     FILE *rem, *temp;
  11:     int procid;
  12:     time_t now;
  13:     char endrem, written;
  14:     struct rmdblock mm;
  15:     char rmddata[8*MAXRCVRS + MAXMSG + DIRSIZE];
  16:     struct passwd *pw;
  17: 
  18: #ifndef DEBUG
  19:     signal(SIGINT,SIG_IGN);          /* Ignore Interrupts */
  20:     signal(SIGQUIT,SIG_IGN);          /* Ignore Quits */
  21:     signal(SIGTERM,SIG_IGN);          /* Ignore Termination */
  22: #endif DEBUG
  23: 
  24:     /* Wait for file to be usable */
  25:     lock();
  26: 
  27:     /* Kill any existing reminder process that may be "sleeping" */
  28:     if ((pf = fopen(rmdproc,"r")) != NULL)
  29:     {
  30:         if(fscanf(pf,"%d",&procid)<= 0)
  31:             error("/rmd/rmdproc unreadable");
  32:         fclose(pf);
  33:         kill (procid,9);
  34:     }
  35:     if((pf=fopen(rmdproc,"w"))==NULL)
  36:     {
  37:         fprintf(stderr,"remind: cannot open %s for writing\n",rmdproc);
  38:         error("");
  39:     }
  40: 
  41:     procid = getpid();
  42:     fprintf(pf,"%d\n",procid);
  43:     fclose(pf);
  44: 
  45:     /* Put new reminder into reminder file (temp) in delivery order */
  46:     if ((rem=fopen(reminders,"r"))==NULL)
  47:     {
  48:         endrem = -1;
  49:         mm.tdeliver = -1L;
  50:     }
  51:     else
  52:         endrem = (fread((char *)&mm, sizeof mm, 1, rem) != 1);
  53:     if ((slptime = tdiff(&m.tdeliver,&m.tsent))
  54:         > (i = tdiff(&mm.tdeliver,&m.tsent)))
  55:             slptime = i;
  56:     if ((temp = fopen(rmdtemp,"w")) == NULL)
  57:         error (notemp);
  58:     else
  59:         if(chmod(rmdtemp,0600) < 0)
  60:             error("Cannot chmod");
  61: 
  62:     for (written = 0;;)
  63:     {       if (!endrem &&
  64:             (written||(tdiff(&mm.tdeliver, &m.tdeliver) <= 0)))
  65:         {
  66:             fwrite ((char *)&mm, sizeof mm, 1, temp);
  67:             fread (rmddata, mm.nobytes,1,rem);
  68:             fwrite (rmddata, mm.nobytes, 1, temp);
  69:             endrem = (fread((char *)&mm, sizeof mm, 1, rem) != 1);
  70:         }
  71:         else if (!written)
  72:         {
  73:             fwrite ((char *)&m, sizeof m, 1, temp);
  74:             fwrite ((char *)rcvrlist, 8*m.nrcvrs, 1, temp);
  75:             if (m.dirsize)
  76:                 fwrite (exdir, m.dirsize&0377, 1, temp);
  77:             fwrite (msg, m.msgbytes, 1, temp);
  78:             written++;
  79:         }
  80:         else break;
  81:     }
  82:     fclose (temp);
  83:     if(rem)
  84:         fclose (rem);
  85:     /*
  86: 	 * Dummy all std files
  87: 	 */
  88:     freopen(dummy,"r",stdin);
  89:     freopen(dummy,"w",stdout);
  90:     freopen(dummy,"w",stderr);
  91:     cleanup();
  92: 
  93:     for (;;)
  94:     {   if (slptime > 0)
  95:             sleep(slptime);
  96:         lock();
  97:         now = time((time_t *)0);
  98:         if ((rem = fopen(reminders,"r")) == NULL)
  99:             bye();
 100:         do
 101:         {       if (fread((char *)&m, sizeof m, 1, rem) != 1)
 102:                 bye();
 103:             if((pw=getpwnam(m.sender))==NULL)
 104:             {
 105:                 fprintf(stderr,"Unknown user: %s\n",m.sender);
 106:                 Uid = -1;
 107:             }
 108:             else
 109:                 Uid = pw->pw_uid;
 110:             if ((slptime = tdiff(&m.tdeliver, &now)) <= 0)
 111:             {
 112:                 fread ((char *)rcvrlist, 8*m.nrcvrs, 1, rem);
 113:                 if (m.dirsize)
 114:                     fread(exdir, m.dirsize&0377, 1, rem);
 115:                 fread (msg, m.msgbytes, 1, rem);
 116:                 if (spawn() == 0)
 117:                 {   fclose(rem);
 118:                     deliver(); /* Child delivers */
 119:                 }
 120:             }
 121:         } while (slptime <= 0);
 122: 
 123:         /* Copy, removing delivered messages */
 124:         if ((temp = fopen(rmdtemp,"w")) == NULL)
 125:             bye();
 126:         else
 127:             chmod(rmdtemp,0600);
 128:         do
 129:         {
 130:             fread (rmddata, m.nobytes, 1, rem);
 131:             fwrite ((char *)&m, sizeof m, 1, temp);
 132:             fwrite (rmddata, m.nobytes, 1, temp);
 133:         } while (fread((char *)&m, sizeof m, 1, rem) == 1);
 134:         fclose (rem);
 135:         fclose (temp);
 136:         cleanup();
 137:     }
 138: }

Defined functions

enqueue defined in line 5; used 1 times

Defined variables

notemp defined in line 3; used 1 times
  • in line 57
Last modified: 1981-09-28
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 961
Valid CSS Valid XHTML 1.0 Strict