You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/05/04 13:20:09 UTC

[incubator-nuttx] branch master updated (d385169 -> 32b79b2)

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from d385169  boards: qemu-i486: Mount procfs in board_app_initialize()
     new 1da8cd6  fs/vfs: Add nx_poll function
     new 390f9a5  fs/vfs: Add nx_dup and nx_dup2 function
     new de2a9d8  sched: add nx_wait, nx_waitid and nx_waitpid
     new 929292f  mqueue: Add nxmq_open/nxmq_close/nxmq_unlink function
     new 32b79b2  Rename pipe2/mkfifo2 to nx_pipe/nx_mkfifo

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 drivers/pipes/fifo.c            |  26 +--
 drivers/pipes/pipe.c            |  22 +--
 drivers/serial/pty.c            |  14 +-
 fs/mqueue/mq_close.c            |  66 +++++--
 fs/mqueue/mq_open.c             | 128 +++++++++-----
 fs/mqueue/mq_unlink.c           |  66 +++++--
 fs/vfs/fs_dup.c                 |  59 ++++---
 fs/vfs/fs_dup2.c                |  76 ++++----
 fs/vfs/fs_dupfd.c               |  29 +---
 fs/vfs/fs_dupfd2.c              |  33 +---
 fs/vfs/fs_poll.c                |  99 ++++++-----
 include/nuttx/drivers/drivers.h |  32 ++--
 include/nuttx/fs/fs.h           |  87 +++++++---
 include/nuttx/mqueue.h          |  87 ++++++++++
 include/nuttx/net/net.h         |  27 +--
 include/nuttx/sched.h           |  10 ++
 include/sys/syscall.h           |  14 +-
 libs/libc/misc/lib_mkfifo.c     |  12 +-
 libs/libc/unistd/lib_pipe.c     |  12 +-
 net/socket/net_dup.c            |  18 +-
 net/socket/net_dup2.c           |  12 +-
 sched/sched/sched_wait.c        |  11 +-
 sched/sched/sched_waitid.c      | 198 +++++++++++----------
 sched/sched/sched_waitpid.c     | 374 ++++++++++++++++++++--------------------
 syscall/syscall.csv             |   4 +-
 syscall/syscall_lookup.h        |   7 +-
 syscall/syscall_stublookup.c    |   7 +-
 27 files changed, 903 insertions(+), 627 deletions(-)


[incubator-nuttx] 02/05: fs/vfs: Add nx_dup and nx_dup2 function

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 390f9a5fb711ac7e0c1db0bb7b9d8f365eaffc68
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon May 4 03:07:01 2020 +0800

    fs/vfs: Add nx_dup and nx_dup2 function
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 fs/vfs/fs_dup.c         | 59 +++++++++++++++++++++++++-------------
 fs/vfs/fs_dup2.c        | 76 ++++++++++++++++++++++++++++---------------------
 fs/vfs/fs_dupfd.c       | 29 +++++--------------
 fs/vfs/fs_dupfd2.c      | 33 +++++----------------
 include/nuttx/fs/fs.h   | 70 +++++++++++++++++++++++++++++----------------
 include/nuttx/net/net.h | 27 ++++++------------
 net/socket/net_dup.c    | 18 ++++--------
 net/socket/net_dup2.c   | 12 ++++----
 8 files changed, 163 insertions(+), 161 deletions(-)

diff --git a/fs/vfs/fs_dup.c b/fs/vfs/fs_dup.c
index a85e8c9..5848877 100644
--- a/fs/vfs/fs_dup.c
+++ b/fs/vfs/fs_dup.c
@@ -51,56 +51,75 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Name: dup
+ * Name: nx_dup
  *
  * Description:
- *   Clone a file or socket descriptor to an arbitrary descriptor number
+ *   nx_dup() is similar to the standard 'dup' interface except that is
+ *   not a cancellation point and it does not modify the errno variable.
+ *
+ *   nx_dup() is an internal NuttX interface and should not be called from
+ *   applications.
+ *
+ * Returned Value:
+ *   The new file descriptor is returned on success; a negated errno value is
+ *   returned on any failure.
  *
  ****************************************************************************/
 
-int dup(int fd)
+int nx_dup(int fd)
 {
-  int ret = OK;
-
   /* Check the range of the descriptor to see if we got a file or a socket
    * descriptor.
    */
 
-  if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
+  if (fd < CONFIG_NFILE_DESCRIPTORS)
     {
       /* Its a valid file descriptor.. dup the file descriptor using any
-       * other file descriptor.  fd_dupfd() sets the errno value in the
-       * event of any failures.
+       * other file descriptor.
        */
 
-      ret = fs_dupfd(fd, 0);
+      return fs_dupfd(fd, 0);
     }
   else
     {
-      /* Not a valid file descriptor.  Did we get a valid socket descriptor? */
+      /* Not a valid file descriptor.
+       * Did we get a valid socket descriptor?
+       */
 
 #ifdef CONFIG_NET
-      if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS))
+      if (fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS))
         {
-          /* Yes.. dup the socket descriptor.  The errno value is not set. */
+          /* Yes.. dup the socket descriptor. */
 
-          ret = net_dup(fd, CONFIG_NFILE_DESCRIPTORS);
+          return net_dup(fd, CONFIG_NFILE_DESCRIPTORS);
         }
       else
 #endif
         {
           /* No.. then it is a bad descriptor number */
 
-          ret = -EBADF;
+          return -EBADF;
         }
+    }
+}
+
+/****************************************************************************
+ * Name: dup
+ *
+ * Description:
+ *   Clone a file or socket descriptor to an arbitrary descriptor number
+ *
+ ****************************************************************************/
 
-      /* Set the errno value on failures */
+int dup(int fd)
+{
+  int ret;
 
-      if (ret < 0)
-        {
-          set_errno(-ret);
-          ret = ERROR;
-        }
+  ret = nx_dup(fd);
+  if (ret < 0)
+    {
+      set_errno(-ret);
+      ret = ERROR;
     }
 
   return ret;
diff --git a/fs/vfs/fs_dup2.c b/fs/vfs/fs_dup2.c
index fdf4511..33ccf8f 100644
--- a/fs/vfs/fs_dup2.c
+++ b/fs/vfs/fs_dup2.c
@@ -46,69 +46,81 @@
 
 #include "inode/inode.h"
 
-/* This logic in this applies only when both socket and file descriptors are
- * in that case, this function discriminates which type of dup2 is being
- * performed.
- */
-
-#ifdef CONFIG_NET
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: dup2
+ * Name: nx_dup2
  *
  * Description:
- *   Clone a file descriptor or socket descriptor to a specific descriptor
- *   number
+ *   nx_dup2() is similar to the standard 'dup2' interface except that is
+ *   not a cancellation point and it does not modify the errno variable.
+ *
+ *   nx_dup2() 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 return on
+ *   any failure.
  *
  ****************************************************************************/
 
-int dup2(int fd1, int fd2)
+int nx_dup2(int fd1, int fd2)
 {
   /* Check the range of the descriptor to see if we got a file or a socket
    * descriptor.
    */
 
-  if ((unsigned int)fd1 >= CONFIG_NFILE_DESCRIPTORS)
+  if (fd1 >= CONFIG_NFILE_DESCRIPTORS)
     {
-      int ret;
-
-      /* Not a valid file descriptor.  Did we get a valid socket descriptor? */
+      /* Not a valid file descriptor.
+       * Did we get a valid socket descriptor?
+       */
 
-      if ((unsigned int)fd1 < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS))
+#ifdef CONFIG_NET
+      if (fd1 < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS))
         {
-          /* Yes.. dup the socket descriptor. The errno value is not set. */
+          /* Yes.. dup the socket descriptor. */
 
-          ret = net_dup2(fd1, fd2);
+          return net_dup2(fd1, fd2);
         }
       else
+#endif
         {
           /* No.. then it is a bad descriptor number */
 
-          ret = -EBADF;
-        }
-
-      /* Set the errno value on failures */
-
-      if (ret < 0)
-        {
-          set_errno(-ret);
-          ret = ERROR;
+          return -EBADF;
         }
-
-      return ret;
     }
   else
     {
-      /* Its a valid file descriptor.. dup the file descriptor.  fd_dupfd()
-       * sets the errno value in the event of any failures.
+      /* Its a valid file descriptor.. dup the file descriptor.
        */
 
       return fs_dupfd2(fd1, fd2);
     }
 }
 
-#endif /* CONFIG_NET */
+/****************************************************************************
+ * Name: dup2
+ *
+ * Description:
+ *   Clone a file descriptor or socket descriptor to a specific descriptor
+ *   number
+ *
+ ****************************************************************************/
+
+int dup2(int fd1, int fd2)
+{
+  int ret;
+
+  ret = nx_dup2(fd1, fd2);
+  if (ret < 0)
+    {
+      set_errno(-ret);
+      ret = ERROR;
+    }
+
+  return ret;
+}
diff --git a/fs/vfs/fs_dupfd.c b/fs/vfs/fs_dupfd.c
index dd323d5..d8bd080 100644
--- a/fs/vfs/fs_dupfd.c
+++ b/fs/vfs/fs_dupfd.c
@@ -47,8 +47,7 @@
  *
  * Description:
  *   Equivalent to the non-standard fs_dupfd() function except that it
- *   accepts a struct file instance instead of a file descriptor and does
- *   not set the errno variable.
+ *   accepts a struct file instance instead of a file descriptor.
  *
  * Returned Value:
  *   Zero (OK) is returned on success; a negated errno value is returned on
@@ -89,19 +88,15 @@ int file_dup(FAR struct file *filep, int minfd)
 }
 
 /****************************************************************************
- * Name: fs_dupfd OR dup
+ * Name: fs_dupfd
  *
  * Description:
  *   Clone a file descriptor 'fd' to an arbitrary descriptor number (any
- *   value greater than or equal to 'minfd'). If socket descriptors are
- *   implemented, then this is called by dup() for the case of file
- *   descriptors.  If socket descriptors are not implemented, then this
- *   function IS dup().
+ *   value greater than or equal to 'minfd').
  *
  * Returned Value:
- *   fs_dupfd is sometimes an OS internal function and sometimes is a direct
- *   substitute for dup().  So it must return an errno value as though it
- *   were dup().
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
  *
  ****************************************************************************/
 
@@ -115,22 +110,12 @@ int fs_dupfd(int fd, int minfd)
   ret = fs_getfilep(fd, &filep);
   if (ret < 0)
     {
-      goto errout;
+      return ret;
     }
 
   DEBUGASSERT(filep != NULL);
 
   /* Let file_dup() do the real work */
 
-  ret = file_dup(filep, minfd);
-  if (ret < 0)
-    {
-      goto errout;
-    }
-
-  return ret;
-
-errout:
-  set_errno(-ret);
-  return ERROR;
+  return file_dup(filep, minfd);
 }
diff --git a/fs/vfs/fs_dupfd2.c b/fs/vfs/fs_dupfd2.c
index 0d0f35c..d314a22 100644
--- a/fs/vfs/fs_dupfd2.c
+++ b/fs/vfs/fs_dupfd2.c
@@ -61,26 +61,18 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Name: fs_dupfd2 OR dup2
+ * Name: fs_dupfd2
  *
  * Description:
- *   Clone a file descriptor to a specific descriptor number. If socket
- *   descriptors are implemented, then this is called by dup2() for the
- *   case of file descriptors.  If socket descriptors are not implemented,
- *   then this function IS dup2().
+ *   Clone a file descriptor to a specific descriptor number.
  *
  * Returned Value:
- *   fs_dupfd is sometimes an OS internal function and sometimes is a direct
- *   substitute for dup2().  So it must return an errno value as though it
- *   were dup2().
+ *   Zero (OK) is returned on success; a negated errno value is return on
+ *   any failure.
  *
  ****************************************************************************/
 
-#ifdef CONFIG_NET
 int fs_dupfd2(int fd1, int fd2)
