[mosh-devel] mosh-server stream changes

Keegan McAllister mcallister.keegan at gmail.com
Tue May 1 20:29:52 EDT 2012


Thanks for reporting this.  I've entered it into our bugtracker here:

  https://github.com/keithw/mosh/issues/255

keegan

On Mon, Apr 30, 2012 at 6:44 PM, Timo Sirainen <tss at iki.fi> wrote:
> This is a bit dangerous:
>
>    /* Necessary to properly detach on old versions of sshd (e.g. RHEL/CentOS 5.0). */
>    fclose( stdin );
>    fclose( stdout );
>    fclose( stderr );
>
> It actually closes the 0/1/2 fds and they will be reused by whatever fds are created next. I think this code attempts to create them back:
>
>    /* reopen stdio */
>    stdin = fdopen( STDIN_FILENO, "r" );
>    stdout = fdopen( STDOUT_FILENO, "w" );
>    stderr = fdopen( STDERR_FILENO, "w" );
>
> But that doesn't work, because those fds are already closed. Reads/writes to these will just fail or will access unintended fds. Also this code doesn't compile in Solaris.
>
> A safer way to detach those fds would be to do e.g.
>
> int nullfd = open("/dev/null", O_RDWR);
> dup2(nullfd, STDIN_FILENO);
> dup2(nullfd, STDOUT_FILENO);
> dup2(nullfd, STDERR_FILENO);
>
>
> _______________________________________________
> mosh-devel mailing list
> mosh-devel at mit.edu
> http://mailman.mit.edu/mailman/listinfo/mosh-devel




More information about the mosh-devel mailing list