=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/calendar/io.c,v retrieving revision 1.10 retrieving revision 1.13 diff -u -r1.10 -r1.13 --- src/usr.bin/calendar/io.c 2000/12/07 19:36:37 1.10 +++ src/usr.bin/calendar/io.c 2001/09/03 15:53:00 1.13 @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.10 2000/12/07 19:36:37 deraadt Exp $ */ +/* $OpenBSD: io.c,v 1.13 2001/09/03 15:53:00 pjanzen Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -43,7 +43,7 @@ #if 0 static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; #else -static char rcsid[] = "$OpenBSD: io.c,v 1.10 2000/12/07 19:36:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: io.c,v 1.13 2001/09/03 15:53:00 pjanzen Exp $"; #endif #endif /* not lint */ @@ -70,10 +70,6 @@ #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[] = { {"From: ", 6}, {NULL, 0}, @@ -127,7 +123,7 @@ if (spev[i].uname != NULL) free(spev[i].uname); if ((spev[i].uname = strdup(p)) == NULL) - errx(1, "cannot allocate memory"); + err(1, NULL); spev[i].ulen = strlen(p); i = NUMEV + 1; } @@ -154,7 +150,7 @@ while (m) { cur_evt = (struct event *) malloc(sizeof(struct event)); if (cur_evt == NULL) - errx(1, "cannot allocate memory"); + err(1, NULL); cur_evt->when = m->when; snprintf(cur_evt->print_date, @@ -165,7 +161,7 @@ cur_evt->ldesc = NULL; } else { if ((cur_evt->ldesc = strdup(p)) == NULL) - errx(1, "cannot allocate memory"); + err(1, NULL); cur_evt->desc = &(cur_evt->ldesc); ev1 = cur_evt; } @@ -179,7 +175,7 @@ else if (printing) { if ((ev1->ldesc = realloc(ev1->ldesc, (2 + strlen(ev1->ldesc) + strlen(buf)))) == NULL) - errx(1, "cannot allocate memory"); + err(1, NULL); strcat(ev1->ldesc, "\n"); strcat(ev1->ldesc, buf); } @@ -321,20 +317,12 @@ FILE * opencal() { - int fd, pdes[2]; + int pdes[2]; int fdin; - struct stat sbuf; /* open up calendar file as stdin */ if ((fdin = openf(calendarFile)) == -1) { - if (doall) { - if (chdir(calendarHome) != 0) - return (NULL); - if (stat(calendarNoMail, &sbuf) == 0) - return (NULL); - if ((fdin = openf(calendarFile)) == -1) - return (NULL); - } else { + if (!doall) { char *home = getenv("HOME"); if (home == NULL || *home == '\0') errx(1, "cannot get home directory"); @@ -360,9 +348,18 @@ (void)close(pdes[1]); } (void)close(pdes[0]); - (void)setuid(geteuid()); - (void)setgid(getegid()); - execl(_PATH_CPP, "cpp", "-P", "-I.", _PATH_INCLUDE, NULL); + /* Set stderr to /dev/null. Necessary so that cron does not + * 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); warn(_PATH_CPP); _exit(1); } @@ -376,10 +373,7 @@ return (stdout); /* set output to a temporary file, so if no output don't send mail */ - (void)snprintf(path, sizeof(path), "%s/_calXXXXXX", _PATH_TMP); - if ((fd = mkstemp(path)) < 0) - return (NULL); - return (fdopen(fd, "w+")); + return(tmpfile()); } void @@ -410,10 +404,8 @@ (void)close(pdes[0]); } (void)close(pdes[1]); - (void)setuid(geteuid()); - (void)setgid(getegid()); execl(_PATH_SENDMAIL, "sendmail", "-i", "-t", "-F", - "\"Reminder Service\"", NULL); + "\"Reminder Service\"", (char *)NULL); warn(_PATH_SENDMAIL); _exit(1); } @@ -427,7 +419,6 @@ (void)write(pdes[1], buf, nread); (void)close(pdes[1]); done: (void)fclose(fp); - (void)unlink(path); while (wait(&status) >= 0) ; }