-#else
-int dup2(int fd1, int fd2)
-#endif
 {
   FAR struct file *filep1;
   FAR struct file *filep2 = NULL;
@@ -96,7 +88,7 @@ int dup2(int fd1, int fd2)
 
   if (ret < 0)
     {
-      goto errout;
+      return ret;
     }
 
   DEBUGASSERT(filep1 != NULL && filep2 != NULL);
@@ -105,8 +97,7 @@ int dup2(int fd1, int fd2)
 
   if (!DUP_ISOPEN(filep1))
     {
-      ret = -EBADF;
-      goto errout;
+      return -EBADF;
     }
 
   /* Handle a special case */
@@ -118,15 +109,5 @@ int dup2(int fd1, int fd2)
 
   /* Perform the dup2 operation */
 
-  ret = file_dup2(filep1, filep2);
-  if (ret < 0)
-    {
-      goto errout;
-    }
-
-  return OK;
-
-errout:
-  set_errno(-ret);
-  return ERROR;
+  return file_dup2(filep1, filep2);
 }
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index 8343c36..9f866f2 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -721,8 +721,7 @@ void files_releaselist(FAR struct filelist *list);
  *
  * Description:
  *   Equivalent to the non-standard fs_dupfd() function except that it
- *   accepts a struct file instance instead of a file descriptor and does
- *   not set the errno variable.
+ *   accepts a struct file instance instead of a file descriptor.
  *
  * Returned Value:
  *   Zero (OK) is returned on success; a negated errno value is returned on
@@ -733,28 +732,42 @@ void files_releaselist(FAR struct filelist *list);
 int file_dup(FAR struct file *filep, int minfd);
 
 /****************************************************************************
- * Name: fs_dupfd OR dup
+ * Name: fs_dupfd
  *
  * Description:
  *   Clone a file descriptor 'fd' to an arbitrary descriptor number (any
- *   value greater than or equal to 'minfd'). If socket descriptors are
- *   implemented, then this is called by dup() for the case of file
- *   descriptors.  If socket descriptors are not implemented, then this
- *   function IS dup().
+ *   value greater than or equal to 'minfd').
  *
  *   This alternative naming is used when dup could operate on both file and
  *   socket descriptors to avoid drawing unused socket support into the link.
  *
  * Returned Value:
- *   fs_dupfd is sometimes an OS internal function and sometimes is a direct
- *   substitute for dup().  So it must return an errno value as though it
- *   were dup().
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
  *
  ****************************************************************************/
 
 int fs_dupfd(int fd, int minfd);
 
 /****************************************************************************
+ * Name: nx_dup
+ *
+ * Description:
+ *   nx_dup() is similar to the standard 'dup' interface except that is
+ *   not a cancellation point and it does not modify the errno variable.
+ *
+ *   nx_dup() is an internal NuttX interface and should not be called from
+ *   applications.
+ *
+ * Returned Value:
+ *   The new file descriptor is returned on success; a negated errno value is
+ *   returned on any failure.
+ *
+ ****************************************************************************/
+
+int nx_dup(int fd);
+
+/****************************************************************************
  * Name: file_dup2
  *
  * Description:
@@ -762,8 +775,7 @@ int fs_dupfd(int fd, int minfd);
  *   dup2.
  *
  *   Equivalent to the non-standard fs_dupfd2() function except that it
- *   accepts struct file instances instead of file descriptors and it does
- *   not set the errno variable.
+ *   accepts struct file instances instead of file descriptors.
  *
  * Returned Value:
  *   Zero (OK) is returned on success; a negated errno value is return on
@@ -774,29 +786,39 @@ int fs_dupfd(int fd, int minfd);
 int file_dup2(FAR struct file *filep1, FAR struct file *filep2);
 
 /****************************************************************************
- * Name: fs_dupfd2 OR dup2
+ * Name: fs_dupfd2
  *
  * Description:
- *   Clone a file descriptor to a specific descriptor number. If socket
- *   descriptors are implemented, then this is called by dup2() for the
- *   case of file descriptors.  If socket descriptors are not implemented,
- *   then this function IS dup2().
+ *   Clone a file descriptor to a specific descriptor number.
  *
  *   This alternative naming is used when dup2 could operate on both file and
  *   socket descriptors to avoid drawing unused socket support into the link.
  *
  * Returned Value:
- *   fs_dupfd2 is sometimes an OS internal function and sometimes is a direct
- *   substitute for dup2().  So it must return an errno value as though it
- *   were dup2().
+ *   Zero (OK) is returned on success; a negated errno value is return on
+ *   any failure.
  *
  ****************************************************************************/
 
-#ifdef CONFIG_NET
 int fs_dupfd2(int fd1, int fd2);
-#else
-#  define fs_dupfd2(fd1, fd2) dup2(fd1, fd2)
-#endif
+
+/****************************************************************************
+ * Name: nx_dup2
+ *
+ * Description:
+ *   nx_dup2() is similar to the standard 'dup2' interface except that is
+ *   not a cancellation point and it does not modify the errno variable.
+ *
+ *   nx_dup2() 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 return on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+int nx_dup2(int fd1, int fd2);
 
 /****************************************************************************
  * Name: file_open
diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h
index bf24060..871236f 100644
--- a/include/nuttx/net/net.h
+++ b/include/nuttx/net/net.h
@@ -1341,14 +1341,11 @@ int net_poll(int sockfd, struct pollfd *fds, bool setup);
  * Name: psock_dup
  *
  * Description:
- *   Clone a socket descriptor to an arbitrary descriptor number.  If file
- *   descriptors are implemented, then this is called by dup() for the case
- *   of socket file descriptors.  If file descriptors are not implemented,
- *   then this function IS dup().
+ *   Clone a socket descriptor to an arbitrary descriptor number.
  *
  * Returned Value:
- *   On success, returns the number of characters sent.  On any error,
- *   a negated errno value is returned:.
+ *   On success, returns the number of new socket.  On any error,
+ *   a negated errno value is returned.
  *
  ****************************************************************************/
 
@@ -1358,14 +1355,11 @@ int psock_dup(FAR struct socket *psock, int minsd);
  * Name: net_dup
  *
  * Description:
- *   Clone a socket descriptor to an arbitrary descriptor number.  If file
- *   descriptors are implemented, then this is called by dup() for the case
- *   of socket file descriptors.  If file descriptors are not implemented,
- *   then this function IS dup().
+ *   Clone a socket descriptor to an arbitrary descriptor number.
  *
  * Returned Value:
- *   On success, returns the number of characters sent.  On any error,
- *   a negated errno value is returned:.
+ *   On success, returns the number of new socket.  On any error,
+ *   a negated errno value is returned.
  *
  ****************************************************************************/
 
@@ -1385,14 +1379,11 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2);
  * Name: net_dup2
  *
  * Description:
- *   Clone a socket descriptor to an arbitrary descriptor number.  If file
- *   descriptors are implemented, then this is called by dup2() for the case
- *   of socket file descriptors.  If file descriptors are not implemented,
- *   then this function IS dup2().
+ *   Clone a socket descriptor to an arbitrary descriptor number.
  *
  * Returned Value:
- *   On success, returns the number of characters sent.  On any error,
- *   a negated errno value is returned:.
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
  *
  ****************************************************************************/
 
diff --git a/net/socket/net_dup.c b/net/socket/net_dup.c
index 09fcbca..e8a3880 100644
--- a/net/socket/net_dup.c
+++ b/net/socket/net_dup.c
@@ -54,14 +54,11 @@
  * Name: psock_dup
  *
  * Description:
- *   Clone a socket descriptor to an arbitrary descriptor number.  If file
- *   descriptors are implemented, then this is called by dup() for the case
- *   of socket file descriptors.  If file descriptors are not implemented,
- *   then this function IS dup().
+ *   Clone a socket descriptor to an arbitrary descriptor number.
  *
  * Returned Value:
- *   On success, returns the number of characters sent.  On any error,
- *   a negated errno value is returned:.
+ *   On success, returns the number of new socket.  On any error,
+ *   a negated errno value is returned.
  *
  ****************************************************************************/
 
@@ -138,14 +135,11 @@ errout:
  * Name: net_dup
  *
  * Description:
- *   Clone a socket descriptor to an arbitrary descriptor number.  If file
- *   descriptors are implemented, then this is called by dup() for the case
- *   of socket file descriptors.  If file descriptors are not implemented,
- *   then this function IS dup().
+ *   Clone a socket descriptor to an arbitrary descriptor number.
  *
  * Returned Value:
- *   On success, returns the number of characters sent.  On any error,
- *   a negated errno value is returned:.
+ *   On success, returns the number of new socket.  On any error,
+ *   a negated errno value is returned.
  *
  ****************************************************************************/
 
diff --git a/net/socket/net_dup2.c b/net/socket/net_dup2.c
index 2754772..1e9f4d2 100644
--- a/net/socket/net_dup2.c
+++ b/net/socket/net_dup2.c
@@ -106,7 +106,8 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2)
    * for this address family type.
    */
 
-  DEBUGASSERT(psock2->s_sockif != NULL && psock2->s_sockif->si_addref != NULL);
+  DEBUGASSERT(psock2->s_sockif != NULL &&
+              psock2->s_sockif->si_addref != NULL);
   psock2->s_sockif->si_addref(psock2);
 
 #ifdef NET_TCP_HAVE_STACK
@@ -156,14 +157,11 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2)
  * Name: net_dup2
  *
  * Description:
- *   Clone a socket descriptor to an arbitrary descriptor number.  If file
- *   descriptors are implemented, then this is called by dup2() for the case
- *   of socket file descriptors.  If file descriptors are not implemented,
- *   then this function IS dup2().
+ *   Clone a socket descriptor to an arbitrary descriptor number.
  *
  * Returned Value:
- *   On success, returns the number of characters sent.  On any error,
- *   a negated errno value is returned:.
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
  *
  ****************************************************************************/
 


[incubator-nuttx] 03/05: sched: add nx_wait, nx_waitid and nx_waitpid

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit de2a9d8a771ac4434d94a654e2b60c4fd0de19a1
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon May 4 00:54:56 2020 +0800

    sched: add nx_wait, nx_waitid and nx_waitpid
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 include/nuttx/sched.h       |  10 ++
 sched/sched/sched_wait.c    |  11 +-
 sched/sched/sched_waitid.c  | 198 ++++++++++++-----------
 sched/sched/sched_waitpid.c | 374 ++++++++++++++++++++++----------------------
 4 files changed, 313 insertions(+), 280 deletions(-)

diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h
index 8d07601..cc63e7c 100644
--- a/include/nuttx/sched.h
+++ b/include/nuttx/sched.h
@@ -1260,6 +1260,16 @@ int nxsched_setaffinity(pid_t pid, size_t cpusetsize,
 
 int sched_get_stackinfo(pid_t pid, FAR struct stackinfo_s *stackinfo);
 
+/********************************************************************************
+ * Name: nx_wait/nx_waitid/nx_waitpid
+ ********************************************************************************/
+
+#ifdef CONFIG_SCHED_WAITPID
+pid_t nx_wait(FAR int *stat_loc);
+int   nx_waitid(int idtype, id_t id, FAR siginfo_t *info, int options);
+pid_t nx_waitpid(pid_t pid, FAR int *stat_loc, int options);
+#endif
+
 #undef EXTERN
 #if defined(__cplusplus)
 }
diff --git a/sched/sched/sched_wait.c b/sched/sched/sched_wait.c
index 7dd9070..42e84f3 100644
--- a/sched/sched/sched_wait.c
+++ b/sched/sched/sched_wait.c
@@ -54,6 +54,15 @@
  ****************************************************************************/
 
 /****************************************************************************
+ * Name: nx_wait
+ ****************************************************************************/
+
+pid_t nx_wait(FAR int *stat_loc)
+{
+  return nx_waitpid((pid_t)-1, stat_loc, 0);
+}
+
+/****************************************************************************
  * Name: wait
  *
  * Description:
@@ -85,7 +94,7 @@ pid_t wait(FAR int *stat_loc)
    * trivial case.
    */
 
-  return waitpid((pid_t) - 1, stat_loc, 0);
+  return waitpid((pid_t)-1, stat_loc, 0);
 }
 
 #endif /* CONFIG_SCHED_WAITPID && CONFIG_SCHED_HAVE_PARENT */
diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c
index a3431de..edabfee 100644
--- a/sched/sched/sched_waitid.c
+++ b/sched/sched/sched_waitid.c
@@ -93,69 +93,10 @@ static void exited_child(FAR struct tcb_s *rtcb,
  ****************************************************************************/
 
 /****************************************************************************
- * Name: waitid
- *
- * Description:
- *   The waitid() function suspends the calling thread until one child of
- *   the process containing the calling thread changes state. It records the
- *   current state of a child in the structure pointed to by 'info'. If a
- *   child process changed state prior to the call to waitid(), waitid()
- *   returns immediately. If more than one thread is suspended in wait() or
- *   waitpid() waiting termination of the same process, exactly one thread
- *   will return the process status at the time of the target process
- *   termination
- *
- *   The idtype and id arguments are used to specify which children waitid()
- *   will wait for.
- *
- *     If idtype is P_PID, waitid() will wait for the child with a process
- *     ID equal to (pid_t)id.
- *
- *     If idtype is P_PGID, waitid() will wait for any child with a process
- *     group ID equal to (pid_t)id.
- *
- *     If idtype is P_ALL, waitid() will wait for any children and id is
- *     ignored.
- *
- *   The options argument is used to specify which state changes waitid()
- *   will will wait for. It is formed by OR-ing together one or more of the
- *   following flags:
- *
- *     WEXITED - Wait for processes that have exited.
- *     WSTOPPED - Status will be returned for any child that has stopped
- *       upon receipt of a signal.
- *     WCONTINUED - Status will be returned for any child that was stopped
- *       and has been continued.
- *     WNOHANG - Return immediately if there are no children to wait for.
- *     WNOWAIT - Keep the process whose status is returned in 'info' in a
- *       waitable state. This will not affect the state of the process; the
- *       process may be waited for again after this call completes.
- *
- *   The 'info' argument must point to a siginfo_t structure. If waitid()
- *   returns because a child process was found that satisfied the conditions
- *   indicated by the arguments idtype and options, then the structure
- *   pointed to by 'info' will be filled in by the system with the status of
- *   the process. The si_signo member will always be equal to SIGCHLD.
- *
- * Input Parameters:
- *   See description.
- *
- * Returned Value:
- *   If waitid() returns due to the change of state of one of its children,
- *   0 is returned. Otherwise, -1 is returned and errno is set to indicate
- *   the error.
- *
- *   The waitid() function will fail if:
- *
- *     ECHILD - The calling process has no existing unwaited-for child
- *       processes.
- *     EINTR - The waitid() function was interrupted by a signal.
- *     EINVAL - An invalid value was specified for options, or idtype and id
- *       specify an invalid set of processes.
- *
+ * Name: nx_waitid
  ****************************************************************************/
 
-int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
+int nx_waitid(int idtype, id_t id, FAR siginfo_t *info, int options)
 {
   FAR struct tcb_s *rtcb = this_task();
   FAR struct tcb_s *ctcb;
@@ -164,8 +105,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
   bool retains;
 #endif
   sigset_t set;
-  int errcode;
-  int ret;
+  int ret = OK;
 
   /* MISSING LOGIC:   If WNOHANG is provided in the options, then this
    * function should returned immediately.  However, there is no mechanism
@@ -179,8 +119,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
 
   if (idtype != P_PID && idtype != P_ALL)
     {
-      set_errno(ENOSYS);
-      return ERROR;
+      return -ENOSYS;
     }
 
   /* None of the options are supported except for WEXITED (which must be
@@ -190,15 +129,10 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
 
   if (options != WEXITED)
     {
-      set_errno(ENOSYS);
-      return ERROR;
+      return -ENOSYS;
     }
 #endif
 
-  /* waitid() is a cancellation point */
-
-  enter_cancellation_point();
-
   /* Create a signal set that contains only SIGCHLD */
 
   sigemptyset(&set);
@@ -221,8 +155,8 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
     {
       /* There are no children */
 
-      errcode = ECHILD;
-      goto errout_with_errno;
+      ret = -ECHILD;
+      goto errout;
     }
   else if (idtype == P_PID)
     {
@@ -238,8 +172,8 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
       if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->pid)
 #endif
         {
-          errcode = ECHILD;
-          goto errout_with_errno;
+          ret = -ECHILD;
+          goto errout;
         }
 
       /* Does this task retain child status? */
@@ -252,8 +186,8 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
             {
               /* This specific pid is not a child */
 
-              errcode = ECHILD;
-              goto errout_with_errno;
+              ret = -ECHILD;
+              goto errout;
             }
         }
     }
@@ -264,8 +198,8 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
     {
       /* There are no children */
 
-      errcode = ECHILD;
-      goto errout_with_errno;
+      ret = -ECHILD;
+      goto errout;
     }
   else if (idtype == P_PID)
     {
@@ -281,8 +215,8 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
       if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->pid)
 #endif
         {
-          errcode = ECHILD;
-          goto errout_with_errno;
+          ret = -ECHILD;
+          goto errout;
         }
     }
 #endif
@@ -353,8 +287,8 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
                * to reported ECHILD than bogus status.
                */
 
-              errcode = ECHILD;
-              goto errout_with_errno;
+              ret = -ECHILD;
+              goto errout;
             }
         }
 #else
@@ -372,8 +306,8 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
            * Let's return ECHILD.. that is at least informative.
            */
 
-          errcode = ECHILD;
-          goto errout_with_errno;
+          ret = -ECHILD;
+          goto errout;
         }
 #endif
 
@@ -382,8 +316,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
       ret = nxsig_waitinfo(&set, info);
       if (ret < 0)
         {
-          errcode = -ret;
-          goto errout_with_errno;
+          goto errout;
         }
 
       /* Make there this was SIGCHLD */
@@ -417,22 +350,97 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
 
           else /* if (idtype == P_PGID) */
             {
-              errcode = ENOSYS;
-              goto errout_with_errno;
+              ret = -ENOSYS;
+              goto errout;
             }
         }
     }
 
-  leave_cancellation_point();
+errout:
   sched_unlock();
-  return OK;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: waitid
+ *
+ * Description:
+ *   The waitid() function suspends the calling thread until one child of
+ *   the process containing the calling thread changes state. It records the
+ *   current state of a child in the structure pointed to by 'info'. If a
+ *   child process changed state prior to the call to waitid(), waitid()
+ *   returns immediately. If more than one thread is suspended in wait() or
+ *   waitpid() waiting termination of the same process, exactly one thread
+ *   will return the process status at the time of the target process
+ *   termination
+ *
+ *   The idtype and id arguments are used to specify which children waitid()
+ *   will wait for.
+ *
+ *     If idtype is P_PID, waitid() will wait for the child with a process
+ *     ID equal to (pid_t)id.
+ *
+ *     If idtype is P_PGID, waitid() will wait for any child with a process
+ *     group ID equal to (pid_t)id.
+ *
+ *     If idtype is P_ALL, waitid() will wait for any children and id is
+ *     ignored.
+ *
+ *   The options argument is used to specify which state changes waitid()
+ *   will will wait for. It is formed by OR-ing together one or more of the
+ *   following flags:
+ *
+ *     WEXITED - Wait for processes that have exited.
+ *     WSTOPPED - Status will be returned for any child that has stopped
+ *       upon receipt of a signal.
+ *     WCONTINUED - Status will be returned for any child that was stopped
+ *       and has been continued.
+ *     WNOHANG - Return immediately if there are no children to wait for.
+ *     WNOWAIT - Keep the process whose status is returned in 'info' in a
+ *       waitable state. This will not affect the state of the process; the
+ *       process may be waited for again after this call completes.
+ *
+ *   The 'info' argument must point to a siginfo_t structure. If waitid()
+ *   returns because a child process was found that satisfied the conditions
+ *   indicated by the arguments idtype and options, then the structure
+ *   pointed to by 'info' will be filled in by the system with the status of
+ *   the process. The si_signo member will always be equal to SIGCHLD.
+ *
+ * Input Parameters:
+ *   See description.
+ *
+ * Returned Value:
+ *   If waitid() returns due to the change of state of one of its children,
+ *   0 is returned. Otherwise, -1 is returned and errno is set to indicate
+ *   the error.
+ *
+ *   The waitid() function will fail if:
+ *
+ *     ECHILD - The calling process has no existing unwaited-for child
+ *       processes.
+ *     EINTR - The waitid() function was interrupted by a signal.
+ *     EINVAL - An invalid value was specified for options, or idtype and id
+ *       specify an invalid set of processes.
+ *
+ ****************************************************************************/
 
-errout_with_errno:
-  set_errno(errcode);
+int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
+{
+  int ret;
+
+  /* waitid() is a cancellation point */
+
+  enter_cancellation_point();
+
+  ret = nx_waitid(idtype, id, info, options);
+  if (ret < 0)
+    {
+      set_errno(-ret);
+      ret = ERROR;
+    }
 
   leave_cancellation_point();
-  sched_unlock();
-  return ERROR;
+  return ret;
 }
 
 #endif /* CONFIG_SCHED_WAITPID && CONFIG_SCHED_HAVE_PARENT */
diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c
index 8ff5244..45527be 100644
--- a/sched/sched/sched_waitpid.c
+++ b/sched/sched/sched_waitpid.c
@@ -59,144 +59,19 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Name: waitpid
- *
- * Description:
- *   The waitpid() functions will obtain status information pertaining to one
- *   of the caller's child processes. The waitpid() function will suspend
- *   execution of the calling thread until status information for one of the
- *   terminated child processes of the calling process is available, or until
- *   delivery of a signal whose action is either to execute a signal-catching
- *   function or to terminate the process. If more than one thread is
- *   suspended in waitpid() awaiting termination of the same process, exactly
- *   one thread will return the process status at the time of the target
- *   process termination. If status information is available prior to the
- *   call to waitpid(), return will be immediate.
- *
- *   The pid argument specifies a set of child processes for which status is
- *   requested. The waitpid() function will only return the status of a child
- *   process from this set:
- *
- *   - If pid is equal to (pid_t)-1, status is requested for any child
- *     process. In this respect, waitpid() is then equivalent to wait().
- *   - If pid is greater than 0, it specifies the process ID of a single
- *     child process for which status is requested.
- *   - If pid is 0, status is requested for any child process whose process
- *     group ID is equal to that of the calling process.
- *   - If pid is less than (pid_t)-1, status is requested for any child
- *     process whose process group ID is equal to the absolute value of pid.
- *
- *   The options argument is constructed from the bitwise-inclusive OR of
- *   zero or more of the following flags, defined in the <sys/wait.h> header:
- *
- *   WCONTINUED - The waitpid() function will report the status of any
- *     continued child process specified by pid whose status has not been
- *     reported since it continued from a job control stop.
- *   WNOHANG - The waitpid() function will not suspend execution of the
- *    calling thread if status is not immediately available for one of the
- *    child processes specified by pid.
- *   WUNTRACED - The status of any child processes specified by pid that are
- *    stopped, and whose status has not yet been reported since they stopped,
- *    will also be reported to the requesting process.
- *
- *   If the calling process has SA_NOCLDWAIT set or has SIGCHLD set to
- *   SIG_IGN, and the process has no unwaited-for children that were
- *   transformed into zombie processes, the calling thread will block until
- *   all of the children of the process containing the calling thread
- *   terminate, and waitpid() will fail and set errno to ECHILD.
- *
- *   If waitpid() returns because the status of a child process is available,
- *   these functions will return a value equal to the process ID of the child
- *   process. In this case, if the value of the argument stat_loc is not a
- *   null pointer, information will be stored in the location pointed to by
- *   stat_loc. The value stored at the location pointed to by stat_loc will
- *   be 0 if and only if the status returned is from a terminated child
- *   process that terminated by one of the following means:
- *
- *   1. The process returned 0 from main().
- *   2. The process called _exit() or exit() with a status argument of 0.
- *   3. The process was terminated because the last thread in the process
- *      terminated.
- *
- *   Regardless of its value, this information may be interpreted using the
- *   following macros, which are defined in <sys/wait.h> and evaluate to
- *   integral expressions; the stat_val argument is the integer value pointed
- *   to by stat_loc.
- *
- *   WIFEXITED(stat_val) - Evaluates to a non-zero value if status was
- *     returned for a child process that terminated normally.
- *   WEXITSTATUS(stat_val) - If the value of WIFEXITED(stat_val) is non-zero,
- *     this macro evaluates to the low-order 8 bits of the status argument
- *     that the child process passed to _exit() or exit(), or the value the
- *     child process returned from main().
- *   WIFSIGNALED(stat_val) - Evaluates to a non-zero value if status was
- *     returned for a child process that terminated due to the receipt of a
- *     signal that was not caught (see <signal.h>).
- *   WTERMSIG(stat_val)  - If the value of WIFSIGNALED(stat_val) is non-zero,
- *     this macro evaluates to the number of the signal that caused the
- *     termination of the child process.
- *   WIFSTOPPED(stat_val) - Evaluates to a non-zero value if status was
- *     returned for a child process that is currently stopped.
- *   WSTOPSIG(stat_val) - If the value of WIFSTOPPED(stat_val) is non-zero,
- *     this macro evaluates to the number of the signal that caused the child
- *     process to stop.
- *   WIFCONTINUED(stat_val) - Evaluates to a non-zero value if status was
- *    returned for a child process that has continued from a job control
- *    stop.
- *
- * Input Parameters:
- *   pid - The task ID of the thread to waid for
- *   stat_loc - The location to return the exit status
- *   options - ignored
- *
- * Returned Value:
- *   If waitpid() returns because the status of a child process is available,
- *   it will return a value equal to the process ID of the child process for
- *   which status is reported.
- *
- *   If waitpid() returns due to the delivery of a signal to the calling
- *   process, -1 will be returned and errno set to EINTR.
- *
- *   If waitpid() was invoked with WNOHANG set in options, it has at least
- *   one child process specified by pid for which status is not available,
- *   and status is not available for any process specified by pid, 0 is
- *   returned.
- *
- *   Otherwise, (pid_t)-1 will be returned, and errno set to indicate the
- *   error:
- *
- *   ECHILD - The process specified by pid does not exist or is not a child
- *            of the calling process, or the process group specified by pid
- *            does not exist does not have any member process that is a child
- *            of the calling process.
- *   EINTR - The function was interrupted by a signal. The value of the
- *           location pointed to by stat_loc is undefined.
- *   EINVAL - The options argument is not valid.
- *
- * Assumptions:
- *
- * Compatibility
- *   If there is no SIGCHLD signal supported (CONFIG_SCHED_HAVE_PARENT not
- *   defined), then waitpid() is still available, but does not obey the
- *   restriction that the pid be a child of the caller.
- *
+ * Name: nx_waitpid
  ****************************************************************************/
 
 #ifndef CONFIG_SCHED_HAVE_PARENT
