This doesn't do what you think it does. You are setting O_CLOEXEC on the fd for /dev/ptm (which is immediately closed), not on the pty master or slave fds. You will need to explicitly set the close-on-exec flag on the master using something like:
fcntl(ptm.cfd, F_SETFD, FD_CLOEXEC);
- todd
