O_CLOEXEC is the default in toybox, so although the code as written _looked_ correct, we need to |O_CLOEXEC to have the fd survive the exec().
Found by folks building the kernel with toybox. --- tests/xargs.test | 2 ++ toys/posix/xargs.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)/tmp
From 5ecfb049677eea77ce0ac6f6039422d16de9bf9b Mon Sep 17 00:00:00 2001 From: Elliott Hughes <e...@google.com> Date: Thu, 21 Apr 2022 17:54:38 -0700 Subject: [PATCH] xargs: open child's stdin non-O_CLOEXEC. O_CLOEXEC is the default in toybox, so although the code as written _looked_ correct, we need to |O_CLOEXEC to have the fd survive the exec(). Found by folks building the kernel with toybox. --- tests/xargs.test | 2 ++ toys/posix/xargs.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/xargs.test b/tests/xargs.test index dc3c7b32..7566e375 100644 --- a/tests/xargs.test +++ b/tests/xargs.test @@ -84,3 +84,5 @@ testing "parallel sleep" " #testing "-n exact match" #testing "-s exact match" #testing "-s impossible" + +testing "no stdin" "echo -n | xargs cat" "" "" "" diff --git a/toys/posix/xargs.c b/toys/posix/xargs.c index cc3ee3de..dfcb49cc 100644 --- a/toys/posix/xargs.c +++ b/toys/posix/xargs.c @@ -184,7 +184,7 @@ void xargs_main(void) if (!(pid = XVFORK())) { close(0); - xopen_stdio(FLAG(o) ? "/dev/tty" : "/dev/null", O_RDONLY); + xopen_stdio(FLAG(o) ? "/dev/tty" : "/dev/null", O_RDONLY|O_CLOEXEC); xexec(out); } TT.np++; -- 2.36.0.rc2.479.g8af0fa9b8e-goog
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net