STDIN dup2 for OpenBSD/NetBSD

42 Views Asked by At

I have a child using dup2:

    case OPGAME:
     users[userid]->userNextEntry = redirectuser( userid, 0, USERMODULES[MENU] );
     pid = fork();
     if ( pid == -1 )
      parseerror( SYSTEMERROR );
     users[userid]->userChildPID = pid;
     if ( pid == 0 ) { // child
      dup2( users[userid]->userFD, STDIN_FILENO );
      dup2( users[userid]->userFD, STDOUT_FILENO );
      dup2( users[userid]->userFD, STDERR_FILENO );
      execl( GAMEPLAYER, GAMEPLAYER, game, (char *)NULL );
     }
    break;

This directs a TCP/IP fd to the first 3 file descriptors, it's used to launch a game over telnet.

All is well with the code, runs as it should on every Linux distro I've tried, except when compiled with OpenBSD/NETBSD.

There, the new STDIN_FILENO receives a constant new line, or a FD_ISSET internal call.

I tried resetting STDIN to canonical input, no help. I believe that the child doesn't inherit changed termios options anyway (parent has done some changes).

Any idea would be helpful.

0

There are 0 best solutions below