From 11d14ef6ab15245c576cb6082e7af83f4918429a Mon Sep 17 00:00:00 2001 From: wanggang26 Date: Wed, 13 Sep 2023 21:08:13 +0800 Subject: [PATCH] enable O_CLOEXEC explicit Signed-off-by: wanggang26 --- arch/arm/src/cxd56xx/cxd56_gnss.c | 8 +- arch/arm/src/lc823450/lc823450_ipl2.c | 2 +- arch/arm/src/rtl8720c/ameba_hci.c | 2 +- binfmt/libelf/libelf_init.c | 2 +- binfmt/libnxflat/libnxflat_init.c | 2 +- drivers/bch/bchdev_unregister.c | 2 +- drivers/loop/losetup.c | 4 +- drivers/mtd/filemtd.c | 2 +- drivers/mtd/mtd_config.c | 3 +- drivers/mtd/mtd_config_fs.c | 2 +- drivers/net/slip.c | 2 +- drivers/rptun/rptun.c | 2 +- .../{fakesensor.c => fakesensor_uorb.c} | 5 +- drivers/sensors/goldfish_gps_uorb.c | 223 ++++++++++++++++++ drivers/sensors/sensor_rpmsg.c | 6 +- .../sensors/{wtgahrs2.c => wtgahrs2_uorb.c} | 4 +- drivers/serial/ptmx.c | 2 +- drivers/serial/pty.c | 5 +- drivers/syslog/syslog_filechannel.c | 2 +- drivers/video/goldfish_camera.c | 4 +- drivers/wireless/bluetooth/bt_uart_shim.c | 2 +- .../wireless/ieee80211/bcm43xxx/bcmf_core.c | 4 +- .../wireless/ieee80211/bcm43xxx/bcmf_driver.c | 2 +- net/local/local_fifo.c | 5 +- net/utils/net_snoop.c | 2 +- 25 files changed, 264 insertions(+), 35 deletions(-) rename drivers/sensors/{fakesensor.c => fakesensor_uorb.c} (98%) create mode 100644 drivers/sensors/goldfish_gps_uorb.c rename drivers/sensors/{wtgahrs2.c => wtgahrs2_uorb.c} (99%) diff --git a/arch/arm/src/cxd56xx/cxd56_gnss.c b/arch/arm/src/cxd56xx/cxd56_gnss.c index ac101812e1340..04b0383a6263f 100644 --- a/arch/arm/src/cxd56xx/cxd56_gnss.c +++ b/arch/arm/src/cxd56xx/cxd56_gnss.c @@ -914,7 +914,7 @@ static int cxd56_gnss_save_backup_data(struct file *filep, } n = file_open(&file, CONFIG_CXD56_GNSS_BACKUP_FILENAME, - O_WRONLY | O_CREAT | O_TRUNC); + O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC); if (n < 0) { kmm_free(buf); @@ -2333,7 +2333,8 @@ static void cxd56_gnss_read_backup_file(int *retval) goto err; } - ret = file_open(&file, CONFIG_CXD56_GNSS_BACKUP_FILENAME, O_RDONLY); + ret = file_open(&file, CONFIG_CXD56_GNSS_BACKUP_FILENAME, + O_RDONLY | O_CLOEXEC); if (ret < 0) { kmm_free(buf); @@ -2489,7 +2490,8 @@ static void cxd56_gnss_default_sighandler(uint32_t data, void *userdata) file_close(&priv->cepfp); } - file_open(&priv->cepfp, CONFIG_CXD56_GNSS_CEP_FILENAME, O_RDONLY); + file_open(&priv->cepfp, CONFIG_CXD56_GNSS_CEP_FILENAME, + O_RDONLY | O_CLOEXEC); return; case CXD56_GNSS_NOTIFY_TYPE_REQCEPCLOSE: diff --git a/arch/arm/src/lc823450/lc823450_ipl2.c b/arch/arm/src/lc823450/lc823450_ipl2.c index ff6b238c5e754..0156182f91ba7 100644 --- a/arch/arm/src/lc823450/lc823450_ipl2.c +++ b/arch/arm/src/lc823450/lc823450_ipl2.c @@ -187,7 +187,7 @@ static int install_recovery(const char *srcpath) return -1; } - ret = file_open(&rfile, srcpath, O_RDONLY, 0444); + ret = file_open(&rfile, srcpath, O_RDONLY | O_CLOEXEC, 0444); if (file_read(&rfile, &upg_image, sizeof(upg_image)) != sizeof(upg_image)) { diff --git a/arch/arm/src/rtl8720c/ameba_hci.c b/arch/arm/src/rtl8720c/ameba_hci.c index 378e0c45df399..c35139ee3d87a 100644 --- a/arch/arm/src/rtl8720c/ameba_hci.c +++ b/arch/arm/src/rtl8720c/ameba_hci.c @@ -389,7 +389,7 @@ static int hci_open(struct file *filep) hci_dev_t *dev = inode->i_private; int ret; ret = file_open(&dev->filep, - CONFIG_AMEBA_HCI_DEV_NAME, O_RDWR); + CONFIG_AMEBA_HCI_DEV_NAME, O_RDWR | O_CLOEXEC); if (ret < 0) { return ret; diff --git a/binfmt/libelf/libelf_init.c b/binfmt/libelf/libelf_init.c index 95a7a0c91e51c..34d07f69772fa 100644 --- a/binfmt/libelf/libelf_init.c +++ b/binfmt/libelf/libelf_init.c @@ -127,7 +127,7 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo) /* Open the binary file for reading (only) */ - ret = file_open(&loadinfo->file, filename, O_RDONLY); + ret = file_open(&loadinfo->file, filename, O_RDONLY | O_CLOEXEC); if (ret < 0) { berr("Failed to open ELF binary %s: %d\n", filename, ret); diff --git a/binfmt/libnxflat/libnxflat_init.c b/binfmt/libnxflat/libnxflat_init.c index 09816e1128c81..81ce65c9d8b45 100644 --- a/binfmt/libnxflat/libnxflat_init.c +++ b/binfmt/libnxflat/libnxflat_init.c @@ -94,7 +94,7 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo) /* Open the binary file */ - ret = file_open(&loadinfo->file, filename, O_RDONLY); + ret = file_open(&loadinfo->file, filename, O_RDONLY | O_CLOEXEC); if (ret < 0) { berr("ERROR: Failed to open NXFLAT binary %s: %d\n", filename, ret); diff --git a/drivers/bch/bchdev_unregister.c b/drivers/bch/bchdev_unregister.c index ad4cfa7174990..f476de72a7064 100644 --- a/drivers/bch/bchdev_unregister.c +++ b/drivers/bch/bchdev_unregister.c @@ -70,7 +70,7 @@ int bchdev_unregister(FAR const char *chardev) /* Open the character driver associated with chardev */ - ret = file_open(&filestruct, chardev, O_RDONLY); + ret = file_open(&filestruct, chardev, O_RDONLY | O_CLOEXEC); if (ret < 0) { _err("ERROR: Failed to open %s: %d\n", chardev, ret); diff --git a/drivers/loop/losetup.c b/drivers/loop/losetup.c index 6fe2fc4f5b883..62750c3ceacc5 100644 --- a/drivers/loop/losetup.c +++ b/drivers/loop/losetup.c @@ -373,7 +373,7 @@ int losetup(FAR const char *devname, FAR const char *filename, ret = -ENOSYS; if (!readonly) { - ret = file_open(&dev->devfile, filename, O_RDWR); + ret = file_open(&dev->devfile, filename, O_RDWR | O_CLOEXEC); } if (ret >= 0) @@ -384,7 +384,7 @@ int losetup(FAR const char *devname, FAR const char *filename, { /* If that fails, then try to open the device read-only */ - ret = file_open(&dev->devfile, filename, O_RDONLY); + ret = file_open(&dev->devfile, filename, O_RDONLY | O_CLOEXEC); if (ret < 0) { ferr("ERROR: Failed to open %s: %d\n", filename, ret); diff --git a/drivers/mtd/filemtd.c b/drivers/mtd/filemtd.c index a7fc0ccc452f2..a181aa715e6f9 100644 --- a/drivers/mtd/filemtd.c +++ b/drivers/mtd/filemtd.c @@ -749,7 +749,7 @@ FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, size_t offset, /* Set the file open mode. */ - mode = O_RDOK | O_WROK; + mode = O_RDOK | O_WROK | O_CLOEXEC; /* Try to open the file. NOTE that block devices will use a character * driver proxy. diff --git a/drivers/mtd/mtd_config.c b/drivers/mtd/mtd_config.c index fe20a0c323a84..0e52099ec1b1a 100644 --- a/drivers/mtd/mtd_config.c +++ b/drivers/mtd/mtd_config.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1801,7 +1802,7 @@ int mtdconfig_unregister(void) FAR struct inode *inode; FAR struct mtdconfig_struct_s *dev; - ret = file_open(&file, "/dev/config", 0); + ret = file_open(&file, "/dev/config", O_CLOEXEC); if (ret < 0) { ferr("ERROR: open /dev/config failed: %d\n", ret); diff --git a/drivers/mtd/mtd_config_fs.c b/drivers/mtd/mtd_config_fs.c index 2d7c4060650cd..9c1096da000db 100644 --- a/drivers/mtd/mtd_config_fs.c +++ b/drivers/mtd/mtd_config_fs.c @@ -2081,7 +2081,7 @@ int mtdconfig_unregister_by_path(FAR const char *path) FAR struct inode *inode; FAR struct nvs_fs *fs; - ret = file_open(&file, path, 0); + ret = file_open(&file, path, O_CLOEXEC); if (ret < 0) { ferr("ERROR: open file %s err: %d\n", path, ret); diff --git a/drivers/net/slip.c b/drivers/net/slip.c index cebb56d98f2ee..5b3b7ccbd2b99 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -998,7 +998,7 @@ int slip_initialize(int intf, FAR const char *devname) self->dev.d_txavail = slip_txavail; /* New TX data callback */ self->dev.d_private = self; /* Used to recover SLIP I/F instance */ - ret = file_open(&self->tty, devname, O_RDWR | O_NONBLOCK); + ret = file_open(&self->tty, devname, O_RDWR | O_NONBLOCK | O_CLOEXEC); if (ret < 0) { diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c index a266d76a47203..ea1231d34d720 100644 --- a/drivers/rptun/rptun.c +++ b/drivers/rptun/rptun.c @@ -841,7 +841,7 @@ static int rptun_store_open(FAR void *store_, int len = 0x100; int ret; - ret = file_open(&store->file, path, O_RDONLY); + ret = file_open(&store->file, path, O_RDONLY | O_CLOEXEC); if (ret < 0) { return ret; diff --git a/drivers/sensors/fakesensor.c b/drivers/sensors/fakesensor_uorb.c similarity index 98% rename from drivers/sensors/fakesensor.c rename to drivers/sensors/fakesensor_uorb.c index 12b54ab804255..bba644704facb 100644 --- a/drivers/sensors/fakesensor.c +++ b/drivers/sensors/fakesensor_uorb.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/sensors/fakesensor.c + * drivers/sensors/fakesensor_urob.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -317,7 +317,8 @@ static int fakesensor_thread(int argc, char** argv) /* Open csv file and init file handle */ - ret = file_open(&sensor->data, sensor->file_path, O_RDONLY); + ret = file_open(&sensor->data, sensor->file_path, + O_RDONLY | O_CLOEXEC); if (ret < 0) { snerr("Failed to open file:%s, err:%d", sensor->file_path, ret); diff --git a/drivers/sensors/goldfish_gps_uorb.c b/drivers/sensors/goldfish_gps_uorb.c new file mode 100644 index 0000000000000..766d7faea0eb2 --- /dev/null +++ b/drivers/sensors/goldfish_gps_uorb.c @@ -0,0 +1,223 @@ +/**************************************************************************** + * drivers/sensors/goldfish_gps_uorb.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct goldfish_gps_s +{ + struct gps_lowerhalf_s gps; + struct file pipe; + volatile bool running; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int goldfish_gps_activate(FAR struct gps_lowerhalf_s *lower, + FAR struct file *filep, bool enabled); +static int goldfish_gps_thread(int argc, FAR char** argv); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct gps_ops_s g_goldfish_gps_ops = +{ + .activate = goldfish_gps_activate, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static inline int goldfish_gps_write_pipe(FAR struct file *pipe, + FAR const void *buffer, + size_t size) +{ + FAR const char *p = (FAR const char *)buffer; + + while (size > 0) + { + int n = file_write(pipe, p, size); + if (n < 0) + { + return n; + } + + p += n; + size -= n; + } + + return 0; +} + +static inline int goldfish_gps_open_pipe(FAR struct file *filep, + FAR const char *ns, + FAR const char *pipe_name, + int flags) +{ + char buf[256]; + int buf_len; + int ret; + + ret = file_open(filep, "/dev/goldfish_pipe", flags); + if (ret < 0) + { + snerr("Could not open '%s': %s", + "/dev/goldfish_pipe", strerror(-ret)); + return ret; + } + + if (ns) + { + buf_len = snprintf(buf, sizeof(buf), "pipe:%s:%s", ns, pipe_name); + } + else + { + buf_len = snprintf(buf, sizeof(buf), "pipe:%s", pipe_name); + } + + ret = goldfish_gps_write_pipe(filep, buf, buf_len + 1); + if (ret < 0) + { + snerr("Could not connect to the '%s' service: %s", + buf, strerror(-ret)); + file_close(filep); + return ret; + } + + return OK; +} + +static int goldfish_gps_activate(FAR struct gps_lowerhalf_s *gps, + FAR struct file *filep, + bool enabled) +{ + FAR struct goldfish_gps_s *priv = + container_of(gps, struct goldfish_gps_s, gps); + priv->running = enabled; + + return OK; +} + +static int goldfish_gps_thread(int argc, FAR char** argv) +{ + FAR struct goldfish_gps_s *priv = (FAR struct goldfish_gps_s *) + ((uintptr_t)strtoul(argv[1], NULL, 0)); + ssize_t len; + char buf[256]; + + while (true) + { + len = file_read(&priv->pipe, buf, sizeof(buf)); + if (priv->running && len > 0) + { + priv->gps.push_data(priv->gps.priv, buf, len, true); + } + } + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: goldfish_gps_init + * + * Description: + * Goldfish GPS driver entrypoint. + * + * Input Parameters: + * devno - The user specifies which device of this type, from 0. + * batch_number- The maximum number of batch. + * + * Returned Value: + * Zero (OK) or positive on success; a negated errno value on failure. + * + ****************************************************************************/ + +int goldfish_gps_init(int devno, uint32_t batch_number) +{ + FAR struct goldfish_gps_s *gps; + FAR char *argv[2]; + char arg1[32]; + int ret; + + /* Alloc memory for sensor */ + + gps = kmm_zalloc(sizeof(struct goldfish_gps_s)); + if (!gps) + { + return -ENOMEM; + } + + ret = goldfish_gps_open_pipe(&gps->pipe, "qemud", "gps", + O_RDWR | O_CLOEXEC); + if (ret < 0) + { + kmm_free(gps); + return ret; + } + + /* Create thread for sensor */ + + snprintf(arg1, 32, "%p", gps); + argv[0] = arg1; + argv[1] = NULL; + ret = kthread_create("goldfish_gps_thread", SCHED_PRIORITY_DEFAULT, + CONFIG_DEFAULT_TASK_STACKSIZE, + goldfish_gps_thread, argv); + if (ret < 0) + { + file_close(&gps->pipe); + kmm_free(gps); + return ret; + } + + /* Register sensor */ + + gps->gps.ops = &g_goldfish_gps_ops; + + return gps_register(&gps->gps, devno, batch_number); +} diff --git a/drivers/sensors/sensor_rpmsg.c b/drivers/sensors/sensor_rpmsg.c index 661f0ba5c81b3..4ac17fffbf0d9 100644 --- a/drivers/sensors/sensor_rpmsg.c +++ b/drivers/sensors/sensor_rpmsg.c @@ -463,7 +463,7 @@ sensor_rpmsg_alloc_proxy(FAR struct sensor_rpmsg_dev_s *dev, proxy->ept = ept; proxy->cookie = msg->cookie; - ret = file_open(&file, dev->path, SENSOR_REMOTE); + ret = file_open(&file, dev->path, SENSOR_REMOTE | O_CLOEXEC); if (ret < 0) { kmm_free(proxy); @@ -532,7 +532,7 @@ sensor_rpmsg_alloc_stub(FAR struct sensor_rpmsg_dev_s *dev, stub->ept = ept; stub->cookie = cookie; ret = file_open(&stub->file, dev->path, - O_RDOK | O_NONBLOCK | SENSOR_REMOTE); + O_RDOK | O_NONBLOCK | O_CLOEXEC | SENSOR_REMOTE); if (ret < 0) { kmm_free(stub); @@ -1075,7 +1075,7 @@ static int sensor_rpmsg_publish_handler(FAR struct rpmsg_endpoint *ept, struct file file; int ret; - ret = file_open(&file, dev->path, SENSOR_REMOTE); + ret = file_open(&file, dev->path, SENSOR_REMOTE | O_CLOEXEC); if (ret >= 0) { file_ioctl(&file, SNIOC_SET_BUFFER_NUMBER, cell->nbuffer); diff --git a/drivers/sensors/wtgahrs2.c b/drivers/sensors/wtgahrs2_uorb.c similarity index 99% rename from drivers/sensors/wtgahrs2.c rename to drivers/sensors/wtgahrs2_uorb.c index 337ea9cb007cb..ca06274ba4ffb 100644 --- a/drivers/sensors/wtgahrs2.c +++ b/drivers/sensors/wtgahrs2_uorb.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/sensors/wtgahrs2.c + * drivers/sensors/wtgahrs2_uorb.c * Driver for the Wit-Motion WTGAHRS2 accelerometer, gyroscope, magnetic, * angle, barometer, temperature, gps sensors by serial interface with host * @@ -453,7 +453,7 @@ int wtgahrs2_initialize(FAR const char *path, int devno) /* Open serial tty port and set baud rate */ - ret = file_open(&rtdata->file, path, O_RDWR); + ret = file_open(&rtdata->file, path, O_RDWR | O_CLOEXEC); if (ret < 0) { snerr("Failed to open wtgahrs2 serial:%s, err:%d", path, ret); diff --git a/drivers/serial/ptmx.c b/drivers/serial/ptmx.c index 2e0f273e6a0b2..39f311f65cf5b 100644 --- a/drivers/serial/ptmx.c +++ b/drivers/serial/ptmx.c @@ -204,7 +204,7 @@ static int ptmx_open(FAR struct file *filep) snprintf(devname, sizeof(devname), "/dev/pty%d", minor); memcpy(&temp, filep, sizeof(temp)); - ret = file_open(filep, devname, O_RDWR); + ret = file_open(filep, devname, O_RDWR | O_CLOEXEC); DEBUGASSERT(ret >= 0); /* file_open() should never fail */ /* Close the multiplexor device: /dev/ptmx */ diff --git a/drivers/serial/pty.c b/drivers/serial/pty.c index 4d160bbf189d2..9795660d3650f 100644 --- a/drivers/serial/pty.c +++ b/drivers/serial/pty.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -201,7 +202,7 @@ static int pty_pipe(FAR struct pty_devpair_s *devpair) pipe_a[0] = &devpair->pp_master.pd_src; pipe_a[1] = &devpair->pp_slave.pd_sink; - ret = file_pipe(pipe_a, CONFIG_PSEUDOTERM_TXBUFSIZE, 0); + ret = file_pipe(pipe_a, CONFIG_PSEUDOTERM_TXBUFSIZE, O_CLOEXEC); if (ret < 0) { return ret; @@ -210,7 +211,7 @@ static int pty_pipe(FAR struct pty_devpair_s *devpair) pipe_b[0] = &devpair->pp_slave.pd_src; pipe_b[1] = &devpair->pp_master.pd_sink; - ret = file_pipe(pipe_b, CONFIG_PSEUDOTERM_RXBUFSIZE, 0); + ret = file_pipe(pipe_b, CONFIG_PSEUDOTERM_RXBUFSIZE, O_CLOEXEC); if (ret < 0) { file_close(pipe_a[0]); diff --git a/drivers/syslog/syslog_filechannel.c b/drivers/syslog/syslog_filechannel.c index 8fa961256e3bb..0cf8ba23ef7f2 100644 --- a/drivers/syslog/syslog_filechannel.c +++ b/drivers/syslog/syslog_filechannel.c @@ -58,7 +58,7 @@ static void log_separate(FAR const char *log_file) { struct file fp; - if (file_open(&fp, log_file, (O_WRONLY | O_APPEND)) < 0) + if (file_open(&fp, log_file, (O_WRONLY | O_APPEND | O_CLOEXEC)) < 0) { return; } diff --git a/drivers/video/goldfish_camera.c b/drivers/video/goldfish_camera.c index 55996c11afd84..377ece237cc98 100644 --- a/drivers/video/goldfish_camera.c +++ b/drivers/video/goldfish_camera.c @@ -301,7 +301,7 @@ static ssize_t goldfish_camera_get_list(FAR goldfish_camera_priv_t **priv, ret = file_open(&file, CONFIG_GOLDFISH_CAMERA_PIPE_PATH, - O_RDWR); + O_RDWR | O_CLOEXEC); if (ret < 0) { verr("Failed to open: %s: %d\n", @@ -565,7 +565,7 @@ static int goldfish_camera_data_init(FAR struct imgdata_s *data) ret = file_open(&priv->file, CONFIG_GOLDFISH_CAMERA_PIPE_PATH, - O_RDWR); + O_RDWR | O_CLOEXEC); if (ret < 0) { verr("Failed to open: %s: %d\n", diff --git a/drivers/wireless/bluetooth/bt_uart_shim.c b/drivers/wireless/bluetooth/bt_uart_shim.c index c579a5a064250..7fc69472ebdb6 100644 --- a/drivers/wireless/bluetooth/bt_uart_shim.c +++ b/drivers/wireless/bluetooth/bt_uart_shim.c @@ -359,7 +359,7 @@ FAR struct btuart_lowerhalf_s *btuart_shim_getdevice(FAR const char *path) s = &n->state; - ret = file_open(&s->f, path, O_RDWR); + ret = file_open(&s->f, path, O_RDWR | O_CLOEXEC); if (ret < 0) { kmm_free(n); diff --git a/drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c b/drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c index cd3201555076f..c5b98edf42e5f 100644 --- a/drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c +++ b/drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c @@ -247,7 +247,7 @@ int bcmf_upload_file(FAR bcmf_interface_dev_t *ibus, uint32_t address, /* Open the file in the detached state */ - ret = file_open(&finfo, path, O_RDONLY); + ret = file_open(&finfo, path, O_RDONLY | O_CLOEXEC); if (ret < 0) { wlerr("ERROR: Failed to open the FILE MTD file %s: %d\n", path, ret); @@ -345,7 +345,7 @@ int bcmf_upload_nvram(FAR bcmf_interface_dev_t *ibus) goto out; } - ret = file_open(&finfo, nvfile, O_RDONLY); + ret = file_open(&finfo, nvfile, O_RDONLY | O_CLOEXEC); if (ret < 0) { goto out; diff --git a/drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c b/drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c index 20f0be4474770..1d3971f08725f 100644 --- a/drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c +++ b/drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c @@ -271,7 +271,7 @@ int bcmf_driver_download_clm(FAR struct bcmf_dev_s *priv) wlinfo("Download %d bytes\n", datalen); ret = file_open(&finfo, CONFIG_IEEE80211_BROADCOM_FWCLMNAME, - O_RDONLY); + O_RDONLY | O_CLOEXEC); if (ret < 0) { wlerr("ERROR: Failed to open the FILE MTD file\n", ret); diff --git a/net/local/local_fifo.c b/net/local/local_fifo.c index 4ff2caff03748..ea683d468fa74 100644 --- a/net/local/local_fifo.c +++ b/net/local/local_fifo.c @@ -240,7 +240,7 @@ static int local_rx_open(FAR struct local_conn_s *conn, FAR const char *path, int oflags = nonblock ? O_RDONLY | O_NONBLOCK : O_RDONLY; int ret; - ret = file_open(&conn->lc_infile, path, oflags); + ret = file_open(&conn->lc_infile, path, oflags | O_CLOEXEC); if (ret < 0) { nerr("ERROR: Failed on open %s for reading: %d\n", @@ -273,7 +273,8 @@ static int local_tx_open(FAR struct local_conn_s *conn, FAR const char *path, { int ret; - ret = file_open(&conn->lc_outfile, path, O_WRONLY | O_NONBLOCK); + ret = file_open(&conn->lc_outfile, path, O_WRONLY | O_NONBLOCK | + O_CLOEXEC); if (ret < 0) { nerr("ERROR: Failed on open %s for writing: %d\n", diff --git a/net/utils/net_snoop.c b/net/utils/net_snoop.c index f0da6cb368e35..ad5895bb704be 100644 --- a/net/utils/net_snoop.c +++ b/net/utils/net_snoop.c @@ -361,7 +361,7 @@ int snoop_open(FAR struct snoop_s *snoop, FAR const char *filename, } } - ret = file_open(&snoop->filep, filename, O_RDWR | O_CREAT); + ret = file_open(&snoop->filep, filename, O_RDWR | O_CREAT | O_CLOEXEC); if (ret < 0) { return ret;