summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormux <mux@FreeBSD.org>2003-03-23 18:29:52 +0000
committermux <mux@FreeBSD.org>2003-03-23 18:29:52 +0000
commit76bd33cd1b93dd2343898e0f0cdb4a8aa1b46271 (patch)
treed8dea2198fb4b799619a7cf539bb2ec6eaf22d25
parent9785758af05bf04abf659e455022398d1923565b (diff)
downloadFreeBSD-src-76bd33cd1b93dd2343898e0f0cdb4a8aa1b46271.zip
FreeBSD-src-76bd33cd1b93dd2343898e0f0cdb4a8aa1b46271.tar.gz
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
-rw-r--r--usr.bin/xargs/xargs.111
-rw-r--r--usr.bin/xargs/xargs.c15
2 files changed, 21 insertions, 5 deletions
diff --git a/usr.bin/xargs/xargs.1 b/usr.bin/xargs/xargs.1
index 7c2f70b..a36edd1 100644
--- a/usr.bin/xargs/xargs.1
+++ b/usr.bin/xargs/xargs.1
@@ -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
diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c
index ec15af7..5e6c2b4 100644
--- a/usr.bin/xargs/xargs.c
+++ b/usr.bin/xargs/xargs.c
@@ -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);
OpenPOWER on IntegriCloud