*/
+#include "prims.h"
#include "ux.h"
#include "uxterm.h"
#include "uxio.h"
#include "ospty.h"
-#include "prims.h"
extern int UX_terminal_control_ok (int fd);
#else
# define TRY_OPEN_PTY_MASTER_BSD 1
#endif
+
+#ifdef ENABLE_SMP
+static pthread_mutex_t mutex = MUTEX_INITIALIZER;
+# ifdef ENABLE_DEBUGGING_TOOLS
+static bool locked_p = false;
+# endif
+#endif
\f
struct terminal_state
{
void
terminal_open (Tchannel channel)
{
+ LOCK();
if (terminal_table_size != OS_channel_table_size)
{
- terminal_table_size = OS_channel_table_size;
terminal_table
= (OS_realloc (terminal_table,
(terminal_table_size
* (sizeof (struct terminal_state)))));
+ terminal_table_size = OS_channel_table_size;
}
(TERMINAL_BUFFER (channel)) = (-1);
+ UNLOCK();
get_terminal_state (channel, (& (TERMINAL_ORIGINAL_STATE (channel))));
}
#ifdef TRY_OPEN_PTY_MASTER_BSD
-static const char *
-open_pty_master_bsd (Tchannel * master_fd, const char ** master_fname)
+static int
+open_pty_master_bsd (Tchannel * master_fd, const char * master_name,
+ const char * slave_name, size_t namelen)
{
- static char master_name [24];
- static char slave_name [24];
const char * p1;
const char * p2;
int fd;
+ if (namelen < 11)
+ {
+ fprintf (stderr, "\nopen_pty_master_bsd: buffers too small\n");
+ fflush (stderr);
+ return (1);
+ }
+
for (p1 = "pqrstuvwxyzPQRST"; ((*p1) != 0); p1 += 1)
for (p2 = "0123456789abcdef"; ((*p2) != 0); p2 += 1)
{
continue;
}
MAKE_CHANNEL (fd, channel_type_unix_pty_master, (*master_fd) =);
- (*master_fname) = master_name;
- return (slave_name);
+ return (0);
}
- return (0);
+ return (1);
}
#endif /* not TRY_OPEN_PTY_MASTER_BSD */
# undef HAVE_POSIX_OPENPT
#endif
-/* Open an available pty, putting channel in (*master_fd),
- and return the file name of the pty.
- Signal error if none available. */
-
-const char *
-OS_open_pty_master (Tchannel * master_fd, const char ** master_fname)
+int
+OS_open_pty_master (Tchannel * master_fd, char * master_fname,
+ char * slave_name, size_t name_length)
{
#ifdef HAVE_GRANTPT
while (1)
{
- static char slave_name [24];
#ifdef HAVE_POSIX_OPENPT
int fd = (posix_openpt (O_RDWR | O_NOCTTY));
#else
int fd;
{
int slave_fd;
- int rc = (openpty ((&fd), (&slave_fd), slave_name, 0, 0));
+ int rc = (openpty ((&fd), (&slave_fd), 0, 0, 0));
if (rc < 0)
fd = -1;
else
#ifdef TRY_OPEN_PTY_MASTER_BSD
/* Try BSD open. This is needed for Linux which might have
Unix98 support in the library but not the kernel. */
- return (open_pty_master_bsd (master_fd, master_fname));
+ return (open_pty_master_bsd (master_fd, master_fname,
+ slave_name, name_length));
#else
- return (0);
+ return (1);
#endif
}
#ifdef sonyrisc
#endif
grantpt (fd);
unlockpt (fd);
- strcpy (slave_name, (ptsname (fd)));
+#ifdef ENABLE_SMP
+ {
+ int err = ptsname_r (fd, slave_name, name_length);
+ if (err)
+ {
+ fprintf (stderr, "\nptsname_r failed: %d (%s)\n",
+ err, strerror(errno));
+ fflush (stderr);
+ return (1);
+ }
+ }
+#else
+ {
+ char *name = ptsname (fd);
+ int len = strlen (name);
+ if (name_length < len)
+ {
+ fprintf (stderr, "\nptsname too long for buffer: %s\n", name);
+ fflush (stderr);
+ return (1);
+ }
+ strcpy (slave_name, name);
+ }
+#endif
#ifdef sonyrisc
sony_unblock_sigchld ();
#endif
MAKE_CHANNEL (fd, channel_type_unix_pty_master, (*master_fd) =);
- (*master_fname) = "/dev/ptmx";
- return (slave_name);
+ strcpy (master_fname, "/dev/ptmx");
+ return (0);
}
#else /* not HAVE_GRANTPT */
if (!OS_have_ptys_p ())
error_unimplemented_primitive ();
- return (open_pty_master_bsd (master_fd, master_fname));
+ return (open_pty_master_bsd (master_fd, master_fname,
+ slave_name, name_length));
#endif /* not HAVE_GRANTPT */
}