提交 1421463e 编写于 作者: D Daniel P. Berrangé

util: remove use of the terms 'master' and 'slave' in PTY code

The two sides of a PTY can be referred to as primary and  secondary
TTYs.
Reviewed-by: NPeter Krempa <pkrempa@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 3f2dd4fb
...@@ -3127,20 +3127,20 @@ virFileBuildPath(const char *dir, const char *name, const char *ext) ...@@ -3127,20 +3127,20 @@ virFileBuildPath(const char *dir, const char *name, const char *ext)
return path; return path;
} }
/* Open a non-blocking master side of a pty. If ttyName is not NULL, /* Open a non-blocking primary side of a pty. If ttyName is not NULL,
* then populate it with the name of the slave. If rawmode is set, * then populate it with the name of the secondary peer. If rawmode is
* also put the master side into raw mode before returning. */ * set, also put the primary side into raw mode before returning. */
#ifndef WIN32 #ifndef WIN32
int int
virFileOpenTty(int *ttymaster, char **ttyName, int rawmode) virFileOpenTty(int *ttyprimary, char **ttyName, int rawmode)
{ {
/* XXX A word of caution - on some platforms (Solaris and HP-UX), /* XXX A word of caution - on some platforms (Solaris and HP-UX),
* additional ioctl() calls are needs after opening the slave * additional ioctl() calls are needs after opening the secondary
* before it will cause isatty() to return true. Should we make * before it will cause isatty() to return true. Should we make
* virFileOpenTty also return the opened slave fd, so the caller * virFileOpenTty also return the opened secondary fd, so the caller
* doesn't have to worry about that mess? */ * doesn't have to worry about that mess? */
int ret = -1; int ret = -1;
int slave = -1; int secondary = -1;
g_autofree char *name = NULL; g_autofree char *name = NULL;
/* Unfortunately, we can't use the name argument of openpty, since /* Unfortunately, we can't use the name argument of openpty, since
...@@ -3148,31 +3148,31 @@ virFileOpenTty(int *ttymaster, char **ttyName, int rawmode) ...@@ -3148,31 +3148,31 @@ virFileOpenTty(int *ttymaster, char **ttyName, int rawmode)
* Likewise, we can't use the termios argument: we have to use * Likewise, we can't use the termios argument: we have to use
* read-modify-write since there is no portable way to initialize * read-modify-write since there is no portable way to initialize
* a struct termios without use of tcgetattr. */ * a struct termios without use of tcgetattr. */
if (openpty(ttymaster, &slave, NULL, NULL, NULL) < 0) if (openpty(ttyprimary, &secondary, NULL, NULL, NULL) < 0)
return -1; return -1;
/* What a shame that openpty cannot atomically set FD_CLOEXEC, but /* What a shame that openpty cannot atomically set FD_CLOEXEC, but
* that using posix_openpt/grantpt/unlockpt/ptsname is not * that using posix_openpt/grantpt/unlockpt/ptsname is not
* thread-safe, and that ptsname_r is not portable. */ * thread-safe, and that ptsname_r is not portable. */
if (virSetNonBlock(*ttymaster) < 0 || if (virSetNonBlock(*ttyprimary) < 0 ||
virSetCloseExec(*ttymaster) < 0) virSetCloseExec(*ttyprimary) < 0)
goto cleanup; goto cleanup;
/* While Linux supports tcgetattr on either the master or the /* While Linux supports tcgetattr on either the primary or the
* slave, Solaris requires it to be on the slave. */ * secondary, Solaris requires it to be on the secondary. */
if (rawmode) { if (rawmode) {
struct termios ttyAttr; struct termios ttyAttr;
if (tcgetattr(slave, &ttyAttr) < 0) if (tcgetattr(secondary, &ttyAttr) < 0)
goto cleanup; goto cleanup;
cfmakeraw(&ttyAttr); cfmakeraw(&ttyAttr);
if (tcsetattr(slave, TCSADRAIN, &ttyAttr) < 0) if (tcsetattr(secondary, TCSADRAIN, &ttyAttr) < 0)
goto cleanup; goto cleanup;
} }
/* ttyname_r on the slave is required by POSIX, while ptsname_r on /* ttyname_r on the secondary is required by POSIX, while ptsname_r on
* the master is a glibc extension, and the POSIX ptsname is not * the primary is a glibc extension, and the POSIX ptsname is not
* thread-safe. Since openpty gave us both descriptors, guess * thread-safe. Since openpty gave us both descriptors, guess
* which way we will determine the name? :) */ * which way we will determine the name? :) */
if (ttyName) { if (ttyName) {
...@@ -3184,7 +3184,7 @@ virFileOpenTty(int *ttymaster, char **ttyName, int rawmode) ...@@ -3184,7 +3184,7 @@ virFileOpenTty(int *ttymaster, char **ttyName, int rawmode)
if (VIR_ALLOC_N(name, len) < 0) if (VIR_ALLOC_N(name, len) < 0)
goto cleanup; goto cleanup;
while ((rc = ttyname_r(slave, name, len)) == ERANGE) { while ((rc = ttyname_r(secondary, name, len)) == ERANGE) {
if (VIR_RESIZE_N(name, len, len, len) < 0) if (VIR_RESIZE_N(name, len, len, len) < 0)
goto cleanup; goto cleanup;
} }
...@@ -3200,14 +3200,14 @@ virFileOpenTty(int *ttymaster, char **ttyName, int rawmode) ...@@ -3200,14 +3200,14 @@ virFileOpenTty(int *ttymaster, char **ttyName, int rawmode)
cleanup: cleanup:
if (ret != 0) if (ret != 0)
VIR_FORCE_CLOSE(*ttymaster); VIR_FORCE_CLOSE(*ttyprimary);
VIR_FORCE_CLOSE(slave); VIR_FORCE_CLOSE(secondary);
return ret; return ret;
} }
#else /* WIN32 */ #else /* WIN32 */
int int
virFileOpenTty(int *ttymaster G_GNUC_UNUSED, virFileOpenTty(int *ttyprimary G_GNUC_UNUSED,
char **ttyName G_GNUC_UNUSED, char **ttyName G_GNUC_UNUSED,
int rawmode G_GNUC_UNUSED) int rawmode G_GNUC_UNUSED)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册