Module Name:    src
Committed By:   mrg
Date:           Sat Oct  9 04:57:30 UTC 2010

Modified Files:
        src/bin/sleep: sleep.1 sleep.c

Log Message:
add SIGINFO support; from freebsd:

when a SIGINFO is delivered, display the approximate remaining seconds.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/bin/sleep/sleep.1
cvs rdiff -u -r1.22 -r1.23 src/bin/sleep/sleep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sleep/sleep.1
diff -u src/bin/sleep/sleep.1:1.19 src/bin/sleep/sleep.1:1.20
--- src/bin/sleep/sleep.1:1.19	Sat Aug 18 00:41:52 2007
+++ src/bin/sleep/sleep.1	Sat Oct  9 04:57:30 2010
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sleep.1,v 1.19 2007/08/18 00:41:52 hubertf Exp $
+.\"	$NetBSD: sleep.1,v 1.20 2010/10/09 04:57:30 mrg Exp $
 .\"
 .\" Copyright (c) 1990, 1993, 1994
 .\"	The Regents of the University of California.  All rights reserved.
@@ -57,6 +57,11 @@
 command will accept and honor a non-integer number of specified seconds.
 This is a non-portable extension, and its use will nearly guarantee that
 a shell script will not execute properly on another system.
+.Pp
+When the
+.Dv SIGINFO
+signal is received, the estimate of the amount of seconds left to
+sleep is printed on the standard output.
 .Sh EXIT STATUS
 The
 .Nm

Index: src/bin/sleep/sleep.c
diff -u src/bin/sleep/sleep.c:1.22 src/bin/sleep/sleep.c:1.23
--- src/bin/sleep/sleep.c:1.22	Sun Jul 20 00:52:40 2008
+++ src/bin/sleep/sleep.c	Sat Oct  9 04:57:30 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sleep.c,v 1.22 2008/07/20 00:52:40 lukem Exp $ */
+/* $NetBSD: sleep.c,v 1.23 2010/10/09 04:57:30 mrg Exp $ */
 
 /*
  * Copyright (c) 1988, 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)sleep.c	8.3 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: sleep.c,v 1.22 2008/07/20 00:52:40 lukem Exp $");
+__RCSID("$NetBSD: sleep.c,v 1.23 2010/10/09 04:57:30 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -57,13 +57,23 @@
 static void usage(void);
 int main(int, char *[]);
 
+static volatile sig_atomic_t report_requested;
+static void
+report_request(int signo __unused)
+{
+
+	report_requested = 1;
+}
+
+
 int
 main(int argc, char *argv[])
 {
 	char *arg, *temp;
 	double fval, ival, val;
 	struct timespec ntime;
-	int ch, fracflag;
+	time_t original;
+	int ch, fracflag, rv;
 
 	setprogname(argv[0]);
 	(void)setlocale(LC_ALL, "");
@@ -115,7 +125,19 @@
 		ntime.tv_nsec = 0;
 	}
 
-	if (nanosleep(&ntime, NULL) == -1)
+	original = ntime.tv_sec;
+	signal(SIGINFO, report_request);
+	while ((rv = nanosleep(&ntime, &ntime)) != 0) {
+		if (report_requested) {
+		/* Reporting does not bother with nanoseconds. */
+			warnx("about %d second(s) left out of the original %d",
+			(int)ntime.tv_sec, (int)original);
+			report_requested = 0;
+		} else
+			break;
+	}
+
+	if (rv == -1)
 		err(EXIT_FAILURE, "nanosleep failed");
 
 	return EXIT_SUCCESS;

Reply via email to