From beae9c3c433876e542f37913eeac97bcf19b25d0 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Mon, 29 Nov 2021 17:32:37 -0600 Subject: [PATCH] roken: Use ptsname_r() if we have it --- configure.ac | 2 +- include/config.h.w32 | 3 --- lib/roken/rkpty.c | 13 ++++++++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index e1d2aa90f..a53131fd5 100644 --- a/configure.ac +++ b/configure.ac @@ -529,7 +529,7 @@ AC_CHECK_FUNCS([ \ getresgid \ getresuid \ grantpt \ - ptsname \ + ptsname_r \ rand \ setitimer \ setregid \ diff --git a/include/config.h.w32 b/include/config.h.w32 index 644378420..658388079 100644 --- a/include/config.h.w32 +++ b/include/config.h.w32 @@ -694,9 +694,6 @@ static const char *const rcsid[] = { (const char *)rcsid, "@(#)" msg } /* This option is added by the NTMakefile if we have a . */ /* #define HAVE_PTHREAD_H 1 */ -/* Define to 1 if you have the `ptsname' function. */ -/* #define HAVE_PTSNAME 1 */ - /* Define to 1 if you have the header file. */ /* #define HAVE_PTY_H 1 */ diff --git a/lib/roken/rkpty.c b/lib/roken/rkpty.c index 619b7b639..f7bfacabe 100644 --- a/lib/roken/rkpty.c +++ b/lib/roken/rkpty.c @@ -123,7 +123,18 @@ open_pty(void) #ifdef HAVE_UNLOCKPT unlockpt(master); #endif - strlcpy(line, ptsname(master), sizeof(line)); +#ifdef HAVE_PTSNAME_R + if (ptsname_r(master, line, sizeof(line)) == -1) + err("Failed to open the pty master %s", *q); +#else + { + char *s = ptsname(master); + + if (s == NULL) + err("Failed to open the pty master %s", *q); + strlcpy(line, s, sizeof(line)); + } +#endif slave = open(line, O_RDWR); if (slave < 0) errx(1, "failed to open slave when using %s", *q);