-pid_t waitpid(pid_t pid, int *stat_loc, int options)
+pid_t nx_waitpid(pid_t pid, int *stat_loc, int options)
 {
   FAR struct tcb_s *ctcb;
   FAR struct task_group_s *group;
   bool mystat = false;
-  int errcode;
   int ret;
 
   DEBUGASSERT(stat_loc);
 
-  /* waitpid() is a cancellation point */
-
-  enter_cancellation_point();
-
   /* Disable pre-emption so that nothing changes in the following tests */
 
   sched_lock();
@@ -206,8 +81,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
   ctcb = sched_gettcb(pid);
   if (ctcb == NULL)
     {
-      errcode = ECHILD;
-      goto errout_with_errno;
+      ret = -ECHILD;
+      goto errout;
     }
 
   /* Then the task group corresponding to this PID */
@@ -249,50 +124,46 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
       /* Don't wait if status is not available */
 
       ret = nxsem_trywait(&group->tg_exitsem);
-      group_delwaiter(group);
-
-      if (ret < 0)
-        {
-          pid = 0;
-        }
     }
   else
     {
       /* Wait if necessary for status to become available */
 
       ret = nxsem_wait(&group->tg_exitsem);
-      group_delwaiter(group);
+    }
 
-      if (ret < 0)
-        {
-          /* Unlock pre-emption and return the ERROR (nxsem_wait has already
-           * set the errno).  Handle the awkward case of whether or not we
-           * need to nullify the stat_loc value.
-           */
+  group_delwaiter(group);
 
-          if (mystat)
-            {
-              group->tg_statloc   = NULL;
-              group->tg_waitflags = 0;
-            }
+  if (ret < 0)
+    {
+      /* Handle the awkward case of whether or not we
+       * need to nullify the stat_loc value.
+       */
+
+      if (mystat)
+        {
+          group->tg_statloc   = NULL;
+          group->tg_waitflags = 0;
+        }
 
-          errcode = -ret;
-          goto errout_with_errno;
+      if ((options & WNOHANG) != 0)
+        {
+          pid = 0;
+        }
+      else
+        {
+          goto errout;
         }
     }
 
   /* On success, return the PID */
 
-  leave_cancellation_point();
   sched_unlock();
   return pid;
 
-errout_with_errno:
-  set_errno(errcode);
-
-  leave_cancellation_point();
+errout:
   sched_unlock();
-  return ERROR;
+  return ret;
 }
 
 /****************************************************************************
@@ -309,7 +180,7 @@ errout_with_errno:
  ****************************************************************************/
 
 #else
-pid_t waitpid(pid_t pid, int *stat_loc, int options)
+pid_t nx_waitpid(pid_t pid, int *stat_loc, int options)
 {
   FAR struct tcb_s *rtcb = this_task();
   FAR struct tcb_s *ctcb;
@@ -319,15 +190,10 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
 #endif
   FAR struct siginfo info;
   sigset_t set;
-  int errcode;
   int ret;
 
   DEBUGASSERT(stat_loc);
 
-  /* waitpid() is a cancellation point */
-
-  enter_cancellation_point();
-
   /* Create a signal set that contains only SIGCHLD */
 
   sigemptyset(&set);
@@ -348,8 +214,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
 
   if (rtcb->group->tg_children == NULL && retains)
     {
-      errcode = ECHILD;
-      goto errout_with_errno;
+      ret = -ECHILD;
+      goto errout;
     }
   else if (pid != (pid_t)-1)
     {
@@ -368,8 +234,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
           if (ctcb->group->tg_ppid != rtcb->pid)
 #endif
             {
-              errcode = ECHILD;
-              goto errout_with_errno;
+              ret = -ECHILD;
+              goto errout;
             }
         }
 
@@ -383,8 +249,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
 
           if (group_findchild(rtcb->group, pid) == NULL)
             {
-              errcode = ECHILD;
-              goto errout_with_errno;
+              ret = -ECHILD;
+              goto errout;
             }
         }
     }
@@ -395,8 +261,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
     {
       /* There are no children */
 
-      errcode = ECHILD;
-      goto errout_with_errno;
+      ret = -ECHILD;
+      goto errout;
     }
   else if (pid != (pid_t)-1)
     {
@@ -412,8 +278,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
       if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->pid)
 #endif
         {
-          errcode = ECHILD;
-          goto errout_with_errno;
+          ret = -ECHILD;
+          goto errout;
         }
     }
 
@@ -497,8 +363,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
                * to reported ECHILD than bogus status.
                */
 
-              errcode = ECHILD;
-              goto errout_with_errno;
+              ret = -ECHILD;
+              goto errout;
             }
         }
 
@@ -518,8 +384,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
            * Let's return ECHILD.. that is at least informative.
            */
 
-          errcode = ECHILD;
-          goto errout_with_errno;
+          ret = -ECHILD;
+          goto errout;
         }
 
 #endif /* CONFIG_SCHED_CHILD_STATUS */
@@ -529,8 +395,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
       ret = nxsig_waitinfo(&set, &info);
       if (ret < 0)
         {
-          errcode = -ret;
-          goto errout_with_errno;
+          goto errout;
         }
 
       /* Was this the death of the thread we were waiting for? In the of
@@ -567,17 +432,158 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
         }
     }
 
-  leave_cancellation_point();
   sched_unlock();
-  return (int)pid;
-
-errout_with_errno:
-  set_errno(errcode);
+  return pid;
 
-  leave_cancellation_point();
+errout:
   sched_unlock();
-  return ERROR;
+  return ret;
 }
 #endif /* CONFIG_SCHED_HAVE_PARENT */
 
+/****************************************************************************
+ * Name: waitpid
+ *
+ * Description:
+ *   The waitpid() functions will obtain status information pertaining to one
+ *   of the caller's child processes. The waitpid() function will suspend
+ *   execution of the calling thread until status information for one of the
+ *   terminated child processes of the calling process is available, or until
+ *   delivery of a signal whose action is either to execute a signal-catching
+ *   function or to terminate the process. If more than one thread is
+ *   suspended in waitpid() awaiting termination of the same process, exactly
+ *   one thread will return the process status at the time of the target
+ *   process termination. If status information is available prior to the
+ *   call to waitpid(), return will be immediate.
+ *
+ *   The pid argument specifies a set of child processes for which status is
+ *   requested. The waitpid() function will only return the status of a child
+ *   process from this set:
+ *
+ *   - If pid is equal to (pid_t)-1, status is requested for any child
+ *     process. In this respect, waitpid() is then equivalent to wait().
+ *   - If pid is greater than 0, it specifies the process ID of a single
+ *     child process for which status is requested.
+ *   - If pid is 0, status is requested for any child process whose process
+ *     group ID is equal to that of the calling process.
+ *   - If pid is less than (pid_t)-1, status is requested for any child
+ *     process whose process group ID is equal to the absolute value of pid.
+ *
+ *   The options argument is constructed from the bitwise-inclusive OR of
+ *   zero or more of the following flags, defined in the <sys/wait.h> header:
+ *
+ *   WCONTINUED - The waitpid() function will report the status of any
+ *     continued child process specified by pid whose status has not been
+ *     reported since it continued from a job control stop.
+ *   WNOHANG - The waitpid() function will not suspend execution of the
+ *    calling thread if status is not immediately available for one of the
+ *    child processes specified by pid.
+ *   WUNTRACED - The status of any child processes specified by pid that are
+ *    stopped, and whose status has not yet been reported since they stopped,
+ *    will also be reported to the requesting process.
+ *
+ *   If the calling process has SA_NOCLDWAIT set or has SIGCHLD set to
+ *   SIG_IGN, and the process has no unwaited-for children that were
+ *   transformed into zombie processes, the calling thread will block until
+ *   all of the children of the process containing the calling thread
+ *   terminate, and waitpid() will fail and set errno to ECHILD.
+ *
+ *   If waitpid() returns because the status of a child process is available,
+ *   these functions will return a value equal to the process ID of the child
+ *   process. In this case, if the value of the argument stat_loc is not a
+ *   null pointer, information will be stored in the location pointed to by
+ *   stat_loc. The value stored at the location pointed to by stat_loc will
+ *   be 0 if and only if the status returned is from a terminated child
+ *   process that terminated by one of the following means:
+ *
+ *   1. The process returned 0 from main().
+ *   2. The process called _exit() or exit() with a status argument of 0.
+ *   3. The process was terminated because the last thread in the process
+ *      terminated.
+ *
+ *   Regardless of its value, this information may be interpreted using the
+ *   following macros, which are defined in <sys/wait.h> and evaluate to
+ *   integral expressions; the stat_val argument is the integer value pointed
+ *   to by stat_loc.
+ *
+ *   WIFEXITED(stat_val) - Evaluates to a non-zero value if status was
+ *     returned for a child process that terminated normally.
+ *   WEXITSTATUS(stat_val) - If the value of WIFEXITED(stat_val) is non-zero,
+ *     this macro evaluates to the low-order 8 bits of the status argument
+ *     that the child process passed to _exit() or exit(), or the value the
+ *     child process returned from main().
+ *   WIFSIGNALED(stat_val) - Evaluates to a non-zero value if status was
+ *     returned for a child process that terminated due to the receipt of a
+ *     signal that was not caught (see <signal.h>).
+ *   WTERMSIG(stat_val)  - If the value of WIFSIGNALED(stat_val) is non-zero,
+ *     this macro evaluates to the number of the signal that caused the
+ *     termination of the child process.
+ *   WIFSTOPPED(stat_val) - Evaluates to a non-zero value if status was
+ *     returned for a child process that is currently stopped.
+ *   WSTOPSIG(stat_val) - If the value of WIFSTOPPED(stat_val) is non-zero,
+ *     this macro evaluates to the number of the signal that caused the child
+ *     process to stop.
+ *   WIFCONTINUED(stat_val) - Evaluates to a non-zero value if status was
+ *    returned for a child process that has continued from a job control
+ *    stop.
+ *
+ * Input Parameters:
+ *   pid - The task ID of the thread to waid for
+ *   stat_loc - The location to return the exit status
+ *   options - ignored
+ *
+ * Returned Value:
+ *   If waitpid() returns because the status of a child process is available,
+ *   it will return a value equal to the process ID of the child process for
+ *   which status is reported.
+ *
+ *   If waitpid() returns due to the delivery of a signal to the calling
+ *   process, -1 will be returned and errno set to EINTR.
+ *
+ *   If waitpid() was invoked with WNOHANG set in options, it has at least
+ *   one child process specified by pid for which status is not available,
+ *   and status is not available for any process specified by pid, 0 is
+ *   returned.
+ *
+ *   Otherwise, (pid_t)-1 will be returned, and errno set to indicate the
+ *   error:
+ *
+ *   ECHILD - The process specified by pid does not exist or is not a child
+ *            of the calling process, or the process group specified by pid
+ *            does not exist does not have any member process that is a child
+ *            of the calling process.
+ *   EINTR - The function was interrupted by a signal. The value of the
+ *           location pointed to by stat_loc is undefined.
+ *   EINVAL - The options argument is not valid.
+ *
+ * Assumptions:
+ *
+ * Compatibility
+ *   If there is no SIGCHLD signal supported (CONFIG_SCHED_HAVE_PARENT not
+ *   defined), then waitpid() is still available, but does not obey the
+ *   restriction that the pid be a child of the caller.
+ *
+ ****************************************************************************/
+
+pid_t waitpid(pid_t pid, int *stat_loc, int options)
+{
+  pid_t ret;
+
+  /* waitpid() is a cancellation point */
+
+  enter_cancellation_point();
+
+  /* Let nx_waitpid() do the work. */
+
+  ret = nx_waitpid(pid, stat_loc, options);
+  if (ret < 0)
+    {
+      set_errno(-ret);
+      ret = ERROR;
+    }
+
+  leave_cancellation_point();
+  return ret;
+}
+
 #endif /* CONFIG_SCHED_WAITPID */


