version 1.17, 2002/02/16 21:27:44 |
version 1.32, 2015/10/23 11:43:16 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* documentation and/or other materials provided with the distribution. |
* 3. All advertising materials mentioning features or use of this software |
* 3. Neither the name of the University nor the names of its contributors |
* must display the following acknowledgement: |
|
* This product includes software developed by the University of |
|
* California, Berkeley and its contributors. |
|
* 4. Neither the name of the University nor the names of its contributors |
|
* may be used to endorse or promote products derived from this software |
* may be used to endorse or promote products derived from this software |
* without specific prior written permission. |
* without specific prior written permission. |
* |
* |
|
|
* SUCH DAMAGE. |
* SUCH DAMAGE. |
*/ |
*/ |
|
|
#ifndef lint |
|
static const char copyright[] = |
|
"@(#) Copyright (c) 1989, 1993\n\ |
|
The Regents of the University of California. All rights reserved.\n"; |
|
#endif /* not lint */ |
|
|
|
#ifndef lint |
|
#if 0 |
|
static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; |
|
#else |
|
static char rcsid[] = "$OpenBSD$"; |
|
#endif |
|
#endif /* not lint */ |
|
|
|
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/wait.h> |
#include <sys/wait.h> |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <limits.h> |
#include <time.h> |
#include <time.h> |
#include <tzfile.h> |
|
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "pathnames.h" |
#include "pathnames.h" |
|
|
|
|
int f_dayAfter = 0; /* days after current date */ |
int f_dayAfter = 0; /* days after current date */ |
int f_dayBefore = 0; /* days before current date */ |
int f_dayBefore = 0; /* days before current date */ |
|
int f_SetdayAfter = 0; /* calendar invoked with -A */ |
|
|
struct specialev spev[NUMEV]; |
struct specialev spev[NUMEV]; |
|
|
void childsig(int); |
void childsig(int); |
|
|
int |
int |
main(argc, argv) |
main(int argc, char *argv[]) |
int argc; |
|
char *argv[]; |
|
{ |
{ |
int ch; |
int ch; |
|
const char *errstr; |
char *caldir; |
char *caldir; |
|
|
(void)setlocale(LC_ALL, ""); |
(void)setlocale(LC_ALL, ""); |
|
|
while ((ch = getopt(argc, argv, "-abf:t:A:B:")) != -1) |
while ((ch = getopt(argc, argv, "abf:t:A:B:-")) != -1) |
switch (ch) { |
switch (ch) { |
case '-': /* backward contemptible */ |
case '-': /* backward contemptible */ |
case 'a': |
case 'a': |
|
|
break; |
break; |
|
|
case 'b': |
case 'b': |
bodun_always++; |
bodun_always = 1; |
break; |
break; |
|
|
case 'f': /* other calendar file */ |
case 'f': /* other calendar file */ |
|
|
break; |
break; |
|
|
case 'A': /* days after current date */ |
case 'A': /* days after current date */ |
f_dayAfter = atoi(optarg); |
f_dayAfter = strtonum(optarg, 0, INT_MAX, &errstr); |
|
if (errstr) |
|
errx(1, "-A %s: %s", optarg, errstr); |
|
f_SetdayAfter = 1; |
break; |
break; |
|
|
case 'B': /* days before current date */ |
case 'B': /* days before current date */ |
f_dayBefore = atoi(optarg); |
f_dayBefore = strtonum(optarg, 0, INT_MAX, &errstr); |
|
if (errstr) |
|
errx(1, "-B %s: %s", optarg, errstr); |
break; |
break; |
|
|
default: |
default: |
|
|
warn("fork"); |
warn("fork"); |
continue; |
continue; |
case 0: /* child */ |
case 0: /* child */ |
|
(void)setpgid(getpid(), getpid()); |
(void)setlocale(LC_ALL, ""); |
(void)setlocale(LC_ALL, ""); |
if (setusercontext(NULL, pw, pw->pw_uid, |
if (setusercontext(NULL, pw, pw->pw_uid, |
LOGIN_SETALL ^ LOGIN_SETLOGIN)) |
LOGIN_SETALL ^ LOGIN_SETLOGIN)) |
err(1, "unable to set user context (uid %d)", |
err(1, "unable to set user context (uid %u)", |
(int)pw->pw_uid); |
pw->pw_uid); |
if (acstat) { |
if (acstat) { |
if (chdir(pw->pw_dir) || |
if (chdir(pw->pw_dir) || |
stat(calendarFile, &sbuf) != 0 || |
stat(calendarFile, &sbuf) != 0 || |
chdir(calendarHome) || |
chdir(calendarHome) || |
stat(calendarNoMail, &sbuf) == 0 || |
stat(calendarNoMail, &sbuf) == 0 || |
stat(calendarFile, &sbuf) != 0) |
stat(calendarFile, &sbuf) != 0) |
exit(0); |
exit(0); |
|
|
/* It doesn't _really_ matter if the kill fails, e.g. |
/* It doesn't _really_ matter if the kill fails, e.g. |
* if there's only a zombie now. |
* if there's only a zombie now. |
*/ |
*/ |
(void)kill(kid, SIGTERM); |
if (getpgid(kid) != getpgrp()) |
warnx("uid %d did not finish in time", (int)pw->pw_uid); |
(void)killpg(getpgid(kid), SIGTERM); |
|
else |
|
(void)kill(kid, SIGTERM); |
|
warnx("uid %u did not finish in time", pw->pw_uid); |
} |
} |
if (time(NULL) - t >= SECSPERDAY) |
if (time(NULL) - t >= SECSPERDAY) |
errx(2, "'calendar -a' took more than a day; stopped at uid %d", |
errx(2, "'calendar -a' took more than a day; " |
(int)pw->pw_uid); |
"stopped at uid %u", |
|
pw->pw_uid); |
} |
} |
for (;;) { |
for (;;) { |
deadkid = waitpid(-1, &kidstat, WNOHANG); |
deadkid = waitpid(-1, &kidstat, WNOHANG); |
|
|
runningkids--; |
runningkids--; |
} |
} |
if (runningkids) |
if (runningkids) |
warnx( |
warnx("%d child processes still running when " |
"%d child processes still running when 'calendar -a' finished", runningkids); |
"'calendar -a' finished", runningkids); |
} |
} else if ((caldir = getenv("CALENDAR_DIR")) != NULL) { |
else if ((caldir = getenv("CALENDAR_DIR")) != NULL) { |
|
if(!chdir(caldir)) |
if(!chdir(caldir)) |
cal(); |
cal(); |
} else |
} else |
|
|
|
|
|
|
void |
void |
usage() |
usage(void) |
{ |
{ |
(void)fprintf(stderr, |
(void)fprintf(stderr, |
"usage: calendar [-a] [-A num] [-b] [-B num] [-t [[[cc]yy][mm]]dd] " |
"usage: calendar [-ab] [-A num] [-B num] [-f calendarfile] " |
"[-f calendarfile]\n"); |
"[-t [[[cc]yy]mm]dd]\n"); |
exit(1); |
exit(1); |
} |
} |
|
|
|
|
void |
void |
childsig(sig) |
childsig(int signo) |
int sig; |
|
{ |
{ |
} |
} |