You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/01/09 12:45:18 UTC

[GitHub] [incubator-nuttx] Ouss4 commented on a change in pull request #2661: fs: file_dup2 shouldn't hold the file list lock

Ouss4 commented on a change in pull request #2661:
URL: https://github.com/apache/incubator-nuttx/pull/2661#discussion_r554423440



##########
File path: fs/vfs/fs_dup.c
##########
@@ -50,6 +50,47 @@
  * Public Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: file_dup
+ *
+ * Description:
+ *   Equivalent to the standard dup() function except that it
+ *   accepts a struct file instance instead of a file descriptor.
+ *
+ * Returned Value:
+ *   The new file descriptor is returned on success; a negated errno value
+ *   is returned on any failure.
+ *
+ ****************************************************************************/
+
+int file_dup(FAR struct file *filep, int minfd)
+{
+  struct file filep2;
+  int fd2;
+  int ret;
+
+  /* Let file_dup2() do the real work */
+
+  memset(&filep2, 0, sizeof(filep2));
+  ret = file_dup2(filep, &filep2);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Then allocate a new file descriptor for the inode */
+
+  fd2 = files_allocate(filep2.f_inode, filep2.f_oflags,
+                       filep2.f_pos, filep2.f_priv, minfd);
+  if (fd2 < 0)
+    {
+      file_close(&filep2);
+      return fd2;

Review comment:
       Should we be concerned if f`iles_allocate` fails at `_files_semtake` and returns other values than `EBADF` and `EMFILE`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org