[incubator-nuttx] 04/05: mqueue: Add nxmq_open/nxmq_close/nxmq_unlink function

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 929292f57b14bbf5544ce2d2b5f4cd603ddc2a1a
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon May 4 04:31:05 2020 +0800

    mqueue: Add nxmq_open/nxmq_close/nxmq_unlink function
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 fs/mqueue/mq_close.c   |  66 ++++++++++++++++++-------
 fs/mqueue/mq_open.c    | 128 ++++++++++++++++++++++++++++++++++---------------
 fs/mqueue/mq_unlink.c  |  66 ++++++++++++++++++-------
 include/nuttx/mqueue.h |  87 +++++++++++++++++++++++++++++++++
 4 files changed, 273 insertions(+), 74 deletions(-)

diff --git a/fs/mqueue/mq_close.c b/fs/mqueue/mq_close.c
index 63cc545..38ad44b 100644
--- a/fs/mqueue/mq_close.c
+++ b/fs/mqueue/mq_close.c
@@ -88,7 +88,7 @@ int nxmq_close_group(mqd_t mqdes, FAR struct task_group_s *group)
           inode = msgq->inode;
           DEBUGASSERT(inode->u.i_mqueue == msgq);
 
-          /* Decrement the reference count on the inode, possibly freeing it */
+          /* Decrement the reference count on the inode, possibly free it */
 
           mq_inode_release(inode);
         }
@@ -100,6 +100,51 @@ int nxmq_close_group(mqd_t mqdes, FAR struct task_group_s *group)
 }
 
 /****************************************************************************
+ * Name: nxmq_close
+ *
+ * Description:
+ *   This is an internal OS interface.  It is functionally equivalent to
+ *   mq_close() except that:
+ *
+ *   - It is not a cancellation point, and
+ *   - It does not modify the errno value.
+ *
+ *  See comments with mq_close() for a more complete description of the
+ *  behavior of this function
+ *
+ * Input Parameters:
+ *   mqdes - Message queue descriptor.
+ *
+ * Returned Value:
+ *   This is an internal OS interface and should not be used by applications.
+ *   It follows the NuttX internal error return policy:  Zero (OK) is
+ *   returned on success. A negated errno value is returned on failure.
+ *
+ ****************************************************************************/
+
+int nxmq_close(mqd_t mqdes)
+{
+  FAR struct tcb_s *rtcb = (FAR struct tcb_s *)sched_self();
+  int ret;
+
+  /* Lock the scheduler to prevent any asynchronous task delete operation
+   * (unlikely).
+   */
+
+  sched_lock();
+
+  rtcb = (FAR struct tcb_s *)sched_self();
+  DEBUGASSERT(mqdes != NULL && rtcb != NULL && rtcb->group != NULL);
+
+  /* Then perform the close operation */
+
+  ret = nxmq_close_group(mqdes, rtcb->group);
+
+  sched_unlock();
+  return ret;
+}
+
+/****************************************************************************
  * Name: mq_close
  *
  * Description:
@@ -129,30 +174,15 @@ int nxmq_close_group(mqd_t mqdes, FAR struct task_group_s *group)
 
 int mq_close(mqd_t mqdes)
 {
-  FAR struct tcb_s *rtcb = (FAR struct tcb_s *)sched_self();
   int ret;
 
-  /* Lock the scheduler to prevent any asynchronous task delete operation
-   * (unlikely).
-   */
-
-  sched_lock();
-
-  rtcb = (FAR struct tcb_s *)sched_self();
-  DEBUGASSERT(mqdes != NULL && rtcb != NULL && rtcb->group != NULL);
-
-  /* Then perform the close operation */
-
-  ret = nxmq_close_group(mqdes, rtcb->group);
-#if 0
-  if (ret < 0)  /* Currently, nxmq_close_group() only returns OK */
+  ret = nxmq_close(mqdes);
+  if (ret < 0)
     {
       set_errno(-ret);
       ret = ERROR;
     }
-#endif
 
-  sched_unlock();
   return ret;
 }
 
diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c
index 5b0263f..3de5f73 100644
--- a/fs/mqueue/mq_open.c
+++ b/fs/mqueue/mq_open.c
@@ -43,14 +43,18 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Name: mq_open
+ * Name: nxmq_open
  *
  * Description:
  *   This function establish a connection between a named message queue and
- *   the calling task.  After a successful call of mq_open(), the task can
- *   reference the message queue using the address returned by the call. The
- *   message queue remains usable until it is closed by a successful call to
- *   mq_close().
+ *   the calling task. This is an internal OS interface.  It is functionally
+ *   equivalent to mq_open() except that:
+ *
+ *   - It is not a cancellation point, and
+ *   - It does not modify the errno value.
+ *
+ *  See comments with mq_open() for a more complete description of the
+ *  behavior of this function
  *
  * Input Parameters:
  *   mq_name - Name of the queue to open
@@ -65,30 +69,27 @@
  *        messages that may be placed in the message queue.
  *
  * Returned Value:
- *   A message queue descriptor or (mqd_t)-1 (ERROR)
- *
- * Assumptions:
+ *   This is an internal OS interface and should not be used by applications.
+ *   It follows the NuttX internal error return policy:  Zero (OK) is
+ *   returned on success, mqdes point to the new message queue descriptor.
+ *   A negated errno value is returned on failure.
  *
  ****************************************************************************/
 
-mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
+int nxmq_open(FAR const char *mq_name, int oflags, mode_t mode,
+              FAR struct mq_attr *attr, FAR mqd_t *mqdes)
 {
   FAR struct inode *inode;
   FAR struct mqueue_inode_s *msgq;
   struct inode_search_s desc;
   char fullpath[MAX_MQUEUE_PATH];
-  va_list ap;
-  struct mq_attr *attr;
-  mqd_t mqdes;
-  mode_t mode;
-  int errcode;
   int ret;
 
   /* Make sure that a non-NULL name is supplied */
 
   if (mq_name == NULL || *mq_name == '\0')
     {
-      errcode = EINVAL;
+      ret = -EINVAL;
       goto errout;
     }
 
@@ -132,7 +133,7 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
 
       if (!INODE_IS_MQUEUE(inode))
         {
-          errcode = ENXIO;
+          ret = -ENXIO;
           goto errout_with_inode;
         }
 
@@ -142,17 +143,17 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
 
       if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
         {
-          errcode = EEXIST;
+          ret = -EEXIST;
           goto errout_with_inode;
         }
 
       /* Create a message queue descriptor for the current thread */
 
       msgq  = inode->u.i_mqueue;
-      mqdes = nxmq_create_des(NULL, msgq, oflags);
-      if (!mqdes)
+      *mqdes = nxmq_create_des(NULL, msgq, oflags);
+      if (!*mqdes)
         {
-          errcode = ENOMEM;
+          ret = -ENOMEM;
           goto errout_with_inode;
         }
     }
@@ -164,25 +165,15 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
         {
           /* The mqueue does not exist and O_CREAT is not set */
 
-          errcode = ENOENT;
+          ret = -ENOENT;
           goto errout_with_lock;
         }
 
-      /* Create the mqueue.  First we have to extract the additional
-       * parameters from the variable argument list.
-       */
-
-      va_start(ap, oflags);
-      mode = va_arg(ap, mode_t);
-      attr = va_arg(ap, FAR struct mq_attr *);
-      va_end(ap);
-
       /* Create an inode in the pseudo-filesystem at this path */
 
       ret = inode_semtake();
       if (ret < 0)
         {
-          errcode = -ret;
           goto errout_with_lock;
         }
 
@@ -191,7 +182,6 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
 
       if (ret < 0)
         {
-          errcode = -ret;
           goto errout_with_lock;
         }
 
@@ -202,16 +192,16 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
       msgq = (FAR struct mqueue_inode_s *)nxmq_alloc_msgq(mode, attr);
       if (!msgq)
         {
-          errcode = ENOSPC;
+          ret = -ENOSPC;
           goto errout_with_inode;
         }
 
       /* Create a message queue descriptor for the TCB */
 
-      mqdes = nxmq_create_des(NULL, msgq, oflags);
-      if (!mqdes)
+      *mqdes = nxmq_create_des(NULL, msgq, oflags);
+      if (!*mqdes)
         {
-          errcode = ENOMEM;
+          ret = -ENOMEM;
           goto errout_with_msgq;
         }
 
@@ -228,7 +218,7 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
 
   RELEASE_SEARCH(&desc);
   sched_unlock();
-  return mqdes;
+  return OK;
 
 errout_with_msgq:
   nxmq_free_msgq(msgq);
@@ -242,6 +232,66 @@ errout_with_lock:
   sched_unlock();
 
 errout:
-  set_errno(errcode);
-  return (mqd_t)ERROR;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: mq_open
+ *
+ * Description:
+ *   This function establish a connection between a named message queue and
+ *   the calling task.  After a successful call of mq_open(), the task can
+ *   reference the message queue using the address returned by the call. The
+ *   message queue remains usable until it is closed by a successful call to
+ *   mq_close().
+ *
+ * Input Parameters:
+ *   mq_name - Name of the queue to open
+ *   oflags - open flags
+ *   Optional parameters.  When the O_CREAT flag is specified, two optional
+ *   parameters are expected:
+ *
+ *     1. mode_t mode (ignored), and
+ *     2. struct mq_attr *attr.  The mq_maxmsg attribute
+ *        is used at the time that the message queue is
+ *        created to determine the maximum number of
+ *        messages that may be placed in the message queue.
+ *
+ * Returned Value:
+ *   A message queue descriptor or (mqd_t)-1 (ERROR)
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
+{
+  FAR struct mq_attr *attr = NULL;
+  mode_t mode = 0;
+  mqd_t mqdes;
+  va_list ap;
+  int ret;
+
+  /* Were we asked to create it? */
+
+  if ((oflags & O_CREAT) != 0)
+    {
+      /* We have to extract the additional
+       * parameters from the variable argument list.
+       */
+
+      va_start(ap, oflags);
+      mode = va_arg(ap, mode_t);
+      attr = va_arg(ap, FAR struct mq_attr *);
+      va_end(ap);
+    }
+
+  ret = nxmq_open(mq_name, oflags, mode, attr, &mqdes);
+  if (ret < 0)
+    {
+      set_errno(ret);
+      mqdes = (mqd_t)ERROR;
+    }
+
+  return mqdes;
 }
