=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/calendar/calendar.c,v retrieving revision 1.25 retrieving revision 1.31 diff -u -r1.25 -r1.31 --- src/usr.bin/calendar/calendar.c 2005/11/16 16:45:11 1.25 +++ src/usr.bin/calendar/calendar.c 2015/04/18 18:28:37 1.31 @@ -1,4 +1,4 @@ -/* $OpenBSD: calendar.c,v 1.25 2005/11/16 16:45:11 deraadt Exp $ */ +/* $OpenBSD: calendar.c,v 1.31 2015/04/18 18:28:37 deraadt 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" @@ -83,6 +69,7 @@ main(int argc, char *argv[]) { int ch; + const char *errstr; char *caldir; (void)setlocale(LC_ALL, ""); @@ -97,7 +84,7 @@ break; case 'b': - bodun_always++; + bodun_always = 1; break; case 'f': /* other calendar file */ @@ -110,12 +97,16 @@ 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; default: @@ -183,6 +174,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)) @@ -228,7 +220,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) @@ -260,7 +255,7 @@ { (void)fprintf(stderr, "usage: calendar [-ab] [-A num] [-B num] [-f calendarfile] " - "[-t [[[cc]yy][mm]]dd]\n"); + "[-t [[[cc]yy]mm]dd]\n"); exit(1); }