You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/03/04 20:04:02 UTC

[incubator-nuttx] branch master updated (66c61d4 -> b3b48a6)

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

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


    from 66c61d4  imxrt: userleds: Teensy 4.x board LED is active high
     new 19e7963  vfs: Forward fcntl(F_SETFD...) to ioctl(FIOCLEX|FIONCLEX...)
     new b2c86f8  net: Remove psock_fcntl related code
     new b3b48a6  fs/aio: Don't include include/nuttx/net/net.h

The 3 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:
 fs/aio/aio.h              |   1 -
 fs/aio/aio_read.c         |   1 -
 fs/aio/aioc_contain.c     |   1 -
 fs/vfs/fs_fcntl.c         |  22 +---
 fs/vfs/fs_ioctl.c         |   8 +-
 include/fcntl.h           |   2 +-
 include/nuttx/net/net.h   |  40 --------
 net/netdev/netdev_ioctl.c |  79 +++++++++++++-
 net/socket/Make.defs      |   8 +-
 net/socket/net_vfcntl.c   | 256 ----------------------------------------------
 10 files changed, 87 insertions(+), 331 deletions(-)
 delete mode 100644 net/socket/net_vfcntl.c

[incubator-nuttx] 02/03: net: Remove psock_fcntl related code

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

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

commit b2c86f808d4553336cd0fd8b669629dd2141dcd6
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Mar 4 16:13:17 2022 +0800

    net: Remove psock_fcntl related code
    
    since the nonblocking mode set through psock_ioctl now
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 fs/vfs/fs_fcntl.c         |  15 ---
 include/nuttx/net/net.h   |  40 --------
 net/netdev/netdev_ioctl.c |  79 +++++++++++++-
 net/socket/Make.defs      |   8 +-
 net/socket/net_vfcntl.c   | 256 ----------------------------------------------
 5 files changed, 80 insertions(+), 318 deletions(-)

diff --git a/fs/vfs/fs_fcntl.c b/fs/vfs/fs_fcntl.c
index c6b929a..1f6f425 100644
--- a/fs/vfs/fs_fcntl.c
+++ b/fs/vfs/fs_fcntl.c
@@ -33,7 +33,6 @@
 #include <nuttx/sched.h>
 #include <nuttx/cancelpt.h>
 #include <nuttx/fs/fs.h>
-#include <nuttx/net/net.h>
 
 #include "inode/inode.h"
 
@@ -56,20 +55,6 @@ static int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
       return -EBADF;
     }
 
