[pty] Support ptsname_r
of glibc
Although glibc `ptsname_r` man page mentions Tru64 and HP-UX, this function appears to be declared obsolete on both.
This commit is contained in:
parent
1b830740ba
commit
e7f8db9079
@ -16,6 +16,7 @@ if /mswin|mingw|bccwin/ !~ RUBY_PLATFORM
|
|||||||
if have_func("posix_openpt") or
|
if have_func("posix_openpt") or
|
||||||
(util or have_func("openpty")) or
|
(util or have_func("openpty")) or
|
||||||
have_func("_getpty") or
|
have_func("_getpty") or
|
||||||
|
have_func("ptsname_r") or
|
||||||
have_func("ptsname") or
|
have_func("ptsname") or
|
||||||
have_func("ioctl")
|
have_func("ioctl")
|
||||||
create_makefile('pty')
|
create_makefile('pty')
|
||||||
|
@ -256,7 +256,21 @@ establishShell(int argc, VALUE *argv, struct pty_info *info,
|
|||||||
RB_GC_GUARD(carg.execarg_obj);
|
RB_GC_GUARD(carg.execarg_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_POSIX_OPENPT) || defined(HAVE_OPENPTY) || defined(HAVE_PTSNAME)
|
#if defined(HAVE_PTSNAME) && !defined(HAVE_PTSNAME_R)
|
||||||
|
/* glibc only, not obsolete interface on Tru64 or HP-UX */
|
||||||
|
static int
|
||||||
|
ptsname_r(int fd, char *buf, size_t buflen)
|
||||||
|
{
|
||||||
|
extern char *ptsname(int);
|
||||||
|
char *name = ptsname(fd);
|
||||||
|
if (!name) return -1;
|
||||||
|
strlcpy(buf, name, buflen);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
# define HAVE_PTSNAME_R 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_POSIX_OPENPT) || defined(HAVE_OPENPTY) || defined(HAVE_PTSNAME_R)
|
||||||
static int
|
static int
|
||||||
no_mesg(char *slavedevice, int nomesg)
|
no_mesg(char *slavedevice, int nomesg)
|
||||||
{
|
{
|
||||||
@ -320,7 +334,8 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|||||||
#endif
|
#endif
|
||||||
if (sigaction(SIGCHLD, &old, NULL) == -1) goto error;
|
if (sigaction(SIGCHLD, &old, NULL) == -1) goto error;
|
||||||
if (unlockpt(masterfd) == -1) goto error;
|
if (unlockpt(masterfd) == -1) goto error;
|
||||||
if ((slavedevice = ptsname(masterfd)) == NULL) goto error;
|
if (ptsname_r(masterfd, SlaveName, DEVICELEN) != 0) goto error;
|
||||||
|
slavedevice = SlaveName;
|
||||||
if (no_mesg(slavedevice, nomesg) == -1) goto error;
|
if (no_mesg(slavedevice, nomesg) == -1) goto error;
|
||||||
if ((slavefd = rb_cloexec_open(slavedevice, O_RDWR|O_NOCTTY, 0)) == -1) goto error;
|
if ((slavefd = rb_cloexec_open(slavedevice, O_RDWR|O_NOCTTY, 0)) == -1) goto error;
|
||||||
rb_update_max_fd(slavefd);
|
rb_update_max_fd(slavefd);
|
||||||
@ -333,7 +348,6 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|||||||
|
|
||||||
*master = masterfd;
|
*master = masterfd;
|
||||||
*slave = slavefd;
|
*slave = slavefd;
|
||||||
strlcpy(SlaveName, slavedevice, DEVICELEN);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
grantpt_error:
|
grantpt_error:
|
||||||
@ -387,7 +401,6 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|||||||
char *slavedevice;
|
char *slavedevice;
|
||||||
void (*s)();
|
void (*s)();
|
||||||
|
|
||||||
extern char *ptsname(int);
|
|
||||||
extern int unlockpt(int);
|
extern int unlockpt(int);
|
||||||
extern int grantpt(int);
|
extern int grantpt(int);
|
||||||
|
|
||||||
@ -405,7 +418,8 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|||||||
#endif
|
#endif
|
||||||
signal(SIGCHLD, s);
|
signal(SIGCHLD, s);
|
||||||
if(unlockpt(masterfd) == -1) goto error;
|
if(unlockpt(masterfd) == -1) goto error;
|
||||||
if((slavedevice = ptsname(masterfd)) == NULL) goto error;
|
if (ptsname_r(masterfd, SlaveName, DEVICELEN) != 0) goto error;
|
||||||
|
slavedevice = SlaveName;
|
||||||
if (no_mesg(slavedevice, nomesg) == -1) goto error;
|
if (no_mesg(slavedevice, nomesg) == -1) goto error;
|
||||||
if((slavefd = rb_cloexec_open(slavedevice, O_RDWR, 0)) == -1) goto error;
|
if((slavefd = rb_cloexec_open(slavedevice, O_RDWR, 0)) == -1) goto error;
|
||||||
rb_update_max_fd(slavefd);
|
rb_update_max_fd(slavefd);
|
||||||
@ -416,7 +430,6 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|||||||
#endif
|
#endif
|
||||||
*master = masterfd;
|
*master = masterfd;
|
||||||
*slave = slavefd;
|
*slave = slavefd;
|
||||||
strlcpy(SlaveName, slavedevice, DEVICELEN);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user