[Midnightbsd-cvs] src: usr.bin/time: sync time

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Tue Dec 9 13:25:24 EST 2008


Log Message:
-----------
sync time

Modified Files:
--------------
    src/usr.bin/time:
        Makefile (r1.1.1.1 -> r1.2)
        time.1 (r1.1.1.1 -> r1.2)
        time.c (r1.1.1.1 -> r1.2)

-------------- next part --------------
Index: time.1
===================================================================
RCS file: /home/cvs/src/usr.bin/time/time.1,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/time/time.1 -L usr.bin/time/time.1 -u -r1.1.1.1 -r1.2
--- usr.bin/time/time.1
+++ usr.bin/time/time.1
@@ -30,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)time.1	8.1 (Berkeley) 6/6/93
-.\" $FreeBSD: src/usr.bin/time/time.1,v 1.24 2005/01/17 07:44:31 ru Exp $
+.\" $FreeBSD: src/usr.bin/time/time.1,v 1.26 2006/09/29 15:20:47 ru Exp $
 .\"
-.Dd June 6, 1993
+.Dd May 14, 2006
 .Dt TIME 1
 .Os
 .Sh NAME
@@ -99,6 +99,15 @@
 Consult the
 .Xr builtin 1
 manual page.
+.Pp
+If
+.Nm
+receives a
+.Dv SIGINFO
+(see the status argument for
+.Xr stty 1 )
+signal, the current time the given command is running will be written to the
+standard output.
 .Sh ENVIRONMENT
 The
 .Ev PATH
Index: Makefile
===================================================================
RCS file: /home/cvs/src/usr.bin/time/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/time/Makefile -L usr.bin/time/Makefile -u -r1.1.1.1 -r1.2
--- usr.bin/time/Makefile
+++ usr.bin/time/Makefile
@@ -1,5 +1,7 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
+# $FreeBSD: src/usr.bin/time/Makefile,v 1.2 2007/05/07 12:23:23 dwmalone Exp $
 
 PROG=	time
+WARNS?=6
 
 .include <bsd.prog.mk>
Index: time.c
===================================================================
RCS file: /home/cvs/src/usr.bin/time/time.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/time/time.c -L usr.bin/time/time.c -u -r1.1.1.1 -r1.2
--- usr.bin/time/time.c
+++ usr.bin/time/time.c
@@ -42,7 +42,7 @@
 static char sccsid[] = "@(#)time.c	8.1 (Berkeley) 6/6/93";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: src/usr.bin/time/time.c,v 1.27 2005/05/21 09:55:08 ru Exp $";
+  "$FreeBSD: src/usr.bin/time/time.c,v 1.30 2007/05/07 12:23:23 dwmalone Exp $";
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -58,24 +58,30 @@
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
 #include <unistd.h>
 
 static int getstathz(void);
 static void humantime(FILE *, long, long);
+static void showtime(FILE *, struct timeval *, struct timeval *,
+    struct rusage *);
+static void siginfo(int);
 static void usage(void);
 
 static char decimal_point;
+static struct timeval before_tv;
+static int hflag, pflag;
 
 int
 main(int argc, char **argv)
 {
-	int aflag, ch, hflag, lflag, status, pflag;
+	int aflag, ch, lflag, status;
 	int exitonsig;
 	pid_t pid;
 	struct rlimit rl;
 	struct rusage ru;
-	struct timeval before, after;
+	struct timeval after;
 	char *ofn = NULL;
 	FILE *out = stderr;
 
@@ -115,12 +121,14 @@
 		setvbuf(out, (char *)NULL, _IONBF, (size_t)0);
 	}
 
-	gettimeofday(&before, (struct timezone *)NULL);
+	gettimeofday(&before_tv, (struct timezone *)NULL);
 	switch(pid = fork()) {
 	case -1:			/* error */
 		err(1, "time");
 		/* NOTREACHED */
 	case 0:				/* child */
+		if (ofn)
+			fclose(out);
 		execvp(*argv, argv);
 		err(errno == ENOENT ? 127 : 126, "%s", *argv);
 		/* NOTREACHED */
@@ -128,46 +136,13 @@
 	/* parent */
 	(void)signal(SIGINT, SIG_IGN);
 	(void)signal(SIGQUIT, SIG_IGN);
+	(void)signal(SIGINFO, siginfo);
 	while (wait4(pid, &status, 0, &ru) != pid);
 	gettimeofday(&after, (struct timezone *)NULL);
 	if ( ! WIFEXITED(status))
 		warnx("command terminated abnormally");
 	exitonsig = WIFSIGNALED(status) ? WTERMSIG(status) : 0;
-	after.tv_sec -= before.tv_sec;
-	after.tv_usec -= before.tv_usec;
-	if (after.tv_usec < 0)
-		after.tv_sec--, after.tv_usec += 1000000;
-	if (pflag) {
-		/* POSIX wants output that must look like
-		"real %f\nuser %f\nsys %f\n" and requires
-		at least two digits after the radix. */
-		fprintf(out, "real %ld%c%02ld\n",
-			after.tv_sec, decimal_point,
-			after.tv_usec/10000);
-		fprintf(out, "user %ld%c%02ld\n",
-			ru.ru_utime.tv_sec, decimal_point,
-			ru.ru_utime.tv_usec/10000);
-		fprintf(out, "sys %ld%c%02ld\n",
-			ru.ru_stime.tv_sec, decimal_point,
-			ru.ru_stime.tv_usec/10000);
-	} else if (hflag) {
-		humantime(out, after.tv_sec, after.tv_usec/10000);
-		fprintf(out, " real\t");
-		humantime(out, ru.ru_utime.tv_sec, ru.ru_utime.tv_usec/10000);
-		fprintf(out, " user\t");
-		humantime(out, ru.ru_stime.tv_sec, ru.ru_stime.tv_usec/10000);
-		fprintf(out, " sys\n");
-	} else {
-		fprintf(out, "%9ld%c%02ld real ",
-			after.tv_sec, decimal_point,
-			after.tv_usec/10000);
-		fprintf(out, "%9ld%c%02ld user ",
-			ru.ru_utime.tv_sec, decimal_point,
-			ru.ru_utime.tv_usec/10000);
-		fprintf(out, "%9ld%c%02ld sys\n",
-			ru.ru_stime.tv_sec, decimal_point,
-			ru.ru_stime.tv_usec/10000);
-	}
+	showtime(out, &before_tv, &after, &ru);
 	if (lflag) {
 		int hz = getstathz();
 		u_long ticks;
@@ -276,3 +251,57 @@
 		fprintf(out, "%ldm", mins);
 	fprintf(out, "%ld%c%02lds", sec, decimal_point, usec);
 }
+
+static void
+showtime(FILE *out, struct timeval *before, struct timeval *after,
+    struct rusage *ru)
+{
+
+	after->tv_sec -= before->tv_sec;
+	after->tv_usec -= before->tv_usec;
+	if (after->tv_usec < 0)
+		after->tv_sec--, after->tv_usec += 1000000;
+
+	if (pflag) {
+		/* POSIX wants output that must look like
+		"real %f\nuser %f\nsys %f\n" and requires
+		at least two digits after the radix. */
+		fprintf(out, "real %jd%c%02ld\n",
+			(intmax_t)after->tv_sec, decimal_point,
+			after->tv_usec/10000);
+		fprintf(out, "user %jd%c%02ld\n",
+			(intmax_t)ru->ru_utime.tv_sec, decimal_point,
+			ru->ru_utime.tv_usec/10000);
+		fprintf(out, "sys %jd%c%02ld\n",
+			(intmax_t)ru->ru_stime.tv_sec, decimal_point,
+			ru->ru_stime.tv_usec/10000);
+	} else if (hflag) {
+		humantime(out, after->tv_sec, after->tv_usec/10000);
+		fprintf(out, " real\t");
+		humantime(out, ru->ru_utime.tv_sec, ru->ru_utime.tv_usec/10000);
+		fprintf(out, " user\t");
+		humantime(out, ru->ru_stime.tv_sec, ru->ru_stime.tv_usec/10000);
+		fprintf(out, " sys\n");
+	} else {
+		fprintf(out, "%9jd%c%02ld real ",
+			(intmax_t)after->tv_sec, decimal_point,
+			after->tv_usec/10000);
+		fprintf(out, "%9jd%c%02ld user ",
+			(intmax_t)ru->ru_utime.tv_sec, decimal_point,
+			ru->ru_utime.tv_usec/10000);
+		fprintf(out, "%9jd%c%02ld sys\n",
+			(intmax_t)ru->ru_stime.tv_sec, decimal_point,
+			ru->ru_stime.tv_usec/10000);
+	}
+}
+
+static void
+siginfo(int sig __unused)
+{
+	struct timeval after;
+	struct rusage ru;
+
+	gettimeofday(&after, (struct timezone *)NULL);
+	getrusage(RUSAGE_CHILDREN, &ru);
+	showtime(stdout, &before_tv, &after, &ru);
+}


More information about the Midnightbsd-cvs mailing list