[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.12 and 1.13

version 1.12, 2001/07/09 07:04:48 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 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.
                    */
                   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);                  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\"", (char *)NULL);                      "\"Reminder Service\"", (char *)NULL);
                 warn(_PATH_SENDMAIL);                  warn(_PATH_SENDMAIL);
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.12  
changed lines
  Added in v.1.13