Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sleep add SIGINFO support; from freebsd:
details: https://anonhg.NetBSD.org/src/rev/3d1b3d9a4cda
branches: trunk
changeset: 757972:3d1b3d9a4cda
user: mrg <mrg%NetBSD.org@localhost>
date: Sat Oct 09 04:57:30 2010 +0000
description:
add SIGINFO support; from freebsd:
when a SIGINFO is delivered, display the approximate remaining seconds.
diffstat:
bin/sleep/sleep.1 | 7 ++++++-
bin/sleep/sleep.c | 30 ++++++++++++++++++++++++++----
2 files changed, 32 insertions(+), 5 deletions(-)
diffs (85 lines):
diff -r 661a4168139e -r 3d1b3d9a4cda bin/sleep/sleep.1
--- a/bin/sleep/sleep.1 Fri Oct 08 11:20:22 2010 +0000
+++ b/bin/sleep/sleep.1 Sat Oct 09 04:57:30 2010 +0000
@@ -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
diff -r 661a4168139e -r 3d1b3d9a4cda bin/sleep/sleep.c
--- a/bin/sleep/sleep.c Fri Oct 08 11:20:22 2010 +0000
+++ b/bin/sleep/sleep.c Sat Oct 09 04:57:30 2010 +0000
@@ -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;
Home |
Main Index |
Thread Index |
Old Index