Bug 15146 - xargs: Allow running interactive commands with -o [PATCH]
Summary: xargs: Allow running interactive commands with -o [PATCH]
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All All
: P5 enhancement
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-26 17:59 UTC by Mallory
Modified: 2022-12-22 09:38 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments
Patch to add -o support https://github.com/MalloryA/busybox/commit/2b66ae249d87c3b1c427cc87862ad6612b27c271 (3.95 KB, application/octet-stream)
2022-11-26 17:59 UTC, Mallory
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mallory 2022-11-26 17:59:57 UTC
Created attachment 9416 [details]
Patch to add -o support https://github.com/MalloryA/busybox/commit/2b66ae249d87c3b1c427cc87862ad6612b27c271

-o opens /dev/tty and connects it to the stdin of the commands that get
executed.

Example: say we want to delete some files interactively. We cannot do
that with xargs without the -o option because the `rm -i` command does
not receive an interactive stdin. But if we add `-o`, then xargs will
ensure that /dev/tty is connected as stdin and `rm -i` will show us a
prompt and wait:

```
% touch a b c
% echo a b c | xargs -o rm -i
```

The -o option is available in GNU and FreeBSD versions of xargs as non-POSIX extensions.

Attached is a patch generated by `git format-patch`. I put the same patch on GitHub too: https://github.com/MalloryA/busybox/commit/2b66ae249d87c3b1c427cc87862ad6612b27c271
Comment 1 Denys Vlasenko 2022-12-20 14:31:51 UTC
Buggy. You must not dup2 to stdin, you lose the original input.


+               if (dup2(*fd, STDIN_FILENO) != 0)
+                       bb_error_msg_and_die("can't read from /dev/tty");

The error message is wrong. Anyway, use xdup2() which never returns failure.



+               if ((fd = xopen("/dev/tty", O_RDONLY)) == -1)
+                       bb_error_msg_and_die("can't open /dev/tty");

xopen() never returns -1.
Comment 2 Denys Vlasenko 2022-12-22 09:38:53 UTC
Fixed in git.