-  /* check for operations on a socket descriptor */
-
-#ifdef CONFIG_NET
-  if (INODE_IS_SOCKET(filep->f_inode) &&
-      cmd != F_DUPFD && cmd != F_GETFD && cmd != F_SETFD)
-    {
-      /* Yes.. defer socket descriptor operations to
-       * psock_vfcntl(). The errno is not set on failures.
-       */
-
-      return psock_vfcntl(file_socket(filep), cmd, ap);
-    }
-#endif
-
   switch (cmd)
     {
       case F_DUPFD:
diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h
index 8bdd503..db9a786 100644
--- a/include/nuttx/net/net.h
+++ b/include/nuttx/net/net.h
@@ -1410,46 +1410,6 @@ ssize_t psock_sendfile(FAR struct socket *psock, FAR struct file *infile,
 #endif
 
 /****************************************************************************
- * Name: psock_vfcntl
- *
- * Description:
- *   Performs fcntl operations on socket.
- *
- * Input Parameters:
- *   psock - An instance of the internal socket structure.
- *   cmd   - The fcntl command.
- *   ap    - Command-specific arguments.
- *
- * Returned Value:
- *   Zero (OK) is returned on success; a negated errno value is returned on
- *   any failure to indicate the nature of the failure.
- *
- ****************************************************************************/
-
-int psock_vfcntl(FAR struct socket *psock, int cmd, va_list ap);
-
-/****************************************************************************
- * Name: psock_fcntl
- *
- * Description:
- *   Similar to the standard fcntl function except that is accepts a struct
- *   struct socket instance instead of a file descriptor.
- *
- * Input Parameters:
- *   psock - An instance of the internal socket structure.
- *   cmd   - Identifies the operation to be performed.  Command specific
- *           arguments may follow.
- *
- * Returned Value:
- *   The nature of the return value depends on the command.  Non-negative
- *   values indicate success.  Failures are reported as negated errno
- *   values.
- *
- ****************************************************************************/
-
-int psock_fcntl(FAR struct socket *psock, int cmd, ...);
-
-/****************************************************************************
  * Name: psock_socketpair
  *
  * Description:
diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c
index ceec5b6..e77d7b7 100644
--- a/net/netdev/netdev_ioctl.c
+++ b/net/netdev/netdev_ioctl.c
@@ -1473,6 +1473,73 @@ static int netdev_rt_ioctl(FAR struct socket *psock, int cmd,
 #endif
 
 /****************************************************************************
+ * Name: netdev_file_ioctl
+ *
+ * Description:
+ *   Perform file ioctl operations.
+ *
+ * Parameters:
+ *   psock    Socket structure
+ *   cmd      The ioctl command
+ *   arg      The argument of the ioctl cmd
+ *
+ * Return:
+ *   >=0 on success (positive non-zero values are cmd-specific)
+ *   Negated errno returned on failure.
+ *
+ ****************************************************************************/
+
+static int netdev_file_ioctl(FAR struct socket *psock, int cmd,
+                             unsigned long arg)
+{
+  int ret;
+
+  switch (cmd)
+    {
+      case FIONBIO:
+        {
+          FAR struct socket_conn_s *conn = psock->s_conn;
+          FAR int *nonblock = (FAR int *)(uintptr_t)arg;
+          sockcaps_t sockcaps;
+
+           /* Non-blocking is the only configurable option.  And it applies
+            * only Unix domain sockets and to read operations on TCP/IP
+            * and UDP/IP sockets when read-ahead is enabled.
+            */
+
+          DEBUGASSERT(psock->s_sockif != NULL &&
+                      psock->s_sockif->si_sockcaps != NULL);
+          sockcaps = psock->s_sockif->si_sockcaps(psock);
+
+          if ((sockcaps & SOCKCAP_NONBLOCKING) != 0)
+            {
+               if (nonblock && *nonblock)
+                 {
+                   conn->s_flags |= _SF_NONBLOCK;
+                 }
+               else
+                 {
+                   conn->s_flags &= ~_SF_NONBLOCK;
+                 }
+
+               ret = OK;
+            }
+          else
+            {
+              nerr("ERROR: Non-blocking not supported for this socket\n");
+              ret = -ENOSYS;
+            }
+        }
+
+      default:
+        ret = -ENOTTY;
+        break;
+    }
+
+  return ret;
+}
+
+/****************************************************************************
  * Name: netdev_ioctl
  *
  * Description:
@@ -1673,13 +1740,21 @@ int psock_vioctl(FAR struct socket *psock, int cmd, va_list ap)
 
   arg = va_arg(ap, unsigned long);
 
-  /* Check for a USRSOCK ioctl command */
+  /* Check for socket specific ioctl command */
 
   ret = netdev_ioctl(psock, cmd, arg);
+
+  /* Check for file ioctl command */
+
   if (ret == -ENOTTY)
     {
-      /* Check for a standard network IOCTL command. */
+      ret = netdev_file_ioctl(psock, cmd, arg);
+    }
+
+  /* Check for a standard network IOCTL command. */
 
+  if (ret == -ENOTTY)
+    {
       ret = netdev_ifr_ioctl(psock, cmd, (FAR struct ifreq *)(uintptr_t)arg);
     }
 
diff --git a/net/socket/Make.defs b/net/socket/Make.defs
index 4134efa..2f0e351 100644
--- a/net/socket/Make.defs
+++ b/net/socket/Make.defs
@@ -21,11 +21,9 @@
 # Include socket source files
 
 SOCK_CSRCS += accept.c bind.c connect.c getsockname.c getpeername.c
-SOCK_CSRCS += listen.c recv.c recvfrom.c send.c sendto.c
-SOCK_CSRCS += socket.c socketpair.c net_close.c
-SOCK_CSRCS += recvmsg.c sendmsg.c
-SOCK_CSRCS += net_dup2.c net_sockif.c net_poll.c net_vfcntl.c
-SOCK_CSRCS += net_fstat.c
+SOCK_CSRCS += listen.c recv.c recvfrom.c send.c sendto.c socket.c
+SOCK_CSRCS += socketpair.c net_close.c recvmsg.c sendmsg.c
+SOCK_CSRCS += net_dup2.c net_sockif.c net_poll.c net_fstat.c
 
 # Socket options
 
diff --git a/net/socket/net_vfcntl.c b/net/socket/net_vfcntl.c
deleted file mode 100644
index d8610c3..0000000
--- a/net/socket/net_vfcntl.c
+++ /dev/null
@@ -1,256 +0,0 @@
-/****************************************************************************
- * net/socket/net_vfcntl.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/socket.h>
-#include <stdint.h>
-#include <stdarg.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <debug.h>
-#include <assert.h>
-
-#include <arch/irq.h>
-#include <nuttx/net/net.h>
-#include "socket/socket.h"
-#include "usrsock/usrsock.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: psock_vfcntl
- *
- * Description:
- *   Performs fcntl operations on socket
- *
- * Input Parameters:
- *   psock - An instance of the internal socket structure.
- *   cmd   - The fcntl command.
- *   ap    - Command-specific arguments
- *
- * Returned Value:
- *   Zero (OK) is returned on success; a negated errno value is returned on
- *   any failure to indicate the nature of the failure.
- *
- ****************************************************************************/
-
-int psock_vfcntl(FAR struct socket *psock, int cmd, va_list ap)
-{
-  FAR struct socket_conn_s *conn;
-  int ret = -EINVAL;
-
-  ninfo("sockfd=%p cmd=%d\n", psock, cmd);
-
-  /* Verify that the sockfd corresponds to valid, allocated socket */
-
-  if (psock == NULL || psock->s_conn == NULL)
-    {
-      return -EBADF;
-    }
-
-  conn = psock->s_conn;
-
-  /* Interrupts must be disabled in order to perform operations on socket
-   * structures
-   */
-
-  net_lock();
-  switch (cmd)
-    {
-      case F_GETFL:
-        /* Get the file status flags and file access modes, defined in
-         * <fcntl.h>, for the file description associated with fd. The file
-         * access modes can be extracted from the return value using the
-         * mask O_ACCMODE, which is defined  in <fcntl.h>. File status flags
-         * and file access modes are associated with the file description
-         * and do not affect other file descriptors that refer to the same
-         * file with different open file descriptions.
-         */
-
-        {
-          sockcaps_t sockcaps;
-
-          /* This summarizes the behavior of all NuttX sockets */
-
-          ret = O_RDWR | O_SYNC | O_RSYNC;
-
-          /* Unix domain sockets may be non-blocking.  TCP/IP and UDP/IP
-           * sockets may also be non-blocking if read-ahead is enabled
-           */
-
-          DEBUGASSERT(psock->s_sockif != NULL &&
-                      psock->s_sockif->si_sockcaps != NULL);
-          sockcaps = psock->s_sockif->si_sockcaps(psock);
-
-          if ((sockcaps & SOCKCAP_NONBLOCKING) != 0 &&
-              _SS_ISNONBLOCK(conn->s_flags))
-            {
-              ret |= O_NONBLOCK;
-            }
-        }
-        break;
-
-      case F_SETFL:
-        /* Set the file status flags, defined in <fcntl.h>, for the file
-         * description associated with fd from the corresponding bits in
-         * the third argument, arg, taken as type int. Bits corresponding
-         * to the file access mode and the file creation flags, as defined
-         * in <fcntl.h>, that are set in arg will be ignored. If any bits
-         * in arg other than those mentioned here are changed by the
-         * application, the result is unspecified.
-         */
-
-        {
-           /* Non-blocking is the only configurable option.  And it applies
-            * only Unix domain sockets and to read operations on TCP/IP
-            * and UDP/IP sockets when read-ahead is enabled.
-            */
-
-          int mode =  va_arg(ap, int);
-          sockcaps_t sockcaps;
-
-          DEBUGASSERT(psock->s_sockif != NULL &&
-                      psock->s_sockif->si_sockcaps != NULL);
-          sockcaps = psock->s_sockif->si_sockcaps(psock);
-
-          if ((sockcaps & SOCKCAP_NONBLOCKING) != 0)
-            {
-               if ((mode & O_NONBLOCK) != 0)
-                 {
-                   conn->s_flags |= _SF_NONBLOCK;
-                 }
-               else
-                 {
-                   conn->s_flags &= ~_SF_NONBLOCK;
-                 }
-
-               ret = OK;
-            }
-          else
-            {
-              nerr("ERROR: Non-blocking not supported for this socket\n");
-              ret = -ENOSYS;
-            }
-        }
-        break;
-
-      case F_GETOWN:
-        /* If fd refers to a socket, get the process or process group ID
-         * specified to receive SIGURG signals when out-of-band data is
-         * available.  Positive values indicate a process ID; negative
-         * values, other than -1, indicate a process group ID. If fd does
-         * not refer to a socket, the results are unspecified.
-         */
-
-      case F_SETOWN:
-        /* If fd refers to a socket, set the process or process group ID
-         * specified to receive SIGURG signals when out-of-band data is
-         * available, using the value of the third argument, arg, taken as
-         * type int. Positive values indicate a process ID; negative values,
-         * other than -1, indicate a process group ID.  If fd does not refer
-         * to a socket, the results are unspecified.
-         */
-
-      case F_GETLK:
-        /* Get the first lock which blocks the lock description pointed to
-         * by the third argument, arg, taken as a pointer to type struct
-         * flock, defined in <fcntl.h>.  The information retrieved shall
-         * overwrite the information passed to fcntl() in the structure
-         * flock. If no lock is found that would prevent this lock from
-         * being created, then the structure shall be left unchanged except
-         * for the lock type which shall be set to F_UNLCK.
-         */
-
-      case F_SETLK:
-        /* Set or clear a file segment lock according to the lock
-         * description pointed to by the third argument, arg, taken as a
-         * pointer to type struct flock, defined in <fcntl.h>. F_SETLK can
-         * establish shared (or read) locks (F_RDLCK) or exclusive (or
-         * write) locks (F_WRLCK), as well as to remove either type of
-         * lock  (F_UNLCK).  F_RDLCK, F_WRLCK, and F_UNLCK are defined in
-         * <fcntl.h>. If a shared or exclusive lock cannot be set, fcntl()
-         * shall return immediately with a return value of -1.
-         */
-
-      case F_SETLKW:
-        /* This command shall be equivalent to F_SETLK except that if a
-         * shared or exclusive lock is blocked by other locks, the thread
-         * shall wait until the request can be satisfied. If a signal that
-         * is to be caught is received while fcntl() is waiting for a
-         * region, fcntl() shall be interrupted. Upon return from the signal
-         * handler, fcntl() shall return -1 with errno set to [EINTR], and
-         * the lock operation shall not be done.
-         */
-
-         ret = -ENOSYS; /* F_GETOWN, F_SETOWN, F_GETLK, F_SETLK, F_SETLKW */
-         break;
-
-      default:
-         break;
-    }
-
-  net_unlock();
-  return ret;
-}
-
-/****************************************************************************
- * Name: psock_fcntl
- *
- * Description:
- *   Similar to the standard fcntl function except that is accepts a struct
- *   struct socket instance instead of a file descriptor.
- *
- * Input Parameters:
- *   psock - An instance of the internal socket structure.
- *   cmd   - Identifies the operation to be performed.  Command specific
- *           arguments may follow.
- *
- * Returned Value:
- *   The nature of the return value depends on the command.  Non-negative
- *   values indicate success.  Failures are reported as negated errno
- *   values.
- *
- ****************************************************************************/
-
-int psock_fcntl(FAR struct socket *psock, int cmd, ...)
-{
-  va_list ap;
-  int ret;
-
-  /* Setup to access the variable argument list */
-
-  va_start(ap, cmd);
-
-  /* Let psock_vfcntl() do the real work.  The errno is not set on
-   * failures.
-   */
-
-  ret = psock_vfcntl(psock, cmd, ap);
-
-  va_end(ap);
-  return ret;
-}

[incubator-nuttx] 01/03: vfs: Forward fcntl(F_SETFD...) to ioctl(FIOCLEX|FIONCLEX...)

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

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

commit 19e796305ad0aa3231f88851936bdcb17ea96445
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Mar 4 11:53:57 2022 +0800

    vfs: Forward fcntl(F_SETFD...) to ioctl(FIOCLEX|FIONCLEX...)
    
    this is follow change to:
    commit 37730a1fce987b5a997ee50f4553d6b30a158543
    Author: fangzhenwei <fa...@xiaomi.com>
    Date:   Thu Nov 25 13:43:10 2021 +0800
    
        nuttx/fcntl:pass O_NONBLOCK flag to ioctl
    
        1. fix pty fcntl F_SETFL(O_NONBLOCK) fail issue
    
        Signed-off-by: fangzhenwei <fa...@xiaomi.com>
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 fs/vfs/fs_fcntl.c | 7 ++-----
 fs/vfs/fs_ioctl.c | 8 ++++----
 include/fcntl.h   | 2 +-
 3 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/fs/vfs/fs_fcntl.c b/fs/vfs/fs_fcntl.c
index aaccd4d..c6b929a 100644
--- a/fs/vfs/fs_fcntl.c
+++ b/fs/vfs/fs_fcntl.c
@@ -121,14 +121,12 @@ static int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
 
           if (oflags & FD_CLOEXEC)
             {
-              filep->f_oflags |= O_CLOEXEC;
+              ret = file_ioctl(filep, FIOCLEX, NULL);
             }
           else
             {
-              filep->f_oflags &= ~O_CLOEXEC;
+              ret = file_ioctl(filep, FIONCLEX, NULL);
             }
-
-          ret = OK;
         }
         break;
 
@@ -167,7 +165,6 @@ static int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
               oflags          &=  (FFCNTL & ~O_NONBLOCK);
               filep->f_oflags &= ~(FFCNTL & ~O_NONBLOCK);
               filep->f_oflags |=  oflags;
-              ret              =  OK;
             }
         }
         break;
