Add a new -o option to tell xargs(1) to reopen /dev/tty as stdin in
the child process, before executing the command. This is very useful when you do stuff like ``find ... | xargs interactive_application''. Without -o, the application would inherit the pipe as its stdin, and you thus lose any control over it. This flag has been carefully chosen to not conflit with other options of other xargs utilities like GNU xargs. Reviewed by: jmallett
This commit is contained in:
parent
f949f795aa
commit
98186e89da
@ -45,7 +45,7 @@
|
||||
.Nd "construct argument list(s) and execute utility"
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl 0pt
|
||||
.Op Fl 0opt
|
||||
.Op Fl E Ar eofstr
|
||||
.Oo
|
||||
.Fl I Ar replstr
|
||||
@ -192,6 +192,13 @@ arguments remaining for the last invocation of
|
||||
The current default value for
|
||||
.Ar number
|
||||
is 5000.
|
||||
.It Fl o
|
||||
Reopen stdin as
|
||||
.Dq /dev/tty
|
||||
in the child process before executing the command.
|
||||
This is useful if you want
|
||||
.Nm
|
||||
to run an interactive application.
|
||||
.It Fl P Ar maxprocs
|
||||
Parallel mode: run at most
|
||||
.Ar maxprocs
|
||||
@ -287,7 +294,7 @@ utility is expected to be
|
||||
.St -p1003.2
|
||||
compliant.
|
||||
The
|
||||
.Fl J , P
|
||||
.Fl J , o , P
|
||||
and
|
||||
.Fl R
|
||||
options are non-standard
|
||||
|
@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#if (__FreeBSD_version >= 450002 && __FreeBSD_version < 500000) || \
|
||||
__FreeBSD_version >= 500017
|
||||
#include <langinfo.h>
|
||||
@ -82,7 +83,7 @@ static char echo[] = _PATH_ECHO;
|
||||
static char **av, **bxp, **ep, **exp, **xp;
|
||||
static char *argp, *bbp, *ebp, *inpline, *p, *replstr;
|
||||
static const char *eofstr;
|
||||
static int count, insingle, indouble, pflag, tflag, Rflag, rval, zflag;
|
||||
static int count, insingle, indouble, oflag, pflag, tflag, Rflag, rval, zflag;
|
||||
static int cnt, Iflag, jfound, Lflag, wasquoted, xflag;
|
||||
static int curprocs, maxprocs;
|
||||
|
||||
@ -127,7 +128,7 @@ main(int argc, char *argv[])
|
||||
nline -= strlen(*ep++) + 1 + sizeof(*ep);
|
||||
}
|
||||
maxprocs = 1;
|
||||
while ((ch = getopt(argc, argv, "0E:I:J:L:n:P:pR:s:tx")) != -1)
|
||||
while ((ch = getopt(argc, argv, "0E:I:J:L:n:oP:pR:s:tx")) != -1)
|
||||
switch(ch) {
|
||||
case 'E':
|
||||
eofstr = optarg;
|
||||
@ -151,6 +152,9 @@ main(int argc, char *argv[])
|
||||
if ((nargs = atoi(optarg)) <= 0)
|
||||
errx(1, "illegal argument count");
|
||||
break;
|
||||
case 'o':
|
||||
oflag = 1;
|
||||
break;
|
||||
case 'P':
|
||||
if ((maxprocs = atoi(optarg)) <= 0)
|
||||
errx(1, "max. processes must be >0");
|
||||
@ -522,6 +526,11 @@ exec:
|
||||
case -1:
|
||||
err(1, "vfork");
|
||||
case 0:
|
||||
if (oflag) {
|
||||
close(0);
|
||||
if (open("/dev/tty", O_RDONLY) == -1)
|
||||
err(1, "open");
|
||||
}
|
||||
execvp(argv[0], argv);
|
||||
childerr = errno;
|
||||
_exit(1);
|
||||
@ -595,7 +604,7 @@ static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: xargs [-0pt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]\n"
|
||||
"usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]\n"
|
||||
" [-L number] [-n number [-x]] [-P maxprocs] [-s size]\n"
|
||||
" [utility [argument ...]]\n");
|
||||
exit(1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user