PTY(3) Introduction to Library Functions PTY(3)

NAME

openpty, forkptyauxiliary functions to obtain a pseudo-terminal

SYNOPSIS

#include <pty.h>

int
openpty(int *amaster, int *aslave, char *name, const struct termios *termp, const struct winsize *winp);

int
forkpty(int *amaster, char *name, const struct termios *termp, const struct winsize *winp);

DESCRIPTION

The function openpty() attempts to obtain the next available pseudo-terminal from the system. If it successfully finds one, it subsequently changes the ownership of the slave device to the real UID of the current process, the group membership to the group “tty” (if such a group exists in the system), the access permissions for reading and writing by the owner, and for writing by the group.

If the argument name is not NULL, the filename of the slave is returned in name.

If the arguments termp or winp are not NULL, openpty() initializes the termios and window size settings from the structures these arguments point to, respectively.

Upon return, the open file descriptors for the master and slave side of the pty are returned in the locations pointed to by amaster and aslave, respectively.

The forkpty() function first calls openpty() to obtain the next available pseudo-terminal from the system. Upon success, it forks off a new process. In the child process, it closes the descriptor for the master side of the pty, and calls login_tty(3) for the slave pty. In the parent process, it closes the descriptor for the slave side of the pty. The arguments amaster, name, termp, and winp have the same meaning as described for openpty().

RETURN VALUES

If a call to openpty() or forkpty() is not successful, -1 is returned and errno is set to indicate the error. Otherwise, openpty() and the child process of forkpty() return 0, and the parent process of forkpty() returns the process ID of the child process.

ERRORS

The openpty() function may fail and set the global variable errno for any of the errors specified for the open(2,) grantpt(3), unlockpt(3,) ptsname(3), ioctl(2), and tcsetattr(3) functions.

In addition to this, forkpty() may set it to any value as described for fork(2).

INTERFACE STABILITY

Comitted

MT-LEVEL

MT-Safe

SEE ALSO

chmod(2), chown(2), fork(2), getuid(2), open(2), login_tty(3), termios(3), group(4)
October 10, 2015 NexentaStor