version 1.6, 1998/12/13 07:31:08 |
version 1.10, 2000/12/07 19:36:37 |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/uio.h> |
#include <sys/uio.h> |
#include <sys/wait.h> |
#include <sys/wait.h> |
|
#include <sys/file.h> |
|
|
#include <ctype.h> |
#include <ctype.h> |
#include <err.h> |
#include <err.h> |
|
|
}; |
}; |
|
|
|
|
|
int openf(char *path); |
|
|
void |
void |
cal() |
cal() |
{ |
{ |
|
|
*p = '\0'; |
*p = '\0'; |
else |
else |
while ((ch = getchar()) != '\n' && ch != EOF); |
while ((ch = getchar()) != '\n' && ch != EOF); |
for (l = strlen(buf); |
for (l = strlen(buf); l > 0 && isspace(buf[l - 1]); l--) |
l > 0 && isspace(buf[l - 1]); |
|
l--) |
|
; |
; |
buf[l] = '\0'; |
buf[l] = '\0'; |
if (buf[0] == '\0') |
if (buf[0] == '\0') |
|
|
int val, var, i; |
int val, var, i; |
char *start, savech; |
char *start, savech; |
|
|
for (; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p) |
for (; !isdigit(*p) && !isalpha(*p) && *p != '*' && *p != '\t'; ++p) |
; |
; |
if (*p == '*') { /* `*' is every month */ |
if (*p == '*') { /* `*' is every month */ |
*flags |= F_ISMONTH; |
*flags |= F_ISMONTH; |
|
|
return (0); |
return (0); |
} |
} |
} |
} |
for (*p = savech; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p) |
for (*p = savech; !isdigit(*p) && !isalpha(*p) && *p != '*' && *p != '\t'; ++p) |
; |
; |
*endp = p; |
*endp = p; |
return (val); |
return (val); |
|
|
|
|
char path[MAXPATHLEN]; |
char path[MAXPATHLEN]; |
|
|
|
int |
|
openf(path) |
|
char *path; |
|
{ |
|
struct stat st; |
|
int fd; |
|
|
|
fd = open(path, O_RDONLY|O_NONBLOCK); |
|
if (fd == -1) |
|
return (-1); |
|
if (fstat(fd, &st) == -1) { |
|
close(fd); |
|
return (-1); |
|
} |
|
if ((st.st_mode & S_IFMT) != S_IFREG) { |
|
close (fd); |
|
return (-1); |
|
} |
|
|
|
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) &~ O_NONBLOCK); |
|
return (fd); |
|
} |
|
|
FILE * |
FILE * |
opencal() |
opencal() |
{ |
{ |
int fd, pdes[2]; |
int fd, pdes[2]; |
|
int fdin; |
struct stat sbuf; |
struct stat sbuf; |
|
|
/* open up calendar file as stdin */ |
/* open up calendar file as stdin */ |
if (!freopen(calendarFile, "r", stdin)) { |
if ((fdin = openf(calendarFile)) == -1) { |
if (doall) { |
if (doall) { |
if (chdir(calendarHome) != 0) |
if (chdir(calendarHome) != 0) |
return (NULL); |
return (NULL); |
if (stat(calendarNoMail, &sbuf) == 0) |
if (stat(calendarNoMail, &sbuf) == 0) |
return (NULL); |
return (NULL); |
if (!freopen(calendarFile, "r", stdin)) |
if ((fdin = openf(calendarFile)) == -1) |
return (NULL); |
return (NULL); |
} else { |
} else { |
chdir(getenv("HOME")); |
char *home = getenv("HOME"); |
if (!(chdir(calendarHome) == 0 && |
if (home == NULL || *home == '\0') |
freopen(calendarFile, "r", stdin))) |
errx(1, "cannot get home directory"); |
|
if (!(chdir(home) == 0 && |
|
chdir(calendarHome) == 0 && |
|
(fdin = openf(calendarFile)) != -1)) |
errx(1, "no calendar file: ``%s'' or ``~/%s/%s", |
errx(1, "no calendar file: ``%s'' or ``~/%s/%s", |
calendarFile, calendarHome, calendarFile); |
calendarFile, calendarHome, calendarFile); |
} |
} |
|
|
(void)close(pdes[1]); |
(void)close(pdes[1]); |
return (NULL); |
return (NULL); |
case 0: |
case 0: |
/* child -- stdin already setup, set stdout to pipe input */ |
dup2(fdin, STDIN_FILENO); |
|
/* child -- set stdout to pipe input */ |
if (pdes[1] != STDOUT_FILENO) { |
if (pdes[1] != STDOUT_FILENO) { |
(void)dup2(pdes[1], STDOUT_FILENO); |
(void)dup2(pdes[1], STDOUT_FILENO); |
(void)close(pdes[1]); |
(void)close(pdes[1]); |
|
|
(void)setuid(geteuid()); |
(void)setuid(geteuid()); |
(void)setgid(getegid()); |
(void)setgid(getegid()); |
execl(_PATH_SENDMAIL, "sendmail", "-i", "-t", "-F", |
execl(_PATH_SENDMAIL, "sendmail", "-i", "-t", "-F", |
"\"Reminder Service\"", "-f", "root", NULL); |
"\"Reminder Service\"", NULL); |
warn(_PATH_SENDMAIL); |
warn(_PATH_SENDMAIL); |
_exit(1); |
_exit(1); |
} |
} |
|
|
(void)close(pdes[1]); |
(void)close(pdes[1]); |
done: (void)fclose(fp); |
done: (void)fclose(fp); |
(void)unlink(path); |
(void)unlink(path); |
while (wait(&status) >= 0); |
while (wait(&status) >= 0) |
|
; |
} |
} |
|
|
|
|