Implement -o flag which tells pwait(1) to exit if any of the given processes
has terminated. Sponsored by: Fudo Security
This commit is contained in:
parent
5e2e2222ae
commit
2362bc2cf5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=357141
@ -32,7 +32,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd March 7, 2017
|
.Dd January 26, 2020
|
||||||
.Dt PWAIT 1
|
.Dt PWAIT 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -41,7 +41,7 @@
|
|||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl t Ar duration
|
.Op Fl t Ar duration
|
||||||
.Op Fl v
|
.Op Fl ov
|
||||||
.Ar pid
|
.Ar pid
|
||||||
\&...
|
\&...
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
@ -51,6 +51,8 @@ utility will wait until each of the given processes has terminated.
|
|||||||
.Pp
|
.Pp
|
||||||
The following option is available:
|
The following option is available:
|
||||||
.Bl -tag -width indent
|
.Bl -tag -width indent
|
||||||
|
.It Fl o
|
||||||
|
Exit when any of the given processes has terminated.
|
||||||
.It Fl t Ar duration
|
.It Fl t Ar duration
|
||||||
If any process is still running after
|
If any process is still running after
|
||||||
.Ar duration ,
|
.Ar duration ,
|
||||||
|
@ -53,7 +53,7 @@ static void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
errx(EX_USAGE, "usage: pwait [-t timeout] [-v] pid ...");
|
errx(EX_USAGE, "usage: pwait [-t timeout] [-ov] pid ...");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -65,16 +65,22 @@ main(int argc, char *argv[])
|
|||||||
struct itimerval itv;
|
struct itimerval itv;
|
||||||
int kq;
|
int kq;
|
||||||
struct kevent *e;
|
struct kevent *e;
|
||||||
int tflag, verbose;
|
int oflag, tflag, verbose;
|
||||||
int opt, nleft, n, i, status;
|
int opt, nleft, n, i, status;
|
||||||
long pid;
|
long pid;
|
||||||
char *s, *end;
|
char *s, *end;
|
||||||
double timeout;
|
double timeout;
|
||||||
|
|
||||||
tflag = verbose = 0;
|
oflag = 0;
|
||||||
|
tflag = 0;
|
||||||
|
verbose = 0;
|
||||||
memset(&itv, 0, sizeof(itv));
|
memset(&itv, 0, sizeof(itv));
|
||||||
while ((opt = getopt(argc, argv, "t:v")) != -1) {
|
|
||||||
|
while ((opt = getopt(argc, argv, "t:ov")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
case 'o':
|
||||||
|
oflag = 1;
|
||||||
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
tflag = 1;
|
tflag = 1;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
@ -144,11 +150,14 @@ main(int argc, char *argv[])
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
EV_SET(e + nleft, pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
|
EV_SET(e + nleft, pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
|
||||||
if (kevent(kq, e + nleft, 1, NULL, 0, NULL) == -1)
|
if (kevent(kq, e + nleft, 1, NULL, 0, NULL) == -1) {
|
||||||
warn("%ld", pid);
|
warn("%ld", pid);
|
||||||
else
|
if (oflag)
|
||||||
|
exit(EX_OK);
|
||||||
|
} else {
|
||||||
nleft++;
|
nleft++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (nleft > 0 && tflag) {
|
if (nleft > 0 && tflag) {
|
||||||
/*
|
/*
|
||||||
@ -187,6 +196,8 @@ main(int argc, char *argv[])
|
|||||||
printf("%ld: terminated.\n",
|
printf("%ld: terminated.\n",
|
||||||
(long)e[i].ident);
|
(long)e[i].ident);
|
||||||
}
|
}
|
||||||
|
if (oflag)
|
||||||
|
exit(EX_OK);
|
||||||
--nleft;
|
--nleft;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user