diff --git a/fs/mqueue/mq_unlink.c b/fs/mqueue/mq_unlink.c
index a99e6f3..ebe93b6 100644
--- a/fs/mqueue/mq_unlink.c
+++ b/fs/mqueue/mq_unlink.c
@@ -40,30 +40,33 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Name: mq_unlink
+ * Name: nxmq_unlink
  *
  * Description:
- *   This function removes the message queue named by "mq_name." If one
- *   or more tasks have the message queue open when mq_unlink() is called,
- *   removal of the message queue is postponed until all references to the
- *   message queue have been closed.
+ *   This is an internal OS interface.  It is functionally equivalent to
+ *   mq_unlink() except that:
+ *
+ *   - It is not a cancellation point, and
+ *   - It does not modify the errno value.
+ *
+ *  See comments with mq_unlink() for a more complete description of the
+ *  behavior of this function
  *
  * Input Parameters:
  *   mq_name - Name of the message queue
  *
  * Returned Value:
- *   None
- *
- * Assumptions:
+ *   This is an internal OS interface and should not be used by applications.
+ *   It follows the NuttX internal error return policy:  Zero (OK) is
+ *   returned on success. A negated errno value is returned on failure.
  *
  ****************************************************************************/
 
-int mq_unlink(FAR const char *mq_name)
+int nxmq_unlink(FAR const char *mq_name)
 {
   FAR struct inode *inode;
   struct inode_search_s desc;
   char fullpath[MAX_MQUEUE_PATH];
-  int errcode;
   int ret;
 
   /* Get the full path to the message queue */
@@ -80,7 +83,6 @@ int mq_unlink(FAR const char *mq_name)
     {
       /* There is no inode that includes in this path */
 
-      errcode = -ret;
       goto errout_with_search;
     }
 
@@ -93,7 +95,7 @@ int mq_unlink(FAR const char *mq_name)
 
   if (!INODE_IS_MQUEUE(inode))
     {
-      errcode = ENXIO;
+      ret = -ENXIO;
       goto errout_with_inode;
     }
 
@@ -104,13 +106,12 @@ int mq_unlink(FAR const char *mq_name)
   ret = inode_semtake();
   if (ret < 0)
     {
-      errcode = -ret;
       goto errout_with_inode;
     }
 
   if (inode->i_child != NULL)
     {
-      errcode = ENOTEMPTY;
+      ret = -ENOTEMPTY;
       goto errout_with_semaphore;
     }
 
@@ -127,7 +128,6 @@ int mq_unlink(FAR const char *mq_name)
    */
 
   DEBUGASSERT(ret >= 0 || ret == -EBUSY);
-  UNUSED(ret);
 
   /* Now we do not release the reference count in the normal way (by calling
    * inode release.  Rather, we call mq_inode_release().  mq_inode_release
@@ -151,7 +151,39 @@ errout_with_inode:
 
 errout_with_search:
   RELEASE_SEARCH(&desc);
-  set_errno(errcode);
   sched_unlock();
-  return ERROR;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: mq_unlink
+ *
+ * Description:
+ *   This function removes the message queue named by "mq_name." If one
+ *   or more tasks have the message queue open when mq_unlink() is called,
+ *   removal of the message queue is postponed until all references to the
+ *   message queue have been closed.
+ *
+ * Input Parameters:
+ *   mq_name - Name of the message queue
+ *
+ * Returned Value:
+ *   None
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+int mq_unlink(FAR const char *mq_name)
+{
+  int ret;
+
+  ret = nxmq_unlink(mq_name);
+  if (ret < 0)
+    {
+      set_errno(-ret);
+      ret = ERROR;
+    }
+
+  return ret;
 }
diff --git a/include/nuttx/mqueue.h b/include/nuttx/mqueue.h
index 7cc8bcb..69389ee 100644
--- a/include/nuttx/mqueue.h
+++ b/include/nuttx/mqueue.h
@@ -152,6 +152,93 @@ struct timespec;      /* Forward reference */
 struct task_group_s;  /* Forward reference */
 
 /****************************************************************************
+ * Name: nxmq_open
+ *
+ * Description:
+ *   This function establish a connection between a named message queue and
+ *   the calling task. This is an internal OS interface.  It is functionally
+ *   equivalent to mq_open() except that:
+ *
+ *   - It is not a cancellation point, and
+ *   - It does not modify the errno value.
+ *
+ *  See comments with mq_open() for a more complete description of the
+ *  behavior of this function
+ *
+ * Input Parameters:
+ *   mq_name - Name of the queue to open
+ *   oflags - open flags
+ *   Optional parameters.  When the O_CREAT flag is specified, two optional
+ *   parameters are expected:
+ *
+ *     1. mode_t mode (ignored), and
+ *     2. struct mq_attr *attr.  The mq_maxmsg attribute
+ *        is used at the time that the message queue is
+ *        created to determine the maximum number of
+ *        messages that may be placed in the message queue.
+ *
+ * Returned Value:
+ *   This is an internal OS interface and should not be used by applications.
+ *   It follows the NuttX internal error return policy:  Zero (OK) is
+ *   returned on success, mqdes point to the new message queue descriptor.
+ *   A negated errno value is returned on failure.
+ *
+ ****************************************************************************/
+
+int nxmq_open(FAR const char *mq_name, int oflags, mode_t mode,
+              FAR struct mq_attr *attr, FAR mqd_t *mqdes);
+
+/****************************************************************************
+ * Name: nxmq_close
+ *
+ * Description:
+ *   This is an internal OS interface.  It is functionally equivalent to
+ *   mq_close() except that:
+ *
+ *   - It is not a cancellation point, and
+ *   - It does not modify the errno value.
+ *
+ *  See comments with mq_close() for a more complete description of the
+ *  behavior of this function
+ *
+ * Input Parameters:
+ *   mqdes - Message queue descriptor.
+ *
+ * Returned Value:
+ *   This is an internal OS interface and should not be used by applications.
+ *   It follows the NuttX internal error return policy:  Zero (OK) is
+ *   returned on success. A negated errno value is returned on failure.
+ *
+ ****************************************************************************/
+
+int nxmq_close(mqd_t mqdes);
+
+/****************************************************************************
+ * Name: nxmq_unlink
+ *
+ * Description:
+ *   This is an internal OS interface.  It is functionally equivalent to
+ *   mq_unlink() except that:
+ *
+ *   - It is not a cancellation point, and
+ *   - It does not modify the errno value.
+ *
+ *  See comments with mq_unlink() for a more complete description of the
+ *  behavior of this function
+ *
+ * Input Parameters:
+ *   mq_name - Name of the message queue
+ *
+ * Returned Value:
+ *   This is an internal OS interface and should not be used by applications.
+ *   It follows the NuttX internal error return policy:  Zero (OK) is
+ *   returned on success. A negated errno value is returned on failure.
+ *
+ ****************************************************************************/
+
+int nxmq_unlink(FAR const char *mq_name);
+
+/****************************************************************************
  * Name: nxmq_send
  *
  * Description:


[incubator-nuttx] 05/05: Rename pipe2/mkfifo2 to nx_pipe/nx_mkfifo

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 32b79b22ecf71c8264c604ba82a52323c3291a08
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon May 4 14:49:38 2020 +0800

    Rename pipe2/mkfifo2 to nx_pipe/nx_mkfifo
    
    and don't modify errno anymore
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 drivers/pipes/fifo.c            | 26 +++++++++-----------------
 drivers/pipes/pipe.c            | 22 +++++++++-------------
 drivers/serial/pty.c            | 14 ++++++++------
 include/nuttx/drivers/drivers.h | 32 +++++++++++++++++---------------
 include/sys/syscall.h           | 14 ++++----------
 libs/libc/misc/lib_mkfifo.c     | 12 +++++++++++-
 libs/libc/unistd/lib_pipe.c     | 12 +++++++++++-
 syscall/syscall.csv             |  4 ++--
 syscall/syscall_lookup.h        |  7 ++-----
 syscall/syscall_stublookup.c    |  7 ++++---
 10 files changed, 77 insertions(+), 73 deletions(-)

diff --git a/drivers/pipes/fifo.c b/drivers/pipes/fifo.c
index cf32107..497559d 100644
--- a/drivers/pipes/fifo.c
+++ b/drivers/pipes/fifo.c
@@ -74,15 +74,15 @@ static const struct file_operations fifo_fops =
  ****************************************************************************/
 
 /****************************************************************************
- * Name: mkfifo2
+ * Name: nx_mkfifo
  *
  * Description:
- *   mkfifo() makes a FIFO device driver file with name 'pathname.'  Unlike
+ *   nx_mkfifo() makes a FIFO device driver file with name 'pathname.' Unlike
  *   Linux, a NuttX FIFO is not a special file type but simply a device
  *   driver instance.  'mode' specifies the FIFO's permissions.
  *
- *   Once the FIFO has been created by mkfifo(), any thread can open it for
- *   reading or writing, in the same way as an ordinary file. However, it
+ *   Once the FIFO has been created by nx_mkfifo(), any thread can open it
+ *   for reading or writing, in the same way as an ordinary file. However, it
  *   must have been opened from both reading and writing before input or
  *   output can be performed.  This FIFO implementation will block all
  *   attempts to open a FIFO read-only until at least one thread has opened
@@ -91,7 +91,7 @@ static const struct file_operations fifo_fops =
  *   If all threads that write to the FIFO have closed, subsequent calls to
  *   read() on the FIFO will return 0 (end-of-file).
  *
- *   NOTE: mkfifo2 is a special, non-standard, NuttX-only interface.  Since
+ *   NOTE: nx_mkfifo is a special, non-standard, NuttX-only interface.  Since
  *   the NuttX FIFOs are based in in-memory, circular buffers, the ability
  *   to control the size of those buffers is critical for system tuning.
  *
@@ -102,15 +102,14 @@ static const struct file_operations fifo_fops =
  *   bufsize - The size of the in-memory, circular buffer in bytes.
  *
  * Returned Value:
- *   0 is returned on success; otherwise, -1 is returned with errno set
+ *   0 is returned on success; otherwise, the negative error code return
  *   appropriately.
  *
  ****************************************************************************/
 
-int mkfifo2(FAR const char *pathname, mode_t mode, size_t bufsize)
+int nx_mkfifo(FAR const char *pathname, mode_t mode, size_t bufsize)
 {
   FAR struct pipe_dev_s *dev;
-  int errcode;
   int ret;
 
   /* Allocate and initialize a new device structure instance */
@@ -118,23 +117,16 @@ int mkfifo2(FAR const char *pathname, mode_t mode, size_t bufsize)
   dev = pipecommon_allocdev(bufsize);
   if (!dev)
     {
-      errcode = ENOMEM;
-      goto errout;
+      return -ENOMEM;
     }
 
   ret = register_driver(pathname, &fifo_fops, mode, (FAR void *)dev);
   if (ret != 0)
     {
       pipecommon_freedev(dev);
-      errcode = -ret;
-      goto errout;
     }
 
-  return OK;
-
-errout:
-  set_errno(errcode);
-  return ERROR;
+  return ret;
 }
 
 #endif /* CONFIG_DEV_FIFO_SIZE > 0 */
diff --git a/drivers/pipes/pipe.c b/drivers/pipes/pipe.c
index d595d16..e5e70f9 100644
--- a/drivers/pipes/pipe.c
+++ b/drivers/pipes/pipe.c
@@ -164,14 +164,14 @@ static int pipe_close(FAR struct file *filep)
  ****************************************************************************/
 
 /****************************************************************************
- * Name: pipe2
+ * Name: nx_pipe
  *
  * Description:
- *   pipe() creates a pair of file descriptors, pointing to a pipe inode,
+ *   nx_pipe() creates a pair of file descriptors, pointing to a pipe inode,
  *   and  places them in the array pointed to by 'fd'. fd[0] is for reading,
  *   fd[1] is for writing.
  *
- *   NOTE: pipe2 is a special, non-standard, NuttX-only interface.  Since
+ *   NOTE: nx_pipe is a special, non-standard, NuttX-only interface.  Since
  *   the NuttX FIFOs are based in in-memory, circular buffers, the ability
  *   to control the size of those buffers is critical for system tuning.
  *
@@ -186,12 +186,11 @@ static int pipe_close(FAR struct file *filep)
  *
  ****************************************************************************/
 
-int pipe2(int fd[2], size_t bufsize)
+int nx_pipe(int fd[2], size_t bufsize)
 {
   FAR struct pipe_dev_s *dev = NULL;
   char devname[16];
   int pipeno;
-  int errcode;
   int ret;
 
   /* Get exclusive access to the pipe allocation data */
@@ -199,7 +198,6 @@ int pipe2(int fd[2], size_t bufsize)
   ret = nxsem_wait(&g_pipesem);
   if (ret < 0)
     {
-      errcode = -ret;
       goto errout;
     }
 
@@ -209,7 +207,7 @@ int pipe2(int fd[2], size_t bufsize)
   if (pipeno < 0)
     {
       nxsem_post(&g_pipesem);
-      errcode = -pipeno;
+      ret = pipeno;
       goto errout;
     }
 
@@ -227,7 +225,7 @@ int pipe2(int fd[2], size_t bufsize)
       if (!dev)
         {
           nxsem_post(&g_pipesem);
-          errcode = ENOMEM;
+          ret = -ENOMEM;
           goto errout_with_pipe;
         }
 
@@ -239,7 +237,6 @@ int pipe2(int fd[2], size_t bufsize)
       if (ret != 0)
         {
           nxsem_post(&g_pipesem);
-          errcode = -ret;
           goto errout_with_dev;
         }
 
@@ -255,7 +252,7 @@ int pipe2(int fd[2], size_t bufsize)
   fd[1] = nx_open(devname, O_WRONLY);
   if (fd[1] < 0)
     {
-      errcode = -fd[1];
+      ret = fd[1];
       goto errout_with_driver;
     }
 
@@ -264,7 +261,7 @@ int pipe2(int fd[2], size_t bufsize)
   fd[0] = nx_open(devname, O_RDONLY);
   if (fd[0] < 0)
     {
-      errcode = -fd[0];
+      ret = fd[0];
       goto errout_with_wrfd;
     }
 
@@ -286,8 +283,7 @@ errout_with_pipe:
   pipe_free(pipeno);
 
 errout:
-  set_errno(errcode);
-  return ERROR;
+  return ret;
 }
 
 #endif /* CONFIG_DEV_PIPE_SIZE > 0 */
diff --git a/drivers/serial/pty.c b/drivers/serial/pty.c
index 3530b95..429d5b3 100644
--- a/drivers/serial/pty.c
+++ b/drivers/serial/pty.c
@@ -292,7 +292,9 @@ static int pty_open(FAR struct file *filep)
       sched_lock();
       while (devpair->pp_locked)
         {
-          /* Wait until unlocked.  We will also most certainly suspend here. */
+          /* Wait until unlocked.
+           * We will also most certainly suspend here.
+           */
 
           ret = nxsem_wait(&devpair->pp_slavesem);
           if (ret < 0)
@@ -966,7 +968,7 @@ static int pty_poll(FAR struct file *filep, FAR struct pollfd *fds,
       pollp = (FAR struct pty_poll_s *)fds->priv;
     }
 
-  /* POLLIN: Data other than high-priority data may be read without blocking. */
+  /* POLLIN: Data may be read without blocking. */
 
   if ((fds->events & POLLIN) != 0)
     {
@@ -1070,8 +1072,8 @@ static int pty_unlink(FAR struct inode *inode)
  *   minor - The number that qualifies the naming of the created devices.
  *
  * Returned Value:
- *   Zero (OK) is returned on success; a negated errno value is returned on
- *   any failure.
+ *   0 is returned on success; otherwise, the negative error code return
+ *   appropriately.
  *
  ****************************************************************************/
 
@@ -1116,13 +1118,13 @@ int pty_register(int minor)
    *   pipe_b:  Master sink, slave source (RX, master-to-slave)
    */
 
-  ret = pipe2(pipe_a, CONFIG_PSEUDOTERM_TXBUFSIZE);
+  ret = nx_pipe(pipe_a, CONFIG_PSEUDOTERM_TXBUFSIZE);
   if (ret < 0)
     {
       goto errout_with_devpair;
     }
 
-  ret = pipe2(pipe_b, CONFIG_PSEUDOTERM_RXBUFSIZE);
+  ret = nx_pipe(pipe_b, CONFIG_PSEUDOTERM_RXBUFSIZE);
   if (ret < 0)
     {
       goto errout_with_pipea;
diff --git a/include/nuttx/drivers/drivers.h b/include/nuttx/drivers/drivers.h
index 82ac9ff..ad0813e 100644
--- a/include/nuttx/drivers/drivers.h
+++ b/include/nuttx/drivers/drivers.h
@@ -1,7 +1,8 @@
 /****************************************************************************
  * include/nuttx/fs/drivers.h
  *
- *   Copyright (C) 2007-2009, 2011-2013, 2015-2016 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2007-2009, 2011-2013, 2015-2016 Gregory Nutt.
+ *   All rights reserved.
  *   Author: Gregory Nutt <gn...@nuttx.org>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -165,8 +166,9 @@ int bchdev_register(FAR const char *blkdev, FAR const char *chardev,
 
 int bchdev_unregister(FAR const char *chardev);
 
-/* Low level, direct access.  NOTE:  low-level access and character driver access
- * are incompatible.  One and only one access method should be implemented.
+/* Low level, direct access. NOTE: low-level access and character driver
+ * access are incompatible. One and only one access method should be
+ * implemented.
  */
 
 /****************************************************************************
@@ -216,14 +218,14 @@ ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset,
                      size_t len);
 
 /****************************************************************************
- * Name: pipe2
+ * Name: nx_pipe
  *
  * Description:
- *   pipe() creates a pair of file descriptors, pointing to a pipe inode,
+ *   nx_pipe() creates a pair of file descriptors, pointing to a pipe inode,
  *   and  places them in the array pointed to by 'fd'. fd[0] is for reading,
  *   fd[1] is for writing.
  *
- *   NOTE: pipe2 is a special, non-standard, NuttX-only interface.  Since
+ *   NOTE: nx_pipe is a special, non-standard, NuttX-only interface.  Since
  *   the NuttX FIFOs are based in in-memory, circular buffers, the ability
  *   to control the size of those buffers is critical for system tuning.
  *
@@ -233,25 +235,25 @@ ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset,
  *   bufsize - The size of the in-memory, circular buffer in bytes.
  *
  * Returned Value:
- *   0 is returned on success; otherwise, -1 is returned with errno set
+ *   0 is returned on success; otherwise, the negative error code return
  *   appropriately.
  *
  ****************************************************************************/
 
 #if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0
-int pipe2(int fd[2], size_t bufsize);
+int nx_pipe(int fd[2], size_t bufsize);
 #endif
 
 /****************************************************************************
- * Name: mkfifo2
+ * Name: nx_mkfifo
  *
  * Description:
- *   mkfifo() makes a FIFO device driver file with name 'pathname.'  Unlike
+ *   nx_mkfifo() makes a FIFO device driver file with name 'pathname.' Unlike
  *   Linux, a NuttX FIFO is not a special file type but simply a device
  *   driver instance.  'mode' specifies the FIFO's permissions.
  *
- *   Once the FIFO has been created by mkfifo(), any thread can open it for
- *   reading or writing, in the same way as an ordinary file. However, it
+ *   Once the FIFO has been created by nx_mkfifo(), any thread can open it
+ *   for reading or writing, in the same way as an ordinary file. However, it
  *   must have been opened from both reading and writing before input or
  *   output can be performed.  This FIFO implementation will block all
  *   attempts to open a FIFO read-only until at least one thread has opened
@@ -260,7 +262,7 @@ int pipe2(int fd[2], size_t bufsize);
  *   If all threads that write to the FIFO have closed, subsequent calls to
  *   read() on the FIFO will return 0 (end-of-file).
  *
- *   NOTE: mkfifo2 is a special, non-standard, NuttX-only interface.  Since
+ *   NOTE: nx_mkfifo is a special, non-standard, NuttX-only interface.  Since
  *   the NuttX FIFOs are based in in-memory, circular buffers, the ability
  *   to control the size of those buffers is critical for system tuning.
  *
@@ -271,13 +273,13 @@ int pipe2(int fd[2], size_t bufsize);
  *   bufsize - The size of the in-memory, circular buffer in bytes.
  *
  * Returned Value:
- *   0 is returned on success; otherwise, -1 is returned with errno set
+ *   0 is returned on success; otherwise, the negative error code return
  *   appropriately.
  *
  ****************************************************************************/
 
 #if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0
-int mkfifo2(FAR const char *pathname, mode_t mode, size_t bufsize);
+int nx_mkfifo(FAR const char *pathname, mode_t mode, size_t bufsize);
 #endif
 
 #undef EXTERN
diff --git a/include/sys/syscall.h b/include/sys/syscall.h
index 6fffa7c..6ee8655 100644
--- a/include/sys/syscall.h
+++ b/include/sys/syscall.h
@@ -371,17 +371,11 @@
 #endif
 
 #if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0
-#  define SYS_pipe2                    (__SYS_pipes + 0)
-#  define __SYS_mkfifo2                (__SYS_pipes + 1)
+#  define SYS_nx_pipe                  (__SYS_pipes + 0)
+#  define SYS_nx_mkfifo                (__SYS_pipes + 1)
+#  define __SYS_fs_fdopen              (__SYS_pipes + 2)
 #else
-#  define __SYS_mkfifo2                (__SYS_pipes + 0)
-#endif
-
-#if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0
-#  define SYS_mkfifo2                  (__SYS_mkfifo2 + 0)
-#  define __SYS_fs_fdopen              (__SYS_mkfifo2 + 1)
-#else
-#  define __SYS_fs_fdopen              (__SYS_mkfifo2 + 0)
+#  define __SYS_fs_fdopen              (__SYS_pipes + 0)
 #endif
 
 #if CONFIG_NFILE_STREAMS > 0
diff --git a/libs/libc/misc/lib_mkfifo.c b/libs/libc/misc/lib_mkfifo.c
index 42aff2b..ec2ab01 100644
--- a/libs/libc/misc/lib_mkfifo.c
+++ b/libs/libc/misc/lib_mkfifo.c
@@ -39,6 +39,7 @@
 
 #include <nuttx/config.h>
 
+#include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -81,7 +82,16 @@
 
 int mkfifo(FAR const char *pathname, mode_t mode)
 {
-  return mkfifo2(pathname, mode, CONFIG_DEV_FIFO_SIZE);
+  int ret;
+
+  ret = nx_mkfifo(pathname, mode, CONFIG_DEV_FIFO_SIZE);
+  if (ret < 0)
+    {
+      set_errno(-ret);
+      ret = ERROR;
+    }
+
+  return ret;
 }
 
 #endif /* CONFIG_PIPES && CONFIG_DEV_FIFO_SIZE > 0 */
diff --git a/libs/libc/unistd/lib_pipe.c b/libs/libc/unistd/lib_pipe.c
index bd16b0f..c5cbba7 100644
--- a/libs/libc/unistd/lib_pipe.c
+++ b/libs/libc/unistd/lib_pipe.c
@@ -39,6 +39,7 @@
 
 #include <nuttx/config.h>
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <nuttx/drivers/drivers.h>
@@ -69,7 +70,16 @@
 
 int pipe(int fd[2])
 {
-  return pipe2(fd, CONFIG_DEV_PIPE_SIZE);
+  int ret;
+
+  ret = nx_pipe(fd, CONFIG_DEV_PIPE_SIZE);
+  if (ret < 0)
+    {
+      set_errno(-ret);
+      ret = ERROR;
+    }
+
+  return ret;
 }
 
 #endif /* CONFIG_PIPES && CONFIG_DEV_PIPE_SIZE > 0 */
diff --git a/syscall/syscall.csv b/syscall/syscall.csv
index 89bdfc4..238b093 100644
--- a/syscall/syscall.csv
+++ b/syscall/syscall.csv
@@ -48,7 +48,6 @@
 "listen","sys/socket.h","defined(CONFIG_NET)","int","int","int"
 "lseek","unistd.h","","off_t","int","off_t","int"
 "mkdir","sys/stat.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char*","mode_t"
-"mkfifo2","nuttx/drivers/drivers.h","defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0","int","FAR const char*","mode_t","size_t"
 "mmap","sys/mman.h","","FAR void*","FAR void*","size_t","int","int","int","off_t"
 "munmap","sys/mman.h","defined(CONFIG_FS_RAMMAP)","int","FAR void *","size_t"
 "modhandle","nuttx/module.h","defined(CONFIG_MODULE)","FAR void *","FAR const char *"
@@ -63,13 +62,14 @@
 "mq_timedreceive","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","ssize_t","mqd_t","char*","size_t","FAR unsigned int*","const struct timespec*"
 "mq_timedsend","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","const char*","size_t","unsigned int","const struct timespec*"
 "mq_unlink","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","const char*"
+"nx_mkfifo","nuttx/drivers/drivers.h","defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0","int","FAR const char*","mode_t","size_t"
+"nx_pipe","nuttx/drivers/drivers.h","defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0","int","int [2]|int*","size_t"
 "nx_task_spawn","nuttx/spawn.h","defined(CONFIG_LIB_SYSCALL) && !defined(CONFIG_BUILD_KERNEL)","int","FAR const struct spawn_syscall_parms_s *"
 "nx_vsyslog","nuttx/syslog/syslog.h","","int","int","FAR const IPTR char*","FAR va_list*"
 "on_exit","stdlib.h","defined(CONFIG_SCHED_ONEXIT)","int","CODE void (*)(int, FAR void *)","FAR void *"
 "open","fcntl.h","","int","const char*","int","..."
 "opendir","dirent.h","","FAR DIR*","FAR const char*"
 "pgalloc", "nuttx/arch.h", "defined(CONFIG_BUILD_KERNEL)", "uintptr_t", "uintptr_t", "unsigned int"
-"pipe2","nuttx/drivers/drivers.h","defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0","int","int [2]|int*","size_t"
 "poll","poll.h","","int","FAR struct pollfd*","nfds_t","int"
 "ppoll","poll.h","","int","FAR struct pollfd*","nfds_t","FAR const struct timespec *","FAR const sigset_t *"
 "prctl","sys/prctl.h", "CONFIG_TASK_NAME_SIZE > 0","int","int","..."
diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h
index 37220dd..17e5e6a 100644
--- a/syscall/syscall_lookup.h
+++ b/syscall/syscall_lookup.h
@@ -259,11 +259,8 @@ SYSCALL_LOOKUP(up_assert,                  2, STUB_up_assert)
 #endif
 
 #if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0
-  SYSCALL_LOOKUP(pipe2,                    2, STUB_pipe2)
-#endif
-
-#if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0
-  SYSCALL_LOOKUP(mkfifo2,                  3, STUB_mkfifo2)
+  SYSCALL_LOOKUP(nx_pipe,                  2, STUB_nx_pipe)
+  SYSCALL_LOOKUP(nx_mkfifo,                3, STUB_nx_mkfifo)
 #endif
 
 #if CONFIG_NFILE_STREAMS > 0
diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c
index e63cf6d..493f8e6 100644
--- a/syscall/syscall_stublookup.c
+++ b/syscall/syscall_stublookup.c
@@ -57,7 +57,8 @@ uintptr_t STUB_sched_setscheduler(int nbr, uintptr_t parm1, uintptr_t parm2,
             uintptr_t parm3);
 uintptr_t STUB_sched_unlock(int nbr);
 uintptr_t STUB_sched_yield(int nbr);
-uintptr_t STUB_sched_get_stackinfo(int nbr, uintptr_t parm1, uintptr_t parm2);
+uintptr_t STUB_sched_get_stackinfo(int nbr, uintptr_t parm1,
+            uintptr_t parm2);
 
 uintptr_t STUB_sched_getaffinity(int nbr, uintptr_t parm1, uintptr_t parm2,
             uintptr_t parm3);
@@ -264,8 +265,8 @@ uintptr_t STUB_link(int nbr, uintptr_t parm1, uintptr_t parm2);
 uintptr_t STUB_readlink(int nbr, uintptr_t parm1, uintptr_t parm2,
             uintptr_t parm3);
 
-uintptr_t STUB_pipe2(int nbr, uintptr_t parm1, uintptr_t parm2);
-uintptr_t STUB_mkfifo2(int nbr, uintptr_t parm1, uintptr_t parm2,
+uintptr_t STUB_nx_pipe(int nbr, uintptr_t parm1, uintptr_t parm2);
+uintptr_t STUB_nx_mkfifo(int nbr, uintptr_t parm1, uintptr_t parm2,
             uintptr_t parm3);
 
 uintptr_t STUB_fs_fdopen(int nbr, uintptr_t parm1, uintptr_t parm2,


[incubator-nuttx] 01/05: fs/vfs: Add nx_poll function

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 1da8cd6b89e78cf332d18f0fd4c27c88f61a32f4
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon May 4 01:51:42 2020 +0800

    fs/vfs: Add nx_poll function
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 fs/vfs/fs_poll.c      | 99 +++++++++++++++++++++++++++++++--------------------
 include/nuttx/fs/fs.h | 17 +++++++++
 2 files changed, 77 insertions(+), 39 deletions(-)

diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c
index 737d9d3..c90c931 100644
--- a/fs/vfs/fs_poll.c
+++ b/fs/vfs/fs_poll.c
@@ -88,13 +88,12 @@ static int poll_fdsetup(int fd, FAR struct pollfd *fds, bool setup)
 {
   /* Check for a valid file descriptor */
 
-  if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS)
+  if (fd >= CONFIG_NFILE_DESCRIPTORS)
     {
       /* Perform the socket ioctl */
 
 #ifdef CONFIG_NET
-      if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS +
-                              CONFIG_NSOCKET_DESCRIPTORS))
+      if (fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS))
         {
           return net_poll(fd, fds, setup);
         }
@@ -360,7 +359,7 @@ int file_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
 }
 
 /****************************************************************************
- * Name: fdesc_poll
+ * Name: fs_poll
  *
  * Description:
  *   The standard poll() operation redirects operations on file descriptors
@@ -399,49 +398,29 @@ int fs_poll(int fd, FAR struct pollfd *fds, bool setup)
 }
 
 /****************************************************************************
- * Name: poll
+ * Name: nx_poll
  *
  * Description:
- *   poll() waits for one of a set of file descriptors to become ready to
- *   perform I/O.  If none of the events requested (and no error) has
- *   occurred for any of  the  file  descriptors,  then  poll() blocks until
- *   one of the events occurs.
+ *   nx_poll() is similar to the standard 'poll' interface except that is
+ *   not a cancellation point and it does not modify the errno variable.
  *
- * Input Parameters:
- *   fds  - List of structures describing file descriptors to be monitored
- *   nfds - The number of entries in the list
- *   timeout - Specifies an upper limit on the time for which poll() will
- *     block in milliseconds.  A negative value of timeout means an infinite
- *     timeout.
+ *   nx_poll() is an internal NuttX interface and should not be called from
+ *   applications.
  *
  * Returned Value:
- *   On success, the number of structures that have non-zero revents fields.
- *   A value of 0 indicates that the call timed out and no file descriptors
- *   were ready.  On error, -1 is returned, and errno is set appropriately:
- *
- *   EBADF  - An invalid file descriptor was given in one of the sets.
- *   EFAULT - The fds address is invalid
- *   EINTR  - A signal occurred before any requested event.
- *   EINVAL - The nfds value exceeds a system limit.
- *   ENOMEM - There was no space to allocate internal data structures.
- *   ENOSYS - One or more of the drivers supporting the file descriptor
- *     does not support the poll method.
+ *   Zero is returned on success; a negated value is returned on any failure.
  *
  ****************************************************************************/
 
-int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
+int nx_poll(FAR struct pollfd *fds, unsigned int nfds, int timeout)
 {
   sem_t sem;
   int count = 0;
-  int errcode;
+  int ret2;
   int ret;
 
   DEBUGASSERT(nfds == 0 || fds != NULL);
 
-  /* poll() is a cancellation point */
-
-  enter_cancellation_point();
-
   /* This semaphore is used for signaling and, hence, should not have
    * priority inheritance enabled.
    */
@@ -515,23 +494,65 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
        * Preserve ret, if negative, since it holds the result of the wait.
        */
 
-      errcode = poll_teardown(fds, nfds, &count, ret);
-      if (errcode < 0 && ret >= 0)
+      ret2 = poll_teardown(fds, nfds, &count, ret);
+      if (ret2 < 0 && ret >= 0)
         {
-          ret = errcode;
+          ret = ret2;
         }
     }
 
   nxsem_destroy(&sem);
-  leave_cancellation_point();
+  return ret < 0 ? ret : count;
+}
+
+/****************************************************************************
+ * Name: poll
+ *
+ * Description:
+ *   poll() waits for one of a set of file descriptors to become ready to
+ *   perform I/O.  If none of the events requested (and no error) has
+ *   occurred for any of  the  file  descriptors,  then  poll() blocks until
+ *   one of the events occurs.
+ *
+ * Input Parameters:
+ *   fds  - List of structures describing file descriptors to be monitored
+ *   nfds - The number of entries in the list
+ *   timeout - Specifies an upper limit on the time for which poll() will
+ *     block in milliseconds.  A negative value of timeout means an infinite
+ *     timeout.
+ *
+ * Returned Value:
+ *   On success, the number of structures that have non-zero revents fields.
+ *   A value of 0 indicates that the call timed out and no file descriptors
+ *   were ready.  On error, -1 is returned, and errno is set appropriately:
+ *
+ *   EBADF  - An invalid file descriptor was given in one of the sets.
+ *   EFAULT - The fds address is invalid
+ *   EINTR  - A signal occurred before any requested event.
+ *   EINVAL - The nfds value exceeds a system limit.
+ *   ENOMEM - There was no space to allocate internal data structures.
+ *   ENOSYS - One or more of the drivers supporting the file descriptor
+ *     does not support the poll method.
+ *
+ ****************************************************************************/
 
-  /* Check for errors */
+int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
+{
+  int ret;
+
+  /* poll() is a cancellation point */
+
+  enter_cancellation_point();
+
+  /* Let nx_poll() do all of the work */
 
+  ret = nx_poll(fds, nfds, timeout);
   if (ret < 0)
     {
       set_errno(-ret);
-      return ERROR;
+      ret = ERROR;
     }
 
-  return count;
+  leave_cancellation_point();
+  return ret;
 }
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index 4221d85..8343c36 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -1376,6 +1376,23 @@ int file_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup);
 int fs_poll(int fd, FAR struct pollfd *fds, bool setup);
 
 /****************************************************************************
+ * Name: nx_poll
+ *
+ * Description:
+ *   nx_poll() is similar to the standard 'poll' interface except that is
+ *   not a cancellation point and it does not modify the errno variable.
+ *
+ *   nx_poll() is an internal NuttX interface and should not be called from
+ *   applications.
+ *
+ * Returned Value:
+ *   Zero is returned on success; a negated value is returned on any failure.
+ *
+ ****************************************************************************/
+
+int nx_poll(FAR struct pollfd *fds, unsigned int nfds, int timeout);
+
+/****************************************************************************
  * Name: file_fstat
  *
  * Description: