=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/calendar/calendar.c,v retrieving revision 1.25 retrieving revision 1.35 diff -u -r1.25 -r1.35 --- src/usr.bin/calendar/calendar.c 2005/11/16 16:45:11 1.25 +++ src/usr.bin/calendar/calendar.c 2015/12/07 18:46:35 1.35 @@ -1,4 +1,4 @@ -/* $OpenBSD: calendar.c,v 1.25 2005/11/16 16:45:11 deraadt Exp $ */ +/* $OpenBSD: calendar.c,v 1.35 2015/12/07 18:46:35 espie Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -29,20 +29,6 @@ * 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 const char rcsid[] = "$OpenBSD: calendar.c,v 1.25 2005/11/16 16:45:11 deraadt Exp $"; -#endif -#endif /* not lint */ - #include #include #include @@ -55,8 +41,8 @@ #include #include #include +#include #include -#include #include #include "pathnames.h" @@ -68,6 +54,7 @@ struct passwd *pw; int doall = 0; +int daynames = 0; time_t f_time = 0; int bodun_always = 0; @@ -83,11 +70,12 @@ main(int argc, char *argv[]) { int ch; + const char *errstr; char *caldir; (void)setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "abf:t:A:B:-")) != -1) + while ((ch = getopt(argc, argv, "abwf:t:A:B:-")) != -1) switch (ch) { case '-': /* backward contemptible */ case 'a': @@ -97,7 +85,7 @@ break; case 'b': - bodun_always++; + bodun_always = 1; break; case 'f': /* other calendar file */ @@ -110,14 +98,22 @@ break; 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; 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; + case 'w': + daynames = 1; + break; + default: usage(); } @@ -127,6 +123,15 @@ if (argc) usage(); + if (doall) { + if (pledge("stdio rpath tmppath fattr getpw id proc exec", NULL) + == -1) + err(1, "pledge"); + } else { + if (pledge("stdio rpath proc exec", NULL) == -1) + err(1, "pledge"); + } + /* use current time */ if (f_time <= 0) (void)time(&f_time); @@ -183,6 +188,7 @@ warn("fork"); continue; case 0: /* child */ + (void)setpgid(getpid(), getpid()); (void)setlocale(LC_ALL, ""); if (setusercontext(NULL, pw, pw->pw_uid, LOGIN_SETALL ^ LOGIN_SETLOGIN)) @@ -191,7 +197,7 @@ if (acstat) { if (chdir(pw->pw_dir) || stat(calendarFile, &sbuf) != 0 || - chdir(calendarHome) || + chdir(calendarHome) || stat(calendarNoMail, &sbuf) == 0 || stat(calendarFile, &sbuf) != 0) exit(0); @@ -228,7 +234,10 @@ /* It doesn't _really_ matter if the kill fails, e.g. * if there's only a zombie now. */ - (void)kill(kid, SIGTERM); + if (getpgid(kid) != getpgrp()) + (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) @@ -259,8 +268,8 @@ usage(void) { (void)fprintf(stderr, - "usage: calendar [-ab] [-A num] [-B num] [-f calendarfile] " - "[-t [[[cc]yy][mm]]dd]\n"); + "usage: calendar [-abw] [-A num] [-B num] [-f calendarfile] " + "[-t [[[cc]yy]mm]dd]\n"); exit(1); }