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:03 UTC

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

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