hujun260 commented on PR #9497:
URL: https://github.com/apache/nuttx/pull/9497#issuecomment-1600325164

   > @hujun260 Here is what I think it happens:
   > 
   > 1. `select()` is called, and uses `fdcheck_restore()`.
   > 2. `select()` is calling `poll()` internally.
   > 3. `poll()` calls `poll_setup()`.
   > 4. `poll_setup()` calls `poll_fdsetup()`.
   > 5. `poll_fdsetup()` calls `fs_getfilep()` before `file_poll()`.
   > 6. `fs_getfilep()` calls _again_ `fdcheck_restore()` on an already 
restored file descriptor.
   > 
   > I added prints, and I verified that the error originates 
[here](https://github.com/apache/nuttx/blob/master/fs/inode/fs_files.c#L469) 
(following the above sequence).
   > 
   > The actual error is `EBADF` (no idea why `errno` contained garbage).
   
   I have written some test code and it seems to be fine. 
   Can you provide a complete and runnable test code so that I can reproduce 
it? for example
   
           int fd = open("/dev/null", O_WRONLY);
           int rc;
           fd_set w_set;
           FD_ZERO(&w_set);
           FD_SET(fd, &w_set);
   
           if ((rc = select(fd + 1, NULL, &w_set, NULL, NULL)) == -1) {
               printf("error  %d\n", rc);
               close(fd);
               goto end;
           }
           if (rc == 0) {  // we had a timeout
               printf("timeout\n");
               close(fd);
               goto end;
           }
   
           if (FD_ISSET(fd, &w_set)) {
               int len = write(fd, "test",4);
               printf("writeok %d\n", len);
               close(fd);
               goto end;
           } else {
               printf("faild %d\n", rc);
               close(fd);
               goto end;
           }


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to