Module Name:    src
Committed By:   christos
Date:           Wed Mar  4 16:36:12 UTC 2015

Modified Files:
        src/usr.bin/pwait: pwait.1 pwait.c

Log Message:
add flag that let's you not wait for all the processes specified.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/pwait/pwait.1
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/pwait/pwait.c

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

Modified files:

Index: src/usr.bin/pwait/pwait.1
diff -u src/usr.bin/pwait/pwait.1:1.3 src/usr.bin/pwait/pwait.1:1.4
--- src/usr.bin/pwait/pwait.1:1.3	Tue Mar  3 14:59:48 2015
+++ src/usr.bin/pwait/pwait.1	Wed Mar  4 11:36:12 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pwait.1,v 1.3 2015/03/03 19:59:48 christos Exp $
+.\"	$NetBSD: pwait.1,v 1.4 2015/03/04 16:36:12 christos Exp $
 .\"
 .\" Copyright (c) 2004-2009, Jilles Tjoelker
 .\" All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\" $FreeBSD: head/bin/pwait/pwait.1 233648 2012-03-29 05:02:12Z eadler $
 .\"
-.Dd March 3, 2015
+.Dd March 4, 2015
 .Dt PWAIT 1
 .Os
 .Sh NAME
@@ -41,7 +41,7 @@
 .Nd wait for processes to terminate
 .Sh SYNOPSIS
 .Nm
-.Op Fl sv
+.Op Fl isv
 .Op Fl t Ar timeout
 .Ar pid
 \&...
@@ -52,6 +52,9 @@ utility will wait until each of the give
 .Pp
 The following option is available:
 .Bl -tag -width indent
+.It Fl i
+Don't wait for all the processes, exit after the first process or group
+of processes exit.
 .It Fl s
 Exit with the status code of the first non-zero exit status pid, or
 if timed out exit with

Index: src/usr.bin/pwait/pwait.c
diff -u src/usr.bin/pwait/pwait.c:1.4 src/usr.bin/pwait/pwait.c:1.5
--- src/usr.bin/pwait/pwait.c:1.4	Wed Mar  4 08:31:53 2015
+++ src/usr.bin/pwait/pwait.c	Wed Mar  4 11:36:12 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: pwait.c,v 1.4 2015/03/04 13:31:53 christos Exp $	*/
+/*	$NetBSD: pwait.c,v 1.5 2015/03/04 16:36:12 christos Exp $	*/
 
 /*-
  * Copyright (c) 2004-2009, Jilles Tjoelker
@@ -37,7 +37,7 @@
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/bin/pwait/pwait.c 245506 2013-01-16 18:15:25Z delphij $");
 #endif
-__RCSID("$NetBSD: pwait.c,v 1.4 2015/03/04 13:31:53 christos Exp $");
+__RCSID("$NetBSD: pwait.c,v 1.5 2015/03/04 16:36:12 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/event.h>
@@ -58,7 +58,7 @@ static __dead void
 usage(void)
 {
 
-	fprintf(stderr, "Usage: %s [-sv] [-t <timeout>] <pid> ...\n",
+	fprintf(stderr, "Usage: %s [-isv] [-t <timeout>] <pid> ...\n",
 	    getprogname());
 	exit(EX_USAGE);
 }
@@ -72,7 +72,7 @@ main(int argc, char *argv[])
 	int kq;
 	struct kevent *e;
 	int verbose = 0, childstatus = 0;
-	int opt, duplicate, status;
+	int opt, duplicate, status, immediately = 0;
 	size_t nleft, n, i;
 	pid_t pid;
 	char *s, *end;
@@ -80,8 +80,11 @@ main(int argc, char *argv[])
 	struct timespec ts, *tsp;
 
 	setprogname(argv[0]);
-	while ((opt = getopt(argc, argv, "st:v")) != -1) {
+	while ((opt = getopt(argc, argv, "ist:v")) != -1) {
 		switch (opt) {
+		case 'i':
+			immediately = 1;
+			break;
 		case 's':
 			childstatus = 1;
 			break;
@@ -187,6 +190,9 @@ main(int argc, char *argv[])
 				return status;
 		}
 		nleft -= n;
+		// n != 0 here, belt-n-suspenders...
+		if (immediately && n)
+			break;
 	}
 
 	return EX_OK;

Reply via email to