[mosh-devel] mosh-server stream changes

Keith Winstein keithw at MIT.EDU
Tue May 1 20:36:25 EDT 2012


I don't think we are quite guilty of this, for the reasons explained
on the issue, but I'm willing to believe we could do something better
here. Timo, why doesn't the fdopen() work on Solaris?

-Keith

On Tue, May 1, 2012 at 8:29 PM, Keegan McAllister
<mcallister.keegan at gmail.com> wrote:
> 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
>
> _______________________________________________
> 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