diff --git a/fs/vfs/fs_ioctl.c b/fs/vfs/fs_ioctl.c
index 796cbcf..29c5ec7 100644
--- a/fs/vfs/fs_ioctl.c
+++ b/fs/vfs/fs_ioctl.c
@@ -95,13 +95,13 @@ int file_vioctl(FAR struct file *filep, int req, va_list ap)
         break;
 
       case FIOCLEX:
-        ret = file_fcntl(filep, F_SETFD,
-                         file_fcntl(filep, F_GETFD) | FD_CLOEXEC);
+        filep->f_oflags |= O_CLOEXEC;
+        ret = OK;
         break;
 
       case FIONCLEX:
-        ret = file_fcntl(filep, F_SETFD,
-                         file_fcntl(filep, F_GETFD) & ~FD_CLOEXEC);
+        filep->f_oflags &= ~O_CLOEXEC;
+        ret = OK;
         break;
 
       case FIOC_FILEPATH:
diff --git a/include/fcntl.h b/include/fcntl.h
index 2b1de82..9cef7ed 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -103,7 +103,7 @@
 #define F_WRLCK     1  /* Take out a write lease */
 #define F_UNLCK     2  /* Remove a lease */
 
-/* close-on-exec flag for F_GETRL and F_SETFL */
+/* close-on-exec flag for F_GETFD and F_SETFD */
 
 #define FD_CLOEXEC  1
 

[incubator-nuttx] 03/03: fs/aio: Don't include include/nuttx/net/net.h

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

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

commit b3b48a658ff944e0b9186119b720f001aa468ca9
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Mar 5 01:20:46 2022 +0800

    fs/aio: Don't include include/nuttx/net/net.h
    
    since it isn't really used
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 fs/aio/aio.h          | 1 -
 fs/aio/aio_read.c     | 1 -
 fs/aio/aioc_contain.c | 1 -
 3 files changed, 3 deletions(-)

diff --git a/fs/aio/aio.h b/fs/aio/aio.h
index 509d11a..00ca9e7 100644
--- a/fs/aio/aio.h
+++ b/fs/aio/aio.h
@@ -33,7 +33,6 @@
 #include <queue.h>
 
 #include <nuttx/wqueue.h>
-#include <nuttx/net/net.h>
 
 #ifdef CONFIG_FS_AIO
 
diff --git a/fs/aio/aio_read.c b/fs/aio/aio_read.c
index dad4f0c..28f79ac 100644
--- a/fs/aio/aio_read.c
+++ b/fs/aio/aio_read.c
@@ -32,7 +32,6 @@
 #include <debug.h>
 
 #include <nuttx/fs/fs.h>
-#include <nuttx/net/net.h>
 
 #include "aio/aio.h"
 
diff --git a/fs/aio/aioc_contain.c b/fs/aio/aioc_contain.c
index a40a986..fee268d 100644
--- a/fs/aio/aioc_contain.c
+++ b/fs/aio/aioc_contain.c
@@ -30,7 +30,6 @@
 
 #include <nuttx/sched.h>
 #include <nuttx/fs/fs.h>
-#include <nuttx/net/net.h>
 
 #include "aio/aio.h"