Date: Tue, 24 Apr 2001 03:51:16 -0700 From: Kris Kennaway <kris@obsecurity.org> To: audit@FreeBSD.org Subject: More leave(1) syncing Message-ID: <20010424035116.A82401@xor.obsecurity.org>
next in thread | raw e-mail | index | archive | help
--n8g4imXOkfNTN/H1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable While I was in there, I synced up the rest of leave(1) with OpenBSD. The main change is that it handles 24-hour times better. Please review, and especially check cvs diff to make sure I didn't spam any previous FreeBSD fixes. Thanks. Kris Index: leave.1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/usr.bin/leave/leave.1,v retrieving revision 1.7 diff -u -r1.7 leave.1 --- leave.1 2001/02/06 16:20:31 1.7 +++ leave.1 2001/04/24 10:49:49 @@ -63,8 +63,8 @@ hours (on a 12 or 24 hour clock), and .Ar mm are minutes. -All times are converted to a 12 hour clock, and assumed to -be in the next 12 hours. +In ambiguous cases, times are converted to a 12 hour clock, +and assumed to be in the next 12 hours. .It Cm \&+ If the time is preceded by .Ql Cm \&+ , Index: leave.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/usr.bin/leave/leave.c,v retrieving revision 1.6 diff -u -r1.6 leave.c --- leave.c 2001/04/24 10:39:17 1.6 +++ leave.c 2001/04/24 10:49:49 @@ -42,7 +42,7 @@ static char sccsid[] =3D "@(#)leave.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] =3D - "$FreeBSD: src/usr.bin/leave/leave.c,v 1.6 2001/04/24 10:39:17 kris Exp = $"; + "$FreeBSD$"; #endif /* not lint */ =20 #include <err.h> @@ -70,9 +70,9 @@ register u_int secs; register int hours, minutes; register char c, *cp =3D NULL; - struct tm *t, *localtime(); - time_t now, time(); - int plusnow, t_12_hour; + struct tm *t =3D NULL; + time_t now; + int plusnow; char buf[50]; =20 if (setlocale(LC_TIME, "") =3D=3D NULL) @@ -80,7 +80,7 @@ =20 if (argc < 2) { #define MSG1 "When do you have to leave? " - (void)write(1, MSG1, sizeof(MSG1) - 1); + (void)write(STDOUT_FILENO, MSG1, sizeof(MSG1) - 1); cp =3D fgets(buf, sizeof(buf), stdin); if (cp =3D=3D NULL || *cp =3D=3D '\n') exit(0); @@ -92,8 +92,11 @@ if (*cp =3D=3D '+') { plusnow =3D 1; ++cp; - } else + } else { plusnow =3D 0; + (void)time(&now); + t =3D localtime(&now); + } =20 for (hours =3D 0; (c =3D *cp) && c !=3D '\n'; ++cp) { if (!isdigit(c)) @@ -108,30 +111,19 @@ if (plusnow) secs =3D hours * 60 * 60 + minutes * 60; else { - (void)time(&now); - t =3D localtime(&now); - if (hours > 23) usage(); - - /* Convert tol to 12 hr time (0:00...11:59) */ - if (hours > 11) - hours -=3D 12; - - /* Convert tm to 12 hr time (0:00...11:59) */ - if (t->tm_hour > 11) - t_12_hour =3D t->tm_hour - 12; - else - t_12_hour =3D t->tm_hour; - - if (hours < t_12_hour || - (hours =3D=3D t_12_hour && minutes <=3D t->tm_min)) - /* Leave time is in the past so we add 12 hrs */ - hours +=3D 12; + if (t->tm_hour > hours ||=20 + (t->tm_hour =3D=3D hours && t->tm_min >=3D minutes)) { + /* determine 24 hours mode */ + if (hours >=3D 13) + hours +=3D 24; + else + hours +=3D 12; + } =20 - secs =3D (hours - t_12_hour) * 60 * 60; + secs =3D (hours - t->tm_hour) * 60 * 60; secs +=3D (minutes - t->tm_min) * 60; - secs -=3D now % 60; /* truncate (now + secs) to min */ } doalarm(secs); exit(0); @@ -142,15 +134,14 @@ u_int secs; { register int bother; - time_t daytime, time(); - char tb[80]; + time_t daytime; int pid; =20 if ((pid =3D fork())) { (void)time(&daytime); daytime +=3D secs; - strftime(tb, sizeof(tb), "%+", localtime(&daytime)); - printf("Alarm set for %s. (pid %d)\n", tb, pid); + printf("Alarm set for %.16s. (pid %d)\n", + ctime(&daytime), pid); exit(0); } sleep((u_int)2); /* let parent print set message */ @@ -165,7 +156,7 @@ #define MSG2 "\07\07You have to leave in 5 minutes.\n" if (secs >=3D FIVEMIN) { sleep(secs - FIVEMIN); - if (write(1, MSG2, sizeof(MSG2) - 1) !=3D sizeof(MSG2) - 1) + if (write(STDOUT_FILENO, MSG2, sizeof(MSG2) - 1) !=3D sizeof(MSG2) - 1) exit(0); secs =3D FIVEMIN; } @@ -174,19 +165,19 @@ #define MSG3 "\07\07Just one more minute!\n" if (secs >=3D ONEMIN) { sleep(secs - ONEMIN); - if (write(1, MSG3, sizeof(MSG3) - 1) !=3D sizeof(MSG3) - 1) + if (write(STDOUT_FILENO, MSG3, sizeof(MSG3) - 1) !=3D sizeof(MSG3) - 1) exit(0); } =20 #define MSG4 "\07\07Time to leave!\n" for (bother =3D 10; bother--;) { sleep((u_int)ONEMIN); - if (write(1, MSG4, sizeof(MSG4) - 1) !=3D sizeof(MSG4) - 1) + if (write(STDOUT_FILENO, MSG4, sizeof(MSG4) - 1) !=3D sizeof(MSG4) - 1) exit(0); } =20 #define MSG5 "\07\07That was the last time I'll tell you. Bye.\n" - (void)write(1, MSG5, sizeof(MSG5) - 1); + (void)write(STDOUT_FILENO, MSG5, sizeof(MSG5) - 1); exit(0); } =20 --n8g4imXOkfNTN/H1 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (FreeBSD) Comment: For info see http://www.gnupg.org iD8DBQE65VqiWry0BWjoQKURAtfZAJ4xq/EJQ9lAjgahrHSToT0GeJV77gCeJgsQ n37b6EN5bjZO4jtFZ6U8BTI= =EQ0i -----END PGP SIGNATURE----- --n8g4imXOkfNTN/H1-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010424035116.A82401>