1
Fork 0
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:
Ludovic Courtès 2008-11-30 18:43:41 +01:00
parent 9b36a80c79
commit 634aa8de8f
5 changed files with 31 additions and 12 deletions

View file

@ -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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -41,6 +41,8 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <full-write.h>
/* {Asynchronous Events} /* {Asynchronous Events}
* *
@ -241,13 +243,13 @@ scm_i_queue_async_cell (SCM c, scm_i_thread *t)
if (sleep_fd >= 0) if (sleep_fd >= 0)
{ {
char dummy = 0; char dummy = 0;
/* Likewise, T might already been done with sleeping here, but /* Likewise, T might already been done with sleeping here, but
interrupting it once too often does no harm. T might also interrupting it once too often does no harm. T might also
not yet have started sleeping, but this is no problem either not yet have started sleeping, but this is no problem either
since the data written to a pipe will not be lost, unlike a since the data written to a pipe will not be lost, unlike a
condition variable signal. condition variable signal. */
*/ full_write (sleep_fd, &dummy, 1);
write (sleep_fd, &dummy, 1);
} }
/* This is needed to protect sleep_mutex. /* This is needed to protect sleep_mutex.

View file

@ -59,6 +59,8 @@
# include <winsock2.h> # include <winsock2.h>
#endif /* __MINGW32__ */ #endif /* __MINGW32__ */
#include <full-write.h>
/* Mingw (version 3.4.5, circa 2006) has ftruncate as an alias for chsize /* 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, already, but have this code here in case that wasn't so in past versions,
or perhaps to help other minimal DOS environments. 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 "; const char *msg = "Error: could not flush file-descriptor ";
char buf[11]; char buf[11];
write (2, msg, strlen (msg)); full_write (2, msg, strlen (msg));
sprintf (buf, "%d\n", fp->fdes); sprintf (buf, "%d\n", fp->fdes);
write (2, buf, strlen (buf)); full_write (2, buf, strlen (buf));
count = remaining; count = remaining;
} }

View file

@ -277,7 +277,7 @@ SCM_DEFINE (scm_getgroups, "getgroups", 0, 0, 0,
size = ngroups * sizeof (GETGROUPS_T); size = ngroups * sizeof (GETGROUPS_T);
groups = scm_malloc (size); groups = scm_malloc (size);
getgroups (ngroups, groups); ngroups = getgroups (ngroups, groups);
result = scm_c_make_vector (ngroups, SCM_BOOL_F); result = scm_c_make_vector (ngroups, SCM_BOOL_F);
while (--ngroups >= 0) while (--ngroups >= 0)
@ -1563,12 +1563,15 @@ SCM_DEFINE (scm_nice, "nice", 1, 0, 0,
"The return value is unspecified.") "The return value is unspecified.")
#define FUNC_NAME s_scm_nice #define FUNC_NAME s_scm_nice
{ {
int nice_value;
/* nice() returns "prio-NZERO" on success or -1 on error, but -1 can arise /* 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 */ from "prio-NZERO", so an error must be detected from errno changed */
errno = 0; errno = 0;
nice (scm_to_int (incr)); nice_value = nice (scm_to_int (incr));
if (errno != 0) if (errno != 0)
SCM_SYSERROR; SCM_SYSERROR;
return SCM_UNSPECIFIED; return SCM_UNSPECIFIED;
} }
#undef FUNC_NAME #undef FUNC_NAME

View file

@ -63,6 +63,9 @@
#define pipe(fd) _pipe (fd, 256, O_BINARY) #define pipe(fd) _pipe (fd, 256, O_BINARY)
#endif #endif
#include <full-write.h>
/* SIGRETTYPE is the type that signal handlers return. See <signal.h> */ /* SIGRETTYPE is the type that signal handlers return. See <signal.h> */
@ -137,7 +140,7 @@ static SIGRETTYPE
take_signal (int signum) take_signal (int signum)
{ {
char sigbyte = signum; char sigbyte = signum;
write (signal_pipe[1], &sigbyte, 1); full_write (signal_pipe[1], &sigbyte, 1);
#ifndef HAVE_SIGACTION #ifndef HAVE_SIGACTION
signal (signum, take_signal); signal (signum, take_signal);

View file

@ -61,6 +61,9 @@
# define pipe(fd) _pipe (fd, 256, O_BINARY) # define pipe(fd) _pipe (fd, 256, O_BINARY)
#endif /* __MINGW32__ */ #endif /* __MINGW32__ */
#include <full-read.h>
static void static void
to_timespec (SCM t, scm_t_timespec *waittime) to_timespec (SCM t, scm_t_timespec *waittime)
{ {
@ -480,8 +483,13 @@ guilify_self_1 (SCM_STACKITEM *base)
t->sleep_mutex = NULL; t->sleep_mutex = NULL;
t->sleep_object = SCM_BOOL_F; t->sleep_object = SCM_BOOL_F;
t->sleep_fd = -1; 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->heap_mutex, NULL);
scm_i_pthread_mutex_init (&t->admin_mutex, NULL); scm_i_pthread_mutex_init (&t->admin_mutex, NULL);
t->clear_freelists_p = 0; t->clear_freelists_p = 0;
@ -1776,7 +1784,8 @@ scm_std_select (int nfds,
if (res > 0 && FD_ISSET (wakeup_fd, readfds)) if (res > 0 && FD_ISSET (wakeup_fd, readfds))
{ {
char dummy; char dummy;
read (wakeup_fd, &dummy, 1); full_read (wakeup_fd, &dummy, 1);
FD_CLR (wakeup_fd, readfds); FD_CLR (wakeup_fd, readfds);
res -= 1; res -= 1;
if (res == 0) if (res == 0)