diff --git a/TODO b/TODO index 2f3b29ae4f..f7df1b03a1 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated August 30, 2018) +NuttX TODO List (Last updated September 15, 2018) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -268,6 +268,10 @@ o Task/Scheduler (sched/) scheduler functions used within the OS: sched_getparam(), sched_setparam(), sched_getscheduler(), sched_setschedule(), and sched_setaffinity(), + 2018-09-15: This change has been completed for the case of + open() used within the OS. There are places under libs/ and + configs/ that have not been converted. I also note cases + where fopen() is called under libs/libc/netdb/. Status: Open Priority: Low. Things are working OK the way they are. But the design diff --git a/binfmt/builtin.c b/binfmt/builtin.c index 36bae470a9..1c3d04c8cd 100644 --- a/binfmt/builtin.c +++ b/binfmt/builtin.c @@ -48,6 +48,7 @@ #include #include +#include #include #include #include @@ -99,12 +100,11 @@ static int builtin_loadbinary(struct binary_s *binp) /* Open the binary file for reading (only) */ - fd = open(binp->filename, O_RDONLY); + fd = nx_open(binp->filename, O_RDONLY); if (fd < 0) { - int errval = get_errno(); - berr("ERROR: Failed to open binary %s: %d\n", binp->filename, errval); - return -errval; + berr("ERROR: Failed to open binary %s: %d\n", binp->filename, fd); + return fd; } /* If this file is a BINFS file system, then we can recover the name of diff --git a/binfmt/libelf/libelf_init.c b/binfmt/libelf/libelf_init.c index 3e09a6676a..faaab96ab2 100644 --- a/binfmt/libelf/libelf_init.c +++ b/binfmt/libelf/libelf_init.c @@ -48,6 +48,7 @@ #include #include +#include #include #include "libelf.h" @@ -162,12 +163,12 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo) /* Open the binary file for reading (only) */ - loadinfo->filfd = open(filename, O_RDONLY); + loadinfo->filfd = nx_open(filename, O_RDONLY); if (loadinfo->filfd < 0) { - int errval = get_errno(); - berr("Failed to open ELF binary %s: %d\n", filename, errval); - return -errval; + ret = loadinfo->filfd; + berr("Failed to open ELF binary %s: %d\n", filename, ret); + return ret; } /* Read the ELF ehdr from offset 0 */ diff --git a/binfmt/libnxflat/libnxflat_init.c b/binfmt/libnxflat/libnxflat_init.c index d3f48c0073..0c4607e28f 100644 --- a/binfmt/libnxflat/libnxflat_init.c +++ b/binfmt/libnxflat/libnxflat_init.c @@ -1,7 +1,7 @@ /**************************************************************************** * binfmt/libnxflat/libnxflat_init.c * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,6 +48,7 @@ #include #include +#include #include /**************************************************************************** @@ -108,12 +109,12 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo) /* Open the binary file */ - loadinfo->filfd = open(filename, O_RDONLY); + loadinfo->filfd = nx_open(filename, O_RDONLY); if (loadinfo->filfd < 0) { - int errval = get_errno(); - berr("Failed to open NXFLAT binary %s: %d\n", filename, errval); - return -errval; + ret = loadinfo->filfd; + berr("Failed to open NXFLAT binary %s: %d\n", filename, ret); + return ret; } /* Read the NXFLAT header from offset 0 */ diff --git a/binfmt/pcode.c b/binfmt/pcode.c index c0b6034b68..e6b40b3f91 100644 --- a/binfmt/pcode.c +++ b/binfmt/pcode.c @@ -1,7 +1,7 @@ /**************************************************************************** * binfmt/pcode.c * - * Copyright (C) 2014-2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -49,7 +49,7 @@ #include #include -#include +#include #include #include #include @@ -391,12 +391,11 @@ static int pcode_load(struct binary_s *binp) /* Open the binary file for reading (only) */ - fd = open(binp->filename, O_RDONLY); + fd = nx_open(binp->filename, O_RDONLY); if (fd < 0) { - int errval = get_errno(); - berr("ERROR: Failed to open binary %s: %d\n", binp->filename, errval); - return -errval; + berr("ERROR: Failed to open binary %s: %d\n", binp->filename, fd); + return fd; } /* Read the POFF file header */ diff --git a/configs/ea3131/src/lpc31_fillpage.c b/configs/ea3131/src/lpc31_fillpage.c index 89b0e094a2..0193dc2c9d 100644 --- a/configs/ea3131/src/lpc31_fillpage.c +++ b/configs/ea3131/src/lpc31_fillpage.c @@ -1,7 +1,8 @@ /**************************************************************************** * configs/ea3131/src/lpc31_fillpage.c * - * Copyright (C) 2010, 2012-2013, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2012-2013, 20172018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -277,7 +278,7 @@ static inline void lpc31_initsrc(void) /* Open the selected path for read-only access */ - g_pgsrc.fd = open(CONFIG_PAGING_BINPATH, O_RDONLY); + g_pgsrc.fd = nx_open(CONFIG_PAGING_BINPATH, O_RDONLY); DEBUGASSERT(g_pgsrc.fd >= 0); /* Then we are initialized */ diff --git a/configs/ea3152/src/lpc31_fillpage.c b/configs/ea3152/src/lpc31_fillpage.c index 629b50c8de..52d220da0b 100644 --- a/configs/ea3152/src/lpc31_fillpage.c +++ b/configs/ea3152/src/lpc31_fillpage.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/ea3152/src/lpc31_fillpage.c * - * Copyright (C) 2011, 2013, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013, 2017-2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -277,7 +277,7 @@ static inline void lpc31_initsrc(void) /* Open the selected path for read-only access */ - g_pgsrc.fd = open(CONFIG_PAGING_BINPATH, O_RDONLY); + g_pgsrc.fd = nx_open(CONFIG_PAGING_BINPATH, O_RDONLY); DEBUGASSERT(g_pgsrc.fd >= 0); /* Then we are initialized */ diff --git a/configs/nucleo-144/src/stm32_bbsram.c b/configs/nucleo-144/src/stm32_bbsram.c index a453ff3b3e..305f9bf7ca 100644 --- a/configs/nucleo-144/src/stm32_bbsram.c +++ b/configs/nucleo-144/src/stm32_bbsram.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-144/src/stm32_bbsram.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016m, 2018 Gregory Nutt. All rights reserved. * Author: David Sidrane * * Redistribution and use in source and binary forms, with or without @@ -50,8 +50,10 @@ #include #include -#include -#include +#include + +#include "up_internal.h" +#include "stm32_bbsram.h" #include "nucleo-144.h" @@ -290,7 +292,7 @@ static uint8_t g_sdata[STM32F7_BBSRAM_SIZE]; static int hardfault_get_desc(struct bbsramd_s *desc) { int ret = -ENOENT; - int fd = open(HARDFAULT_PATH, O_RDONLY); + int fd = nx_open(HARDFAULT_PATH, O_RDONLY); int rv; if (fd < 0) diff --git a/configs/nucleo-f4x1re/src/stm32_ajoystick.c b/configs/nucleo-f4x1re/src/stm32_ajoystick.c index 5a88e2e95b..eb481e06a8 100644 --- a/configs/nucleo-f4x1re/src/stm32_ajoystick.c +++ b/configs/nucleo-f4x1re/src/stm32_ajoystick.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-f3x1re/src/stm32_ajoystick.c * - * Copyright (C) 2014, 2016-2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016-2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -451,30 +451,15 @@ int board_ajoy_initialize(void) int i; #ifndef NO_JOYSTICK_ADC - int fd; - iinfo("Initialize ADC driver: /dev/adc0\n"); /* NOTE: The ADC driver was initialized earlier in the bring-up sequence. */ /* Open the ADC driver for reading. */ - fd = open("/dev/adc0", O_RDONLY); - if (fd < 0) - { - int errcode = get_errno(); - ierr("ERROR: Failed to open /dev/adc0: %d\n", errcode); - return -errcode; - } - - /* Detach the file structure from the file descriptor so that it can be - * used on any thread. - */ - - ret = file_detach(fd, &g_adcfile); + ret = file_open(&g_adcfile, "/dev/adc0", O_RDONLY); if (ret < 0) { - ierr("ERROR: Failed to detach from file descriptor: %d\n", ret); - (void)close(fd); + ierr("ERROR: Failed to open /dev/adc0: %d\n", ret); return ret; } #endif diff --git a/configs/nucleo-l452re/src/stm32_adc.c b/configs/nucleo-l452re/src/stm32_adc.c index ce54c0c9bd..f6b57420a4 100644 --- a/configs/nucleo-l452re/src/stm32_adc.c +++ b/configs/nucleo-l452re/src/stm32_adc.c @@ -172,7 +172,7 @@ int stm32l4_adc_measure_voltages(uint32_t *vrefint, uint32_t *vbat, uint32_t *ve int ret; int fd; - fd = open("/dev/adc0", O_RDONLY); + fd = nx_open("/dev/adc0", O_RDONLY); if (fd < 0) { aerr("ERROR: Cannot open ADC converter\n"); diff --git a/configs/nucleo-l476rg/src/stm32_ajoystick.c b/configs/nucleo-l476rg/src/stm32_ajoystick.c index d39bd4a150..ff9eda2c15 100644 --- a/configs/nucleo-l476rg/src/stm32_ajoystick.c +++ b/configs/nucleo-l476rg/src/stm32_ajoystick.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-l476rg/src/stm32_ajoystick.c * - * Copyright (C) 2014, 2016-2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016-2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -450,30 +450,16 @@ int board_ajoy_initialize(void) int i; #ifndef NO_JOYSTICK_ADC - int fd; iinfo("Initialize ADC driver: /dev/adc0\n"); /* NOTE: The ADC driver was initialized earlier in the bring-up sequence. */ /* Open the ADC driver for reading. */ - fd = open("/dev/adc0", O_RDONLY); - if (fd < 0) - { - int errcode = get_errno(); - ierr("ERROR: Failed to open /dev/adc0: %d\n", errcode); - return -errcode; - } - - /* Detach the file structure from the file descriptor so that it can be - * used on any thread. - */ - - ret = file_detach(fd, &g_adcfile); + ret = file_open(&g_adcfile, "/dev/adc0", O_RDONLY); if (ret < 0) { - ierr("ERROR: Failed to detach from file descriptor: %d\n", ret); - (void)close(fd); + ierr("ERROR: Failed to open /dev/adc0: %d\n", ret); return ret; } #endif diff --git a/configs/photon/src/stm32_rgbled.c b/configs/photon/src/stm32_rgbled.c index 648bb9d363..63e1bbf114 100644 --- a/configs/photon/src/stm32_rgbled.c +++ b/configs/photon/src/stm32_rgbled.c @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -163,7 +164,7 @@ int stm32_rgbled_setup(void) return ret; } - fd = open("/dev/rgbled0", O_WRONLY); + fd = nx_open("/dev/rgbled0", O_WRONLY); if (fd < 0) { lederr("ERROR: open failed: %d\n", fd); @@ -172,7 +173,7 @@ int stm32_rgbled_setup(void) /* Initialize led off */ - write(fd, "#000000", 8); + (void)nx_write(fd, "#000000", 8); close(fd); /* Now we are initialized */ diff --git a/configs/photon/src/stm32_wdt.c b/configs/photon/src/stm32_wdt.c index f8c0b36034..6f30f6a291 100644 --- a/configs/photon/src/stm32_wdt.c +++ b/configs/photon/src/stm32_wdt.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/photon/src/stm32_wdt.c * - * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2017-2018 Gregory Nutt. All rights reserved. * Author: Simon Piriou * * Redistribution and use in source and binary forms, with or without @@ -48,6 +48,7 @@ #include #include +#include #include #include @@ -69,12 +70,12 @@ static int wdog_daemon(int argc, char *argv[]) /* Open watchdog device */ - fd = open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY); + fd = nx_open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY); if (fd < 0) { - wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, errno); - return ERROR; + wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, fd); + return fd; } /* Start watchdog timer */ @@ -128,11 +129,11 @@ int photon_watchdog_initialize(void) /* Open the watchdog device */ - fd = open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY); + fd = nx_open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY); if (fd < 0) { - wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, errno); - return ERROR; + wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, fd); + return fd; } /* Set the watchdog timeout */ diff --git a/configs/sam4s-xplained-pro/src/sam_wdt.c b/configs/sam4s-xplained-pro/src/sam_wdt.c index 8dcecd638e..151cae0e76 100644 --- a/configs/sam4s-xplained-pro/src/sam_wdt.c +++ b/configs/sam4s-xplained-pro/src/sam_wdt.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/sam4s-xplained-pro/src/up_wdt.c * - * Copyright (C) 2014, 2016-2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016-2018 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * Bob Doiron * @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -98,10 +99,10 @@ static int wdog_daemon(int argc, char *argv[]) /* Open the watchdog device for reading */ wdinfo("Opening.\n"); - fd = open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY); + fd = nx_open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY); if (fd < 0) { - wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, errno); + wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, fd); goto errout; } @@ -160,11 +161,11 @@ int sam_watchdog_initialize(void) /* Open the watchdog device */ wdinfo("Opening.\n"); - fd = open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY); + fd = nx_open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY); if (fd < 0) { - wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, errno); - goto errout; + wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, fd); + goto fd; } /* Set the watchdog timeout */ diff --git a/configs/sama5d3-xplained/src/sam_ajoystick.c b/configs/sama5d3-xplained/src/sam_ajoystick.c index 4aa092f000..b9332260fb 100644 --- a/configs/sama5d3-xplained/src/sam_ajoystick.c +++ b/configs/sama5d3-xplained/src/sam_ajoystick.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sama5d3-xplained/src/sam_ajoystick.c * - * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -402,29 +402,15 @@ static int ajoy_interrupt(int irq, FAR void *context, FAR void *arg) int sam_ajoy_initialization(void) { int ret; - int fd; int i; /* NOTE: The ADC driver was initialized earlier in the bring-up sequence. */ /* Open the ADC driver for reading. */ - fd = open("/dev/adc0", O_RDONLY); - if (fd < 0) - { - int errcode = get_errno(); - ierr("ERROR: Failed to open /dev/adc0: %d\n", errcode); - return -errcode; - } - - /* Detach the file structure from the file descriptor so that it can be - * used on any thread. - */ - - ret = file_detach(fd, &g_adcfile); + ret = file_open(&g_adcfile, "/dev/adc0", O_RDONLY); if (ret < 0) { - ierr("ERROR: Failed to detach from file descriptor: %d\n", ret); - (void)close(fd); + ierr("ERROR: Failed to open /dev/adc0: %d\n", ret); return ret; } diff --git a/configs/stm32l4r9ai-disco/src/stm32_adc.c b/configs/stm32l4r9ai-disco/src/stm32_adc.c index eae3be2047..6234f00529 100644 --- a/configs/stm32l4r9ai-disco/src/stm32_adc.c +++ b/configs/stm32l4r9ai-disco/src/stm32_adc.c @@ -172,7 +172,7 @@ int stm32l4_adc_measure_voltages(uint32_t *vrefint, uint32_t *vbat, uint32_t *ve int ret; int fd; - fd = open("/dev/adc0", O_RDONLY); + fd = nx_open("/dev/adc0", O_RDONLY); if (fd < 0) { aerr("ERROR: Cannot open ADC converter\n"); diff --git a/drivers/bch/bchdev_unregister.c b/drivers/bch/bchdev_unregister.c index 1b4e1e138e..bdbdb7b3d7 100644 --- a/drivers/bch/bchdev_unregister.c +++ b/drivers/bch/bchdev_unregister.c @@ -1,7 +1,8 @@ /**************************************************************************** * drivers/bch/bchdev_unregister.c * - * Copyright (C) 2008-2009, 2012, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2012, 2016, 2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -64,7 +65,8 @@ * * Description: * Unregister character driver access to a block device that was created - * by a previous call to bchdev_register(). + / +* by a previous call to bchdev_register(). * ****************************************************************************/ @@ -85,11 +87,11 @@ int bchdev_unregister(FAR const char *chardev) /* Open the character driver associated with chardev */ - fd = open(chardev, O_RDONLY); + fd = nx_open(chardev, O_RDONLY); if (fd < 0) { - _err("ERROR: Failed to open %s: %d\n", chardev, errno); - return -errno; + _err("ERROR: Failed to open %s: %d\n", chardev, fd); + return fd; } /* Get a reference to the internal data structure. On success, we diff --git a/drivers/loop/losetup.c b/drivers/loop/losetup.c index 0a18eaff92..44921db30c 100644 --- a/drivers/loop/losetup.c +++ b/drivers/loop/losetup.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/loop/losetup.c * - * Copyright (C) 2008-2009, 2011, 2014-2015, 2017 Gregory Nutt. All + * Copyright (C) 2008-2009, 2011, 2014-2015, 2017-2018 Gregory Nutt. All * rights reserved. * Author: Gregory Nutt * @@ -373,7 +373,6 @@ int losetup(FAR const char *devname, FAR const char *filename, FAR struct loop_struct_s *dev; struct stat sb; int ret; - int fd = -1; /* Sanity check */ @@ -424,12 +423,13 @@ int losetup(FAR const char *devname, FAR const char *filename, * to open it readonly). */ + ret = -ENOSYS; if (!readonly) { - fd = open(filename, O_RDWR); + ret = file_open(&dev->devfile, filename, O_RDWR); } - if (fd >= 0) + if (ret >= 0) { dev->writeenabled = true; /* Success */ } @@ -438,25 +438,14 @@ int losetup(FAR const char *devname, FAR const char *filename, { /* If that fails, then try to open the device read-only */ - fd = open(filename, O_RDONLY); - if (fd < 0) + ret = file_open(&dev->devfile, filename, O_RDONLY); + if (ret < 0) { - ret = -get_errno(); ferr("ERROR: Failed to open %s: %d\n", filename, ret); goto errout_with_dev; } } - /* Detach the file from the file descriptor */ - - ret = file_detach(fd, &dev->devfile); - if (ret < 0) - { - ferr("ERROR: Failed to open %s: %d\n", filename, ret); - close(fd); - goto errout_with_dev; - } - /* Inode private data will be reference to the loop device structure */ ret = register_blockdriver(devname, &g_bops, 0, dev); diff --git a/drivers/mtd/filemtd.c b/drivers/mtd/filemtd.c index d1ca98e2ca..9ac59ad931 100644 --- a/drivers/mtd/filemtd.c +++ b/drivers/mtd/filemtd.c @@ -494,7 +494,6 @@ FAR struct mtd_dev_s *blockmtd_initialize(FAR const char *path, size_t offset, size_t nblocks; int mode; int ret; - int fd; /* Create an instance of the FILE MTD device state structure */ @@ -516,21 +515,10 @@ FAR struct mtd_dev_s *blockmtd_initialize(FAR const char *path, size_t offset, * driver proxy. */ - fd = open(path, mode); - if (fd <0) - { - ferr("ERROR: Failed to open the FILE MTD file %s\n", path); - kmm_free(priv); - return NULL; - } - - /* Detach the file descriptor from the open file */ - - ret = file_detach(fd, &priv->mtdfile); + ret = file_open(&priv->mtdfile, path, mode); if (ret < 0) { - ferr("ERROR: Failed to detail the FILE MTD file %s\n", path); - close(fd); + ferr("ERROR: Failed to open the FILE MTD file %s: %d\n", path, ret); kmm_free(priv); return NULL; } diff --git a/drivers/net/slip.c b/drivers/net/slip.c index 96e5a2dcdf..38c8bc5aa4 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/net/slip.c * - * Copyright (C) 2011-2012, 2015-2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2015-2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Reference: RFC 1055 @@ -935,6 +935,7 @@ int slip_initialize(int intf, FAR const char *devname) FAR struct slip_driver_s *priv; char buffer[8]; FAR char *argv[2]; + int ret; /* Get the interface structure associated with this interface number. */ @@ -955,11 +956,12 @@ int slip_initialize(int intf, FAR const char *devname) /* Open the device */ - priv->fd = open(devname, O_RDWR, 0666); + priv->fd = nx_open(devname, O_RDWR, 0666); if (priv->fd < 0) { - nerr("ERROR: Failed to open %s: %d\n", devname, errno); - return -errno; + ret = priv->fd; + nerr("ERROR: Failed to open %s: %d\n", devname, ret); + return ret; } /* Initialize the wait semaphore */ diff --git a/drivers/pipes/pipe.c b/drivers/pipes/pipe.c index f3a98e6351..1cf395dc22 100644 --- a/drivers/pipes/pipe.c +++ b/drivers/pipes/pipe.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/pipes/pipe.c * - * Copyright (C) 2008-2009, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2015, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -150,7 +150,7 @@ static int pipe_close(FAR struct file *filep) /* Perform common close operations */ - ret = pipecommon_close(filep); + ret = pipecommon_close(filep); if (ret == 0 && dev->d_refs == 0) { /* Release the pipe when there are no further open references to it. */ @@ -254,7 +254,7 @@ int pipe2(int fd[2], size_t bufsize) /* Get a write file descriptor */ - fd[1] = open(devname, O_WRONLY); + fd[1] = nx_open(devname, O_WRONLY); if (fd[1] < 0) { errcode = -fd[1]; @@ -263,7 +263,7 @@ int pipe2(int fd[2], size_t bufsize) /* Get a read file descriptor */ - fd[0] = open(devname, O_RDONLY); + fd[0] = nx_open(devname, O_RDONLY); if (fd[0] < 0) { errcode = -fd[0]; diff --git a/drivers/serial/ptmx.c b/drivers/serial/ptmx.c index 1ee1c08e3b..dc4a48352e 100644 --- a/drivers/serial/ptmx.c +++ b/drivers/serial/ptmx.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/serial/ptmx.c * - * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -248,8 +248,8 @@ static int ptmx_open(FAR struct file *filep) /* Open the master device: /dev/ptyN, where N=minor */ snprintf(devname, 16, "/dev/pty%d", minor); - fd = open(devname, O_RDWR); - DEBUGASSERT(fd >= 0); /* open() should never fail */ + fd = nx_open(devname, O_RDWR); + DEBUGASSERT(fd >= 0); /* nx_open() should never fail */ /* No unlink the master. This will remove it from the VFS namespace, * the driver will still persist because of the open count on the diff --git a/drivers/syslog/syslog_device.c b/drivers/syslog/syslog_device.c index f4a135cf3c..45d218715f 100644 --- a/drivers/syslog/syslog_device.c +++ b/drivers/syslog/syslog_device.c @@ -325,7 +325,6 @@ static int syslog_dev_outputready(void) int syslog_dev_initialize(FAR const char *devpath, int oflags, int mode) { - int fd; int ret; /* At this point, the only expected states are SYSLOG_UNINITIALIZED or @@ -366,12 +365,9 @@ int syslog_dev_initialize(FAR const char *devpath, int oflags, int mode) /* Open the device driver. */ - fd = open(devpath, oflags, mode); - if (fd < 0) + ret = file_open(&g_syslog_dev.sl_file, devpath, oflags, mode); + if (ret < 0) { - int errcode = get_errno(); - DEBUGASSERT(errcode > 0); - /* We failed to open the file. Perhaps it does exist? Perhaps it * exists, but is not ready because it depends on insertion of a * removable device? @@ -383,23 +379,6 @@ int syslog_dev_initialize(FAR const char *devpath, int oflags, int mode) */ g_syslog_dev.sl_state = SYSLOG_REOPEN; - return -errcode; - } - - /* Detach the file descriptor from the file structure. The file - * descriptor is a task-specific concept. Detaching the file - * descriptor allows us to use the device on all threads in all tasks. - */ - - ret = file_detach(fd, &g_syslog_dev.sl_file); - if (ret < 0) - { - /* This should not happen and means that something very bad has - * occurred. - */ - - g_syslog_dev.sl_state = SYSLOG_FAILURE; - close(fd); return ret; } diff --git a/fs/driver/fs_blockproxy.c b/fs/driver/fs_blockproxy.c index 0726b68a13..1cb47d08f9 100644 --- a/fs/driver/fs_blockproxy.c +++ b/fs/driver/fs_blockproxy.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/driver/fs_blockproxy.c * - * Copyright (C) 2015-2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2015-2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -54,6 +54,7 @@ #include #include +#include #if !defined(CONFIG_DISABLE_MOUNTPOINT) && \ !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS) @@ -202,10 +203,10 @@ int block_proxy(FAR const char *blkdev, int oflags) /* Open the newly created character driver */ oflags &= ~(O_CREAT | O_EXCL | O_APPEND | O_TRUNC); - fd = open(chardev, oflags); + fd = nx_open(chardev, oflags); if (fd < 0) { - ret = -errno; + ret = fd; ferr("ERROR: Failed to open %s: %d\n", chardev, ret); goto errout_with_bchdev; } diff --git a/fs/inode/Make.defs b/fs/inode/Make.defs index bafe86e814..158f30514a 100644 --- a/fs/inode/Make.defs +++ b/fs/inode/Make.defs @@ -40,7 +40,7 @@ ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) CSRCS += fs_files.c fs_foreachinode.c fs_inode.c fs_inodeaddref.c CSRCS += fs_inodebasename.c fs_inodefind.c fs_inodefree.c fs_inoderelease.c CSRCS += fs_inoderemove.c fs_inodereserve.c fs_inodesearch.c -CSRCS += fs_filedetach.c +CSRCS += fs_fileopen.c fs_filedetach.c # Include inode/utils build support diff --git a/fs/inode/fs_fileopen.c b/fs/inode/fs_fileopen.c new file mode 100644 index 0000000000..08f2ab8229 --- /dev/null +++ b/fs/inode/fs_fileopen.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * fs/inode/fs_fileopen.c + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#include "inode/inode.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: file_open + * + * Description: + * file_open() is similar to the standard 'open' interface except that it + * returns an instance of 'struct file' rather than a file descriptor. It + * also is not a cancellation point and does not modify the errno variable. + * + * Input Parameters: + * filep - The caller provided location in which to return the 'struct + * file' instance. + * path - The full path to the file to be open. + * oflags - open flags + * ... - Variable number of arguments, may include 'mode_t mode' + * + * Returned Value: + * Zero (OK) is returned on success. On failure, a negated errno value is + * returned. + * + ****************************************************************************/ + +int file_open(FAR struct file *filep, FAR const char *path, int oflags, ...) +{ + va_list ap; + int ret; + int fd; + + /* At present, this is just a placeholder. It is just a wrapper around + * nx_open() followed by a called to file_detach(). Ideally, this should + * a native open function that opens the VFS node directly without using + * any file descriptors. + */ + + va_start(ap, oflags); + fd = nx_vopen(path, oflags, ap); + va_end(ap); + + if (fd < 0) + { + return fd; + } + + /* Detach the file structure from the file descriptor so that it can be + * used on any thread. + */ + + ret = file_detach(fd, filep); + if (ret < 0) + { + (void)close(fd); + return ret; + } + + return OK; +} diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c index 6016611908..f3f3cff863 100644 --- a/fs/vfs/fs_open.c +++ b/fs/vfs/fs_open.c @@ -46,9 +46,7 @@ #include #include #include -#ifdef CONFIG_FILE_MODE #include -#endif #include #include @@ -82,14 +80,22 @@ int inode_checkflags(FAR struct inode *inode, int oflags) } /**************************************************************************** - * Name: open + * Name: nx_vopen * * Description: - * Standard 'open' interface + * nx_vopen() is identical to 'nx_open' except that it accepts a va_list + * as an argument versus taking a variable length list of arguments. + * + * nx_vopen() is an internal NuttX interface and should not be called from + * applications. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure. * ****************************************************************************/ -int open(FAR const char *path, int oflags, ...) +int nx_vopen(FAR const char *path, int oflags, va_list ap) { struct inode_search_s desc; FAR struct file *filep; @@ -100,14 +106,9 @@ int open(FAR const char *path, int oflags, ...) int ret; int fd; - /* open() is a cancellation point */ - - (void)enter_cancellation_point(); - if (path == NULL) { - set_errno(EINVAL); - goto errout; + return -EINVAL; } #ifdef CONFIG_FILE_MODE @@ -119,7 +120,6 @@ int open(FAR const char *path, int oflags, ...) if ((oflags & (O_WRONLY | O_CREAT)) != 0) { - va_list ap; va_start(ap, oflags); mode = va_arg(ap, mode_t); va_end(ap); @@ -138,7 +138,6 @@ int open(FAR const char *path, int oflags, ...) * symbolic link." */ - ret = -ret; goto errout_with_search; } @@ -169,14 +168,12 @@ int open(FAR const char *path, int oflags, ...) fd = block_proxy(path, oflags); if (fd < 0) { - ret = -fd; goto errout_with_search; } /* Return the file descriptor */ RELEASE_SEARCH(&desc); - leave_cancellation_point(); return fd; } else @@ -193,7 +190,7 @@ int open(FAR const char *path, int oflags, ...) if (!INODE_IS_DRIVER(inode) || !inode->u.i_ops) #endif { - ret = ENXIO; + ret = -ENXIO; goto errout_with_inode; } @@ -202,7 +199,6 @@ int open(FAR const char *path, int oflags, ...) ret = inode_checkflags(inode, oflags); if (ret < 0) { - ret = -ret; goto errout_with_inode; } @@ -211,7 +207,7 @@ int open(FAR const char *path, int oflags, ...) fd = files_allocate(inode, oflags, 0, 0); if (fd < 0) { - ret = EMFILE; + ret = -EMFILE; goto errout_with_inode; } @@ -220,7 +216,6 @@ int open(FAR const char *path, int oflags, ...) ret = fs_getfilep(fd, &filep); if (ret < 0) { - ret = -ret; goto errout_with_inode; } @@ -246,7 +241,6 @@ int open(FAR const char *path, int oflags, ...) if (ret < 0) { - ret = -ret; goto errout_with_fd; } @@ -282,7 +276,6 @@ int open(FAR const char *path, int oflags, ...) #endif RELEASE_SEARCH(&desc); - leave_cancellation_point(); return fd; errout_with_fd: @@ -293,9 +286,74 @@ errout_with_inode: errout_with_search: RELEASE_SEARCH(&desc); - set_errno(ret); - -errout: - leave_cancellation_point(); - return ERROR; + return ret; +} + +/**************************************************************************** + * Name: nx_open + * + * Description: + * nx_open() is similar to the standard 'open' interface except that is is + * not a cancellation point and it does not modify the errno variable. + * + * nx_open() is an internal NuttX interface and should not be called from + * applications. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure. + * + ****************************************************************************/ + +int nx_open(FAR const char *path, int oflags, ...) +{ + va_list ap; + int fd; + + /* Let nx_vopen() do all of the work */ + + va_start(ap, oflags); + fd = nx_vopen(path, oflags, ap); + va_end(ap); + + return fd; +} + +/**************************************************************************** + * Name: open + * + * Description: + * Standard 'open' interface + * + * Returned Value: + * Zero (OK) is returned on success; -1 (ERROR) is returned on any failure + * the the errno value set appropriately. + * + ****************************************************************************/ + +int open(FAR const char *path, int oflags, ...) +{ + va_list ap; + int fd; + + /* open() is a cancellation point */ + + (void)enter_cancellation_point(); + + /* Let nx_vopen() do most of the work */ + + va_start(ap, oflags); + fd = nx_vopen(path, oflags, ap); + va_end(ap); + + /* Set the errno value if any errors were reported by nx_open() */ + + if (fd < 0) + { + set_errno(-fd); + fd = ERROR; + } + + leave_cancellation_point(); + return fd; } diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 64a742c63c..78766a458a 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -83,12 +83,22 @@ */ #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) +# ifdef CONFIG_CPP_HAVE_VARARGS +# define _NX_OPEN(p,f,...) nx_open(f,b,##__VA_ARGS__) +# else +# define _NX_OPEN nx_open +# endif # define _NX_READ(f,b,s) nx_read(f,b,s) # define _NX_WRITE(f,b,s) nx_write(f,b,s) # define _NX_GETERRNO(r) (-(r)) # define _NX_SETERRNO(r) set_errno(-(r)) # define _NX_GETERRVAL(r) (r) #else +# ifdef CONFIG_CPP_HAVE_VARARGS +# define _NX_OPEN(p,f,...) open(f,b,##__VA_ARGS__) +# else +# define _NX_OPEN open +# endif # define _NX_READ(f,b,s) read(f,b,s) # define _NX_WRITE(f,b,s) write(f,b,s) # define _NX_GETERRNO(r) errno @@ -718,6 +728,29 @@ int fs_dupfd2(int fd1, int fd2); #endif #endif +/**************************************************************************** + * Name: file_open + * + * Description: + * file_open() is similar to the standard 'open' interface except that it + * returns an instance of 'struct file' rather than a file descriptor. It + * also is not a cancellation point and does not modify the errno variable. + * + * Input Parameters: + * filep - The caller provided location in which to return the 'struct + * file' instance. + * path - The full path to the file to be open. + * oflags - open flags + * ... - Variable number of arguments, may include 'mode_t mode' + * + * Returned Value: + * Zero (OK) is returned on success. On failure, a negated errno value is + * returned. + * + ****************************************************************************/ + +int file_open(FAR struct file *filep, FAR const char *path, int oflags, ...); + /**************************************************************************** * Name: file_detach * @@ -907,6 +940,28 @@ ssize_t lib_sendfile(int outfd, int infd, off_t *offset, size_t count); int fs_getfilep(int fd, FAR struct file **filep); #endif +/**************************************************************************** + * Name: nx_open and nx_vopen + * + * Description: + * nx_open() is similar to the standard 'open' interface except that is is + * not a cancellation point and it does not modify the errno variable. + * + * nx_vopen() is identical except that it accepts a va_list as an argument + * versus taking a variable length list of arguments. + * + * nx_open() and nx_vopen are internal NuttX interface and should not be + * called from applications. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure. + * + ****************************************************************************/ + +int nx_vopen(FAR const char *path, int oflags, va_list ap); +int nx_open(FAR const char *path, int oflags, ...); + /**************************************************************************** * Name: file_read * diff --git a/libs/libc/modlib/modlib_init.c b/libs/libc/modlib/modlib_init.c index 008ca8dfc8..691efd0f0e 100644 --- a/libs/libc/modlib/modlib_init.c +++ b/libs/libc/modlib/modlib_init.c @@ -1,7 +1,7 @@ /**************************************************************************** * libs/libc/modlib/modlib_init.c * - * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017-2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,7 @@ #include #include +#include #include #include "modlib/modlib.h" @@ -160,10 +161,10 @@ int modlib_initialize(FAR const char *filename, /* Open the binary file for reading (only) */ - loadinfo->filfd = open(filename, O_RDONLY); + loadinfo->filfd = _NX_OPEN(filename, O_RDONLY); if (loadinfo->filfd < 0) { - int errval = get_errno(); + int errval = _NX_GETERRNO(loadinfo->filfd); berr("ERROR: Failed to open ELF binary %s: %d\n", filename, errval); return -errval; } diff --git a/libs/libc/stdio/lib_fopen.c b/libs/libc/stdio/lib_fopen.c index 60af79d5fd..2006fb7e7d 100644 --- a/libs/libc/stdio/lib_fopen.c +++ b/libs/libc/stdio/lib_fopen.c @@ -114,7 +114,7 @@ FAR FILE *fopen(FAR const char *path, FAR const char *mode) fd = open(path, oflags, 0666); - /* If the open was successful, then fdopen() the fil using the file + /* If the open was successful, then call fdopen() using the file * descriptor returned by open. If open failed, then just return the * NULL stream -- open() has already set the errno. */ @@ -131,6 +131,7 @@ FAR FILE *fopen(FAR const char *path, FAR const char *mode) (void)close(fd); } } + return ret; } diff --git a/net/local/local_fifo.c b/net/local/local_fifo.c index 85d8769816..de04dd3bce 100644 --- a/net/local/local_fifo.c +++ b/net/local/local_fifo.c @@ -254,35 +254,22 @@ 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; - int fd; - fd = open(path, oflags); - if (fd < 0) + ret = file_open(&conn->lc_infile, path, oflags); + if (ret < 0) { - int errcode = get_errno(); - DEBUGASSERT(errcode > 0); - nerr("ERROR: Failed on open %s for reading: %d\n", - path, errcode); + path, ret); - /* Map the errcode to something consistent with the return + /* Map the error code to something consistent with the return * error codes from connect(): * - * If errcode is ENOENT, meaning that the FIFO does exist, + * If error is ENOENT, meaning that the FIFO does exist, * return EFAULT meaning that the socket structure address is * outside the user's address space. */ - return errcode == ENOENT ? -EFAULT : -errcode; - } - - /* Detach the file descriptor from the open file instance */ - - ret = file_detach(fd, &conn->lc_infile); - if (ret < 0) - { - close(fd); - return ret; + return ret == -ENOENT ? -EFAULT : ret; } return OK; @@ -301,35 +288,22 @@ static int local_tx_open(FAR struct local_conn_s *conn, FAR const char *path, { int oflags = nonblock ? O_WRONLY | O_NONBLOCK : O_WRONLY; int ret; - int fd; - fd = open(path, oflags); - if (fd < 0) + ret = file_open(&conn->lc_outfile, path, oflags); + if (ret < 0) { - int errcode = get_errno(); - DEBUGASSERT(errcode > 0); - nerr("ERROR: Failed on open %s for writing: %d\n", - path, errcode); + path, ret); - /* Map the errcode to something consistent with the return + /* Map the error code to something consistent with the return * error codes from connect(): * - * If errcode is ENOENT, meaning that the FIFO does exist, + * If error is ENOENT, meaning that the FIFO does exist, * return EFAULT meaning that the socket structure address is * outside the user's address space. */ - return errcode == ENOENT ? -EFAULT : -errcode; - } - - /* Detach the file descriptor from the open file instance */ - - ret = file_detach(fd, &conn->lc_outfile); - if (ret < 0) - { - close(fd); - return ret; + return ret == -ENOENT ? -EFAULT : -errcode; } return OK; diff --git a/net/route/net_fileroute.c b/net/route/net_fileroute.c index 7e6342c17a..30ee1d23ca 100644 --- a/net/route/net_fileroute.c +++ b/net/route/net_fileroute.c @@ -110,27 +110,13 @@ int net_openroute_detached(FAR const char *pathname, int oflags, FAR struct file *filep) { int ret; - int fd; - /* Open the file for read/write access. Here we borrow the file descriptor - * of this tread of execution. We won't use it for long. - */ + /* Open the file for read/write access. */ - fd = open(pathname, oflags, 0644); - if (fd < 0) - { - int errcode = get_errno(); - nerr("ERROR: Failed to open %s: %d\n", pathname, errcode); - return -errcode; - } - - /* Now detach the file descriptor */ - - ret = file_detach(fd, filep); + ret = file_open(filep, pathname, oflags, 0644); if (ret < 0) { - nerr("ERROR: file_detach() failed: %d\n", ret); - (void)close(fd); + nerr("ERROR: Failed to open %s: %d\n", pathname, ret); return ret; } diff --git a/sched/group/group_setupidlefiles.c b/sched/group/group_setupidlefiles.c index 04c809bf82..8aca4c750a 100644 --- a/sched/group/group_setupidlefiles.c +++ b/sched/group/group_setupidlefiles.c @@ -1,7 +1,8 @@ /**************************************************************************** * sched/group/group_setupidlefiles.c * - * Copyright (C) 2007-2010, 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2010, 2012-2013, 2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -104,7 +105,7 @@ int group_setupidlefiles(FAR struct task_tcb_s *tcb) */ #if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_DEV_CONSOLE) - fd = open("/dev/console", O_RDWR); + fd = nx_open("/dev/console", O_RDWR); if (fd == 0) { /* Successfully opened /dev/console as stdin (fd == 0) */ @@ -125,7 +126,7 @@ int group_setupidlefiles(FAR struct task_tcb_s *tcb) } else { - serr("ERROR: Failed to open /dev/console: %d\n", errno); + serr("ERROR: Failed to open /dev/console: %d\n", fd); } return -ENFILE; diff --git a/sched/task/task_spawnparms.c b/sched/task/task_spawnparms.c index 8503afe855..9b1435bcb1 100644 --- a/sched/task/task_spawnparms.c +++ b/sched/task/task_spawnparms.c @@ -46,6 +46,7 @@ #include #include +#include #include "task/spawn.h" #include "task/task.h" @@ -120,10 +121,10 @@ static inline int spawn_open(FAR struct spawn_open_file_action_s *action) sinfo("Open'ing path=%s oflags=%04x mode=%04x\n", action->path, action->oflags, action->mode); - fd = open(action->path, action->oflags, action->mode); + fd = nx_open(action->path, action->oflags, action->mode); if (fd < 0) { - ret = get_errno(); + ret = fd; serr("ERROR: open failed: %d\n", ret); }