[PATCH 1/2] fix O_CLOEXEC related build problems with kernel versions < 2.6.23
Xabier Oneca -- xOneca
xoneca at gmail.com
Wed Oct 18 06:52:46 UTC 2017
Hello Eugene,
Comments inline.
2017-10-17 23:33 GMT+02:00 Eugene Rudoy <gene.devel at gmail.com>:
> Do not use O_CLOEXEC flags (available since 2.6.23),
> use close_on_exec_on provided by libbb instead (like everywhere else)
>
> Signed-off-by: Eugene Rudoy <gene.devel at gmail.com>
> ---
> miscutils/time.c | 6 ++++--
> modutils/modprobe-small.c | 3 ++-
> modutils/modutils.c | 3 ++-
> 3 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/miscutils/time.c b/miscutils/time.c
> index f4f8149d3..4f0e37d35 100644
> --- a/miscutils/time.c
> +++ b/miscutils/time.c
> @@ -444,9 +444,11 @@ 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)
> );
> + if (output_fd >= 0)
Doesn't xopen always guarantee output_fd will be valid? If so, there's
no need for this 'if'.
> + close_on_exec_on(output_fd);
> }
>
> run_command(argv, &res);
> diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c
> index a94b0b9a6..e782d687d 100644
> --- a/modutils/modprobe-small.c
> +++ b/modutils/modprobe-small.c
> @@ -270,8 +270,9 @@ static int load_module(const char *fname, const char *options)
> r = 1;
> # ifdef __NR_finit_module
> {
> - int fd = open(fname, O_RDONLY | O_CLOEXEC);
> + int fd = open(fname, O_RDONLY);
> if (fd >= 0) {
> + close_on_exec_on(fd);
> r = finit_module(fd, options, 0) != 0;
> close(fd);
> }
> diff --git a/modutils/modutils.c b/modutils/modutils.c
> index 6f7cd9721..9f73d676c 100644
> --- a/modutils/modutils.c
> +++ b/modutils/modutils.c
> @@ -215,8 +215,9 @@ int FAST_FUNC bb_init_module(const char *filename, const char *options)
> */
> # ifdef __NR_finit_module
> {
> - int fd = open(filename, O_RDONLY | O_CLOEXEC);
> + int fd = open(filename, O_RDONLY);
> if (fd >= 0) {
> + close_on_exec_on(fd);
> rc = finit_module(fd, options, 0) != 0;
> close(fd);
> if (rc == 0)
> --
> 2.14.2
>
Cheers,
Xabier Oneca_,,_
More information about the busybox
mailing list