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
[-- Attachment #1 --]
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
===================================================================
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
===================================================================
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[] = "@(#)leave.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
- "$FreeBSD: src/usr.bin/leave/leave.c,v 1.6 2001/04/24 10:39:17 kris Exp $";
+ "$FreeBSD$";
#endif /* not lint */
#include <err.h>
@@ -70,9 +70,9 @@
register u_int secs;
register int hours, minutes;
register char c, *cp = NULL;
- struct tm *t, *localtime();
- time_t now, time();
- int plusnow, t_12_hour;
+ struct tm *t = NULL;
+ time_t now;
+ int plusnow;
char buf[50];
if (setlocale(LC_TIME, "") == NULL)
@@ -80,7 +80,7 @@
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 = fgets(buf, sizeof(buf), stdin);
if (cp == NULL || *cp == '\n')
exit(0);
@@ -92,8 +92,11 @@
if (*cp == '+') {
plusnow = 1;
++cp;
- } else
+ } else {
plusnow = 0;
+ (void)time(&now);
+ t = localtime(&now);
+ }
for (hours = 0; (c = *cp) && c != '\n'; ++cp) {
if (!isdigit(c))
@@ -108,30 +111,19 @@
if (plusnow)
secs = hours * 60 * 60 + minutes * 60;
else {
- (void)time(&now);
- t = localtime(&now);
-
if (hours > 23)
usage();
-
- /* Convert tol to 12 hr time (0:00...11:59) */
- if (hours > 11)
- hours -= 12;
-
- /* Convert tm to 12 hr time (0:00...11:59) */
- if (t->tm_hour > 11)
- t_12_hour = t->tm_hour - 12;
- else
- t_12_hour = t->tm_hour;
-
- if (hours < t_12_hour ||
- (hours == t_12_hour && minutes <= t->tm_min))
- /* Leave time is in the past so we add 12 hrs */
- hours += 12;
+ if (t->tm_hour > hours ||
+ (t->tm_hour == hours && t->tm_min >= minutes)) {
+ /* determine 24 hours mode */
+ if (hours >= 13)
+ hours += 24;
+ else
+ hours += 12;
+ }
- secs = (hours - t_12_hour) * 60 * 60;
+ secs = (hours - t->tm_hour) * 60 * 60;
secs += (minutes - t->tm_min) * 60;
- secs -= 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;
if ((pid = fork())) {
(void)time(&daytime);
daytime += 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 >= FIVEMIN) {
sleep(secs - FIVEMIN);
- if (write(1, MSG2, sizeof(MSG2) - 1) != sizeof(MSG2) - 1)
+ if (write(STDOUT_FILENO, MSG2, sizeof(MSG2) - 1) != sizeof(MSG2) - 1)
exit(0);
secs = FIVEMIN;
}
@@ -174,19 +165,19 @@
#define MSG3 "\07\07Just one more minute!\n"
if (secs >= ONEMIN) {
sleep(secs - ONEMIN);
- if (write(1, MSG3, sizeof(MSG3) - 1) != sizeof(MSG3) - 1)
+ if (write(STDOUT_FILENO, MSG3, sizeof(MSG3) - 1) != sizeof(MSG3) - 1)
exit(0);
}
#define MSG4 "\07\07Time to leave!\n"
for (bother = 10; bother--;) {
sleep((u_int)ONEMIN);
- if (write(1, MSG4, sizeof(MSG4) - 1) != sizeof(MSG4) - 1)
+ if (write(STDOUT_FILENO, MSG4, sizeof(MSG4) - 1) != sizeof(MSG4) - 1)
exit(0);
}
#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);
}
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (FreeBSD)
Comment: For info see http://www.gnupg.org
iD8DBQE65VqiWry0BWjoQKURAtfZAJ4xq/EJQ9lAjgahrHSToT0GeJV77gCeJgsQ
n37b6EN5bjZO4jtFZ6U8BTI=
=EQ0i
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010424035116.A82401>
