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

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

commit 253f1d40c3a98956f066450c07b263bfe681e14a
Author: wangjianyu3 <[email protected]>
AuthorDate: Thu Jun 25 16:00:10 2026 +0800

    netutils/rexecd: use dpopen() instead of popen() to get raw fd
    
    popen() now returns a fopencookie-backed FILE* whose fileno() yields the
    cookie pointer rather than a real descriptor, so poll() silently ignores
    the negative fd and the relay loop blocks forever waiting for command
    completion. See https://github.com/apache/nuttx-apps/pull/3511
    
    Use dpopen()/dpclose() to obtain the raw bidirectional socket descriptor
    directly, restoring the EOF/POLLHUP command-completion signal.
    
    Assisted-by: GitHubCopilot:claude-4.8-opus
    Signed-off-by: wangjianyu3 <[email protected]>
---
 netutils/rexecd/rexecd.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/netutils/rexecd/rexecd.c b/netutils/rexecd/rexecd.c
index 6c238d586..13864a841 100644
--- a/netutils/rexecd/rexecd.c
+++ b/netutils/rexecd/rexecd.c
@@ -25,9 +25,11 @@
  ****************************************************************************/
 
 #include <errno.h>
+#include <fcntl.h>
 #include <netdb.h>
 #include <pthread.h>
 #include <netpacket/rpmsg.h>
+#include <sys/socket.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -84,7 +86,7 @@ static FAR void *doit(pthread_addr_t pvarg)
 {
   char buf[REXECD_BUFSIZE];
   struct pollfd fds[2];
-  FAR FILE *fp;
+  pid_t pid;
   int sock = (long)pvarg;
   int ret;
 
@@ -97,18 +99,18 @@ static FAR void *doit(pthread_addr_t pvarg)
   /* we need to read command */
 
   getstr(sock, buf);
-  fp = popen(buf, "r+");
-  if (!fp)
-    {
-      goto errout;
-    }
 
   memset(fds, 0, sizeof(fds));
-  fds[0].fd = fileno(fp);
   fds[0].events = POLLIN;
   fds[1].fd = sock;
   fds[1].events = POLLIN;
 
+  fds[0].fd = dpopen(buf, O_RDWR, &pid);
+  if (fds[0].fd < 0)
+    {
+      goto errout;
+    }
+
   while (1)
     {
       ret = poll(fds, 2, -1);
@@ -119,7 +121,7 @@ static FAR void *doit(pthread_addr_t pvarg)
 
       if (fds[0].revents & POLLIN)
         {
-          ret = read(fileno(fp), buf, REXECD_BUFSIZE);
+          ret = read(fds[0].fd, buf, REXECD_BUFSIZE);
           if (ret <= 0)
             {
               break;
@@ -140,7 +142,7 @@ static FAR void *doit(pthread_addr_t pvarg)
               break;
             }
 
-          ret = write(fileno(fp), buf, ret);
+          ret = write(fds[0].fd, buf, ret);
           if (ret < 0)
             {
               break;
@@ -154,7 +156,7 @@ static FAR void *doit(pthread_addr_t pvarg)
         }
     }
 
-  pclose(fp);
+  dpclose(fds[0].fd, pid);
 errout:
   close(sock);
   return NULL;

Reply via email to