Issue created by Sang Woo Kim: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/work_items/5667



## Summary

`vfcntl()` in `cpukit/libcsupport/src/fcntl.c` has no `case F_DUPFD_CLOEXEC`, 
so the command falls through to `default:` and answers -1 with `EINVAL`. POSIX 
has required it since 2008 and newlib declares it. Present on `6` and `main`.

The pieces are already there — `F_DUPFD` duplicates through `duplicate_iop()`, 
and `LIBIO_FLAGS_CLOSE_ON_EXEC` is the flag `F_GETFD`/`F_SETFD` maintain:

```c
    case F_DUPFD_CLOEXEC: /* dup, new descriptor closed by exec() */
      ret = duplicate_iop( iop );
      if ( ret >= 0 ) {
        rtems_libio_iop_flags_set(
          rtems_libio_iop( ret ),
          LIBIO_FLAGS_CLOSE_ON_EXEC
        );
      }
      break;
```

With that in place, `fcntl(fd, F_DUPFD_CLOEXEC, 0)` succeeds and `F_GETFD` on 
the result reads 1, on arm/xilinx_zynq_a9_qemu for both `6` and `main`. Found 
while working on rtems-libbsd#101.

## Steps to reproduce

```c
int fd = open("/dev/console", O_RDWR);
int d  = fcntl(fd, F_DUPFD_CLOEXEC, 0);   /* -1, errno == EINVAL */
```

-- 
View it on GitLab: https://gitlab.rtems.org/rtems/rtos/rtems/-/work_items/5667
You're receiving this email because of your account on gitlab.rtems.org. 
Unsubscribe from this thread: 
https://gitlab.rtems.org/-/sent_notifications/4-02e9081xeoem6rzng2o03izxe-1d/unsubscribe
 | Manage all notifications: https://gitlab.rtems.org/-/profile/notifications | 
Help: https://gitlab.rtems.org/help


_______________________________________________
bugs mailing list
[email protected]
http://lists.rtems.org/mailman/listinfo/bugs

Reply via email to