[PATCH v2 1/2] time applet: fix a build problem with kernel versions missing O_CLOEXEC symbol
Eugene Rudoy
gene.devel at gmail.com
Wed Oct 18 22:05:10 UTC 2017
Kernel versions < 2.6.23 do not support/provide O_CLOEXEC symbol
causing the time applet not to compile:
time.c: In function 'time_main':
time.c:445:28: error: 'O_CLOEXEC' undeclared (first use in this function)
time.c:445:28: note: each undeclared identifier is reported only once for each function it appears in
Fix it by using close_on_exec_on function provided by libbb
instead of passing O_CLOEXEC flag to open.
Signed-off-by: Eugene Rudoy <gene.devel at gmail.com>
---
v2: remove unnecessary "if (output_fd >= 0)", xopen guarantees the returned
file descriptor to be valid, thanks to Xabier Oneca for pointing it out
---
miscutils/time.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/miscutils/time.c b/miscutils/time.c
index f4f8149d3..c40d945e6 100644
--- a/miscutils/time.c
+++ b/miscutils/time.c
@@ -444,9 +444,10 @@ int time_main(int argc UNUSED_PARAM, char **argv)
if (opt & OPT_o) {
output_fd = xopen(output_filename,
(opt & OPT_a) /* append? */
- ? (O_CREAT | O_WRONLY | O_CLOEXEC | O_APPEND)
- : (O_CREAT | O_WRONLY | O_CLOEXEC | O_TRUNC)
+ ? (O_CREAT | O_WRONLY | O_APPEND)
+ : (O_CREAT | O_WRONLY | O_TRUNC)
);
+ close_on_exec_on(output_fd);
}
run_command(argv, &res);
--
2.14.2
More information about the busybox
mailing list