[BACK]Return to io.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / calendar

Diff for /src/usr.bin/calendar/io.c between version 1.10 and 1.13

version 1.10, 2000/12/07 19:36:37 version 1.13, 2001/09/03 15:53:00
Line 70 
Line 70 
 #include "calendar.h"  #include "calendar.h"
   
   
 char *calendarFile = "calendar";  /* default calendar file */  
 char *calendarHome = ".calendar"; /* HOME */  
 char *calendarNoMail = "nomail";  /* don't sent mail if this file exist */  
   
 struct iovec header[] = {  struct iovec header[] = {
         {"From: ", 6},          {"From: ", 6},
         {NULL, 0},          {NULL, 0},
Line 127 
Line 123 
                                 if (spev[i].uname != NULL)                                  if (spev[i].uname != NULL)
                                         free(spev[i].uname);                                          free(spev[i].uname);
                                 if ((spev[i].uname = strdup(p)) == NULL)                                  if ((spev[i].uname = strdup(p)) == NULL)
                                         errx(1, "cannot allocate memory");                                          err(1, NULL);
                                 spev[i].ulen = strlen(p);                                  spev[i].ulen = strlen(p);
                                 i = NUMEV + 1;                                  i = NUMEV + 1;
                         }                          }
Line 154 
Line 150 
                                 while (m) {                                  while (m) {
                                 cur_evt = (struct event *) malloc(sizeof(struct event));                                  cur_evt = (struct event *) malloc(sizeof(struct event));
                                 if (cur_evt == NULL)                                  if (cur_evt == NULL)
                                         errx(1, "cannot allocate memory");                                          err(1, NULL);
   
                                 cur_evt->when = m->when;                                  cur_evt->when = m->when;
                                 snprintf(cur_evt->print_date,                                  snprintf(cur_evt->print_date,
Line 165 
Line 161 
                                         cur_evt->ldesc = NULL;                                          cur_evt->ldesc = NULL;
                                 } else {                                  } else {
                                         if ((cur_evt->ldesc = strdup(p)) == NULL)                                          if ((cur_evt->ldesc = strdup(p)) == NULL)
                                                 errx(1, "cannot allocate memory");                                                  err(1, NULL);
                                         cur_evt->desc = &(cur_evt->ldesc);                                          cur_evt->desc = &(cur_evt->ldesc);
                                         ev1 = cur_evt;                                          ev1 = cur_evt;
                                 }                                  }
Line 179 
Line 175 
                 else if (printing) {                  else if (printing) {
                         if ((ev1->ldesc = realloc(ev1->ldesc,                          if ((ev1->ldesc = realloc(ev1->ldesc,
                             (2 + strlen(ev1->ldesc) + strlen(buf)))) == NULL)                              (2 + strlen(ev1->ldesc) + strlen(buf)))) == NULL)
                                 errx(1, "cannot allocate memory");                                  err(1, NULL);
                         strcat(ev1->ldesc, "\n");                          strcat(ev1->ldesc, "\n");
                         strcat(ev1->ldesc, buf);                          strcat(ev1->ldesc, buf);
                 }                  }
Line 321 
Line 317 
 FILE *  FILE *
 opencal()  opencal()
 {  {
         int fd, pdes[2];          int pdes[2];
         int fdin;          int fdin;
         struct stat sbuf;  
   
         /* open up calendar file as stdin */          /* open up calendar file as stdin */
         if ((fdin = openf(calendarFile)) == -1) {          if ((fdin = openf(calendarFile)) == -1) {
                 if (doall) {                  if (!doall) {
                         if (chdir(calendarHome) != 0)  
                                 return (NULL);  
                         if (stat(calendarNoMail, &sbuf) == 0)  
                                 return (NULL);  
                         if ((fdin = openf(calendarFile)) == -1)  
                                 return (NULL);  
                 } else {  
                         char *home = getenv("HOME");                          char *home = getenv("HOME");
                         if (home == NULL || *home == '\0')                          if (home == NULL || *home == '\0')
                                 errx(1, "cannot get home directory");                                  errx(1, "cannot get home directory");
Line 360 
Line 348 
                         (void)close(pdes[1]);                          (void)close(pdes[1]);
                 }                  }
                 (void)close(pdes[0]);                  (void)close(pdes[0]);
                 (void)setuid(geteuid());                  /* Set stderr to /dev/null.  Necessary so that cron does not
                 (void)setgid(getegid());                   * wait for cpp to finish if it's running calendar -a.
                 execl(_PATH_CPP, "cpp", "-P", "-I.", _PATH_INCLUDE, NULL);                   */
                   if (doall) {
                           int fderr;
                           fderr = open(_PATH_DEVNULL, O_WRONLY, 0);
                           if (fderr == -1)
                                   _exit(0);
                           (void)dup2(fderr, STDERR_FILENO);
                           (void)close(fderr);
                   }
                   execl(_PATH_CPP, "cpp", "-P", "-I.", _PATH_INCLUDE, (char *)NULL);
                 warn(_PATH_CPP);                  warn(_PATH_CPP);
                 _exit(1);                  _exit(1);
         }          }
Line 376 
Line 373 
                 return (stdout);                  return (stdout);
   
         /* set output to a temporary file, so if no output don't send mail */          /* set output to a temporary file, so if no output don't send mail */
         (void)snprintf(path, sizeof(path), "%s/_calXXXXXX", _PATH_TMP);          return(tmpfile());
         if ((fd = mkstemp(path)) < 0)  
                 return (NULL);  
         return (fdopen(fd, "w+"));  
 }  }
   
 void  void
Line 410 
Line 404 
                         (void)close(pdes[0]);                          (void)close(pdes[0]);
                 }                  }
                 (void)close(pdes[1]);                  (void)close(pdes[1]);
                 (void)setuid(geteuid());  
                 (void)setgid(getegid());  
                 execl(_PATH_SENDMAIL, "sendmail", "-i", "-t", "-F",                  execl(_PATH_SENDMAIL, "sendmail", "-i", "-t", "-F",
                     "\"Reminder Service\"", NULL);                      "\"Reminder Service\"", (char *)NULL);
                 warn(_PATH_SENDMAIL);                  warn(_PATH_SENDMAIL);
                 _exit(1);                  _exit(1);
         }          }
Line 427 
Line 419 
                 (void)write(pdes[1], buf, nread);                  (void)write(pdes[1], buf, nread);
         (void)close(pdes[1]);          (void)close(pdes[1]);
 done:   (void)fclose(fp);  done:   (void)fclose(fp);
         (void)unlink(path);  
         while (wait(&status) >= 0)          while (wait(&status) >= 0)
                 ;                  ;
 }  }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.13