mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-18 17:50:29 +02:00
Check the return value of libc's functions to make `_FORTIFY_SOURCE=2' work.
This fixes bug #24009 reported by Martin Pitt. * libguile/threads.c (guilify_self_1): Check the return value of pipe(2). (scm_std_select): Use `full_read ()' instead of `read ()' when reading from WAKEUP_FD. * libguile/async.c (scm_i_queue_async_cell): Use `full_write ()' instead of write(2) when writing to SLEEP_FD. * libguile/fports.c (fport_flush): Likewise. * libguile/posix.c (getgroups): Use the return value of getgroups(2) as NGROUPS. (scm_nice): Get the return value of nice(2) to make glibc happy. * libguile/scmsigs.c (take_signal): Use `full_write ()' instead of write(2).
This commit is contained in:
parent
9b36a80c79
commit
634aa8de8f
5 changed files with 31 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2002, 2004, 2006 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2002, 2004, 2006, 2008 Free Software Foundation, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -41,6 +41,8 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <full-write.h>
|
||||
|
||||
|
||||
/* {Asynchronous Events}
|
||||
*
|
||||
|
@ -241,13 +243,13 @@ scm_i_queue_async_cell (SCM c, scm_i_thread *t)
|
|||
if (sleep_fd >= 0)
|
||||
{
|
||||
char dummy = 0;
|
||||
|
||||
/* Likewise, T might already been done with sleeping here, but
|
||||
interrupting it once too often does no harm. T might also
|
||||
not yet have started sleeping, but this is no problem either
|
||||
since the data written to a pipe will not be lost, unlike a
|
||||
condition variable signal.
|
||||
*/
|
||||
write (sleep_fd, &dummy, 1);
|
||||
condition variable signal. */
|
||||
full_write (sleep_fd, &dummy, 1);
|
||||
}
|
||||
|
||||
/* This is needed to protect sleep_mutex.
|
||||
|
|
|
@ -59,6 +59,8 @@
|
|||
# include <winsock2.h>
|
||||
#endif /* __MINGW32__ */
|
||||
|
||||
#include <full-write.h>
|
||||
|
||||
/* Mingw (version 3.4.5, circa 2006) has ftruncate as an alias for chsize
|
||||
already, but have this code here in case that wasn't so in past versions,
|
||||
or perhaps to help other minimal DOS environments.
|
||||
|
@ -826,9 +828,9 @@ fport_flush (SCM port)
|
|||
const char *msg = "Error: could not flush file-descriptor ";
|
||||
char buf[11];
|
||||
|
||||
write (2, msg, strlen (msg));
|
||||
full_write (2, msg, strlen (msg));
|
||||
sprintf (buf, "%d\n", fp->fdes);
|
||||
write (2, buf, strlen (buf));
|
||||
full_write (2, buf, strlen (buf));
|
||||
|
||||
count = remaining;
|
||||
}
|
||||
|
|
|
@ -277,7 +277,7 @@ SCM_DEFINE (scm_getgroups, "getgroups", 0, 0, 0,
|
|||
|
||||
size = ngroups * sizeof (GETGROUPS_T);
|
||||
groups = scm_malloc (size);
|
||||
getgroups (ngroups, groups);
|
||||
ngroups = getgroups (ngroups, groups);
|
||||
|
||||
result = scm_c_make_vector (ngroups, SCM_BOOL_F);
|
||||
while (--ngroups >= 0)
|
||||
|
@ -1563,12 +1563,15 @@ SCM_DEFINE (scm_nice, "nice", 1, 0, 0,
|
|||
"The return value is unspecified.")
|
||||
#define FUNC_NAME s_scm_nice
|
||||
{
|
||||
int nice_value;
|
||||
|
||||
/* nice() returns "prio-NZERO" on success or -1 on error, but -1 can arise
|
||||
from "prio-NZERO", so an error must be detected from errno changed */
|
||||
errno = 0;
|
||||
nice (scm_to_int (incr));
|
||||
nice_value = nice (scm_to_int (incr));
|
||||
if (errno != 0)
|
||||
SCM_SYSERROR;
|
||||
|
||||
return SCM_UNSPECIFIED;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
|
|
@ -63,6 +63,9 @@
|
|||
#define pipe(fd) _pipe (fd, 256, O_BINARY)
|
||||
#endif
|
||||
|
||||
#include <full-write.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* SIGRETTYPE is the type that signal handlers return. See <signal.h> */
|
||||
|
@ -137,7 +140,7 @@ static SIGRETTYPE
|
|||
take_signal (int signum)
|
||||
{
|
||||
char sigbyte = signum;
|
||||
write (signal_pipe[1], &sigbyte, 1);
|
||||
full_write (signal_pipe[1], &sigbyte, 1);
|
||||
|
||||
#ifndef HAVE_SIGACTION
|
||||
signal (signum, take_signal);
|
||||
|
|
|
@ -61,6 +61,9 @@
|
|||
# define pipe(fd) _pipe (fd, 256, O_BINARY)
|
||||
#endif /* __MINGW32__ */
|
||||
|
||||
#include <full-read.h>
|
||||
|
||||
|
||||
static void
|
||||
to_timespec (SCM t, scm_t_timespec *waittime)
|
||||
{
|
||||
|
@ -480,8 +483,13 @@ guilify_self_1 (SCM_STACKITEM *base)
|
|||
t->sleep_mutex = NULL;
|
||||
t->sleep_object = SCM_BOOL_F;
|
||||
t->sleep_fd = -1;
|
||||
/* XXX - check for errors. */
|
||||
pipe (t->sleep_pipe);
|
||||
|
||||
if (pipe (t->sleep_pipe) != 0)
|
||||
/* FIXME: Error conditions during the initialization phase are handled
|
||||
gracelessly since public functions such as `scm_init_guile ()'
|
||||
currently have type `void'. */
|
||||
abort ();
|
||||
|
||||
scm_i_pthread_mutex_init (&t->heap_mutex, NULL);
|
||||
scm_i_pthread_mutex_init (&t->admin_mutex, NULL);
|
||||
t->clear_freelists_p = 0;
|
||||
|
@ -1776,7 +1784,8 @@ scm_std_select (int nfds,
|
|||
if (res > 0 && FD_ISSET (wakeup_fd, readfds))
|
||||
{
|
||||
char dummy;
|
||||
read (wakeup_fd, &dummy, 1);
|
||||
full_read (wakeup_fd, &dummy, 1);
|
||||
|
||||
FD_CLR (wakeup_fd, readfds);
|
||||
res -= 1;
|
||||
if (res == 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue