mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-11 06:20:23 +02:00
(scm_ttyname): Use scm_i_misc_mutex for thread safety.
This commit is contained in:
parent
8d20b7af9e
commit
e8a590639c
1 changed files with 23 additions and 4 deletions
|
@ -768,6 +768,15 @@ SCM_DEFINE (scm_setsid, "setsid", 0, 0, 0,
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
#endif /* HAVE_SETSID */
|
#endif /* HAVE_SETSID */
|
||||||
|
|
||||||
|
|
||||||
|
/* ttyname returns its result in a single static buffer, hence
|
||||||
|
scm_i_misc_mutex for thread safety. In glibc 2.3.2 two threads
|
||||||
|
continuously calling ttyname will otherwise get an overwrite quite
|
||||||
|
easily.
|
||||||
|
|
||||||
|
ttyname_r (when available) could be used instead of scm_i_misc_mutex, but
|
||||||
|
there's probably little to be gained in either speed or parallelism. */
|
||||||
|
|
||||||
#ifdef HAVE_TTYNAME
|
#ifdef HAVE_TTYNAME
|
||||||
SCM_DEFINE (scm_ttyname, "ttyname", 1, 0, 0,
|
SCM_DEFINE (scm_ttyname, "ttyname", 1, 0, 0,
|
||||||
(SCM port),
|
(SCM port),
|
||||||
|
@ -776,22 +785,32 @@ SCM_DEFINE (scm_ttyname, "ttyname", 1, 0, 0,
|
||||||
#define FUNC_NAME s_scm_ttyname
|
#define FUNC_NAME s_scm_ttyname
|
||||||
{
|
{
|
||||||
char *result;
|
char *result;
|
||||||
int fd;
|
int fd, err;
|
||||||
|
SCM ret;
|
||||||
|
|
||||||
port = SCM_COERCE_OUTPORT (port);
|
port = SCM_COERCE_OUTPORT (port);
|
||||||
SCM_VALIDATE_OPPORT (1, port);
|
SCM_VALIDATE_OPPORT (1, port);
|
||||||
if (!SCM_FPORTP (port))
|
if (!SCM_FPORTP (port))
|
||||||
return SCM_BOOL_F;
|
return SCM_BOOL_F;
|
||||||
fd = SCM_FPORT_FDES (port);
|
fd = SCM_FPORT_FDES (port);
|
||||||
|
|
||||||
|
scm_mutex_lock (&scm_i_misc_mutex);
|
||||||
SCM_SYSCALL (result = ttyname (fd));
|
SCM_SYSCALL (result = ttyname (fd));
|
||||||
|
err = errno;
|
||||||
|
ret = scm_makfrom0str (result);
|
||||||
|
scm_mutex_unlock (&scm_i_misc_mutex);
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
SCM_SYSERROR;
|
{
|
||||||
/* result could be overwritten by another call to ttyname */
|
errno = err;
|
||||||
return (scm_makfrom0str (result));
|
SCM_SYSERROR;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
#endif /* HAVE_TTYNAME */
|
#endif /* HAVE_TTYNAME */
|
||||||
|
|
||||||
|
|
||||||
/* For thread safety "buf" is used instead of NULL for the ctermid static
|
/* For thread safety "buf" is used instead of NULL for the ctermid static
|
||||||
buffer. Actually it's unlikely the controlling terminal will change
|
buffer. Actually it's unlikely the controlling terminal will change
|
||||||
during program execution, and indeed on glibc (2.3.2) it's always just
|
during program execution, and indeed on glibc (2.3.2) it's always just
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue