You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc < 2) {
exit(1);
}
int result = lseek(atoi(argv[1]), 0, SEEK_SET);
printf("checkfd result = %d\n", result);
}
To test:
# cc fdcloexec.c -o fdcloexec
# cc checkfd.c -o checkfd
# ./fdcloexec
mydupfd = 4
checkfd result = -1
The first program opens a file and passes that file number as an argument to the checkfd program which it executes with system.
If F_DUPFD_CLOEXEC is used to duplicate the file number then the checkfd result should be -1. This indicates the file number passed to checkfd was closed when the program checkfd was executed.
If a plain F_DUPFD is used the checkfd result will be 0.
A PR is forthcoming which implements the F_DUPFD_CLOEXEC option.
Activity
mikaku commentedon Aug 16, 2023
Looks good to me.
Thank you.