Skip to content

Instantly share code, notes, and snippets.

@alanc
Created August 4, 2024 18:17
Show Gist options
  • Save alanc/1d626c41350b864bda6c639ff9a7589b to your computer and use it in GitHub Desktop.
Save alanc/1d626c41350b864bda6c639ff9a7589b to your computer and use it in GitHub Desktop.
Test to see if FD_CLOFORK persists across exec calls on Solaris 11.4
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main(void) {
int fd;
char pidbuf[16];
fd = open("/etc/motd", O_RDONLY | O_CLOFORK);
snprintf(pidbuf, sizeof(pidbuf), "%ld", getpid());
execl("/usr/bin/pfiles", "pfiles", pidbuf, NULL);
}
23872: pfiles 23872
Current rlimit: 4095 file descriptors
Current umask: 022
0: S_IFCHR mode:0620 dev:16377,0 ino:65866307 uid:50758 gid:7 rdev:151,13
O_RDWR|O_LARGEFILE
/dev/pts/13
1: S_IFCHR mode:0620 dev:16377,0 ino:65866307 uid:50758 gid:7 rdev:151,13
O_RDWR|O_LARGEFILE
/dev/pts/13
2: S_IFCHR mode:0620 dev:16377,0 ino:65866307 uid:50758 gid:7 rdev:151,13
O_RDWR|O_LARGEFILE
/dev/pts/13
3: S_IFREG mode:0644 dev:231,65538 ino:691743 uid:0 gid:0 size:0
O_RDONLY FD_CLOFORK
/etc/motd
offset:0
4: S_IFDIR mode:0500 dev:16380,0 ino:14508 uid:50758 gid:10 size:4112
O_RDONLY|O_NDELAY|O_LARGEFILE FD_CLOEXEC
/proc/23872/fdinfo
offset:112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment