Branch: Tag:

2013-11-13

2013-11-13 16:59:56 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Stdio.File: Fix grantpt() on Solaris (and others?)

grantpt(3C) on Solaris is implemented as fork + exec of
"/usr/lib/pt_chmod". Unfortunately the libc function doesn't bother
clearing the FD_CLOEXEC flag before the exec, so the fd never got
to the helper binary, which caused grantpt(3C) to fail with EPERM.

2465:    *! filename of the associated pts-file. This function should only be    *! called once.    *! +  *! @returns +  *! Returns the filename of the corresponding pts. +  *!    *! @note    *! This function is only available on some platforms.    */
2512:    }    pop_n_elems(3);   #else /* HAVE_GRANTPT */ +  /* Make sure the fd doesn't get closed when it gets sent +  * to the subprocess (aka /usr/lib/pt_chmod). +  */ +  set_close_on_exec(FD, 0);    if( grantpt( FD ) )    Pike_error("grantpt failed: %s\n", strerror(errno)); -  +  set_close_on_exec(FD, 1);   #endif /* USE_PT_CHMOD || USE_CHGPT */    push_text( ptsname( FD ) );   #ifdef HAVE_UNLOCKPT