Superuser/jni/su/pts.c
/**
 * watch_sigwinch_async
 *
 * After calling this function, if the application receives
 * SIGWINCH, the terminal window size will be read from 
 * "input" and set on "output".
 *
 * NOTE: This function blocks SIGWINCH and spawns a thread.
 * NOTE 2: This function must be called before any of the
 *         pump functions.
 *
 * Arguments
 * master   A file descriptor of the TTY window size to follow
 * slave    A file descriptor of the TTY window size which is
 *          to be set on SIGWINCH
 *
 * Return Value
 * on failure, -1 and errno will be set. In this case, no
 *      thread has been spawned and SIGWINCH will not be 
 *      blocked.
 * on success, 0
 */
watch_sigwinch_async
After calling this function, if the application receives
SIGWINCH, the terminal window size will be read from
"input" and set on "output".

This function blocks SIGWINCH and spawns a thread.
NOTE 2: This function must be called before any of the
pump functions.

Arguments
master   A file descriptor of the TTY window size to follow
slave    A file descriptor of the TTY window size which is
to be set on SIGWINCH

Return Value
on failure, -1 and errno will be set. In this case, no
thread has been spawned and SIGWINCH will not be
blocked.
on success, 0
watch_sigwinch_async After calling this function if the application receives SIGWINCH the terminal window size will be read from " input " and set on " output " . This function blocks SIGWINCH and spawns a thread . NOTE 2 : This function must be called before any of the pump functions . Arguments master A file descriptor of the TTY window size to follow slave A file descriptor of the TTY window size which is to be set on SIGWINCH Return Value on failure - 1 and errno will be set . In this case no thread has been spawned and SIGWINCH will not be blocked . on success 0
int watch_sigwinch_async(int master, int slave) {
    pthread_t watcher;
    int *files = (int *) malloc(sizeof(int) * 2);
    if (files == NULL) {
        return -1;
    }
    sigset_t winch;
    sigemptyset(&winch);
    sigaddset(&winch, SIGWINCH);
    if (sigprocmask(SIG_BLOCK, &winch, NULL) == -1) {
        free(files);
        return -1;
    }
    closing_time = 0;
    files[0] = master;
    files[1] = slave;
    int ret = pthread_create(&watcher, NULL, &watch_sigwinch, files);
    if (ret != 0) {
        free(files);
        errno = ret;
        return -1;
    }
    raise(SIGWINCH);
    return 0;
}
int watch_sigwinch_async ( int master , int slave ) { pthread_t watcher ; int * files = ( int * ) malloc ( sizeof ( int ) * 2 ) ; if ( files == NULL ) { return -1 ; } sigset_t winch ; sigemptyset ( & winch ) ; sigaddset ( & winch , SIGWINCH ) ; if ( sigprocmask ( SIG_BLOCK , & winch , NULL ) == -1 ) { free ( files ) ; return -1 ; } closing_time = 0 ; files [ 0 ] = master ; files [ 1 ] = slave ; int ret = pthread_create ( & watcher , NULL , & watch_sigwinch , files ) ; if ( ret != 0 ) { free ( files ) ; errno = ret ; return -1 ; } raise ( SIGWINCH ) ; return 0 ; }
watch_sigwinch_async
 After calling this function, if the application receives
 SIGWINCH, the terminal window size will be read from
 "input" and set on "output".
watch_sigwinch_async After calling this function if the application receives SIGWINCH the terminal window size will be read from " input " and set on " output " .
// Block SIGWINCH so sigwait can later receive it // Initialize some variables, then start the thread // Set the initial terminal size