From: Taylor R. Campbell Date: Wed, 15 Apr 2009 13:00:32 +0000 (+0000) Subject: New function UX_prim_check_fd_errno to to be used after a system call X-Git-Tag: 20090517-FFI~39 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=f01e68533c4a22644a37784c11b1e5e559d204a1;p=mit-scheme.git New function UX_prim_check_fd_errno to to be used after a system call that creates file descriptors fails. If errno is EMFILE or ENFILE, this requests a garbage collection in case any unreferenced file descriptors can be closed. Change OS_make_pipe to call this if pipe(2) fails. New macro STD_FD_SYSTEM_CALL is like STD_UINT_SYSTEM_CALL but uses UX_prim_check_fd_errno rather than UX_prim_check_errno. Change OS_open_*_file and OS_open_*_socket to use STD_FD_SYSTEM_CALL to call open(2) and socket(2). Change STD_*_SYSTEM_CALL to use do/while rather than braces for compound statements and to call UX_prim_check_errno rather than copying it in-line. --- diff --git a/v7/src/microcode/ux.c b/v7/src/microcode/ux.c index b7488584a..cda2d9266 100644 --- a/v7/src/microcode/ux.c +++ b/v7/src/microcode/ux.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ux.c,v 1.36 2008/05/04 07:13:37 cph Exp $ +$Id: ux.c,v 1.37 2009/04/15 13:00:19 riastradh Exp $ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, @@ -40,6 +40,31 @@ UX_prim_check_errno (enum syscall_names name) deliver_pending_interrupts (); } +void +UX_prim_check_fd_errno (enum syscall_names name) +{ + static bool out_of_files_p = false; + switch (errno) + { + case EINTR: + deliver_pending_interrupts (); + break; + + case EMFILE: + case ENFILE: + if (!out_of_files_p) + { + out_of_files_p = true; + REQUEST_GC (0); + deliver_pending_interrupts (); + } + /* Fall through */ + + default: + error_system_call (errno, name); + } +} + #ifdef HAVE_TERMIOS_H int diff --git a/v7/src/microcode/ux.h b/v7/src/microcode/ux.h index 34458d935..afa32cb61 100644 --- a/v7/src/microcode/ux.h +++ b/v7/src/microcode/ux.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ux.h,v 1.90 2009/03/21 07:09:09 riastradh Exp $ +$Id: ux.h,v 1.91 2009/04/15 13:00:24 riastradh Exp $ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, @@ -852,35 +852,30 @@ extern int UX_sigsuspend (const sigset_t *); #endif /* not _POSIX_VERSION */ extern void UX_prim_check_errno (enum syscall_names name); - -#define STD_VOID_SYSTEM_CALL(name, expression) \ -{ \ - while ((expression) < 0) \ - { \ - if (errno != EINTR) \ - error_system_call (errno, (name)); \ - deliver_pending_interrupts (); \ - } \ -} - -#define STD_UINT_SYSTEM_CALL(name, result, expression) \ -{ \ - while (((result) = (expression)) < 0) \ - { \ - if (errno != EINTR) \ - error_system_call (errno, (name)); \ - deliver_pending_interrupts (); \ - } \ -} - -#define STD_PTR_SYSTEM_CALL(name, result, expression) \ -{ \ - while (((result) = (expression)) == 0) \ - { \ - if (errno != EINTR) \ - error_system_call (errno, (name)); \ - deliver_pending_interrupts (); \ - } \ -} +extern void UX_prim_check_fd_errno (enum syscall_names name); + +#define STD_VOID_SYSTEM_CALL(name, expression) \ + do { \ + while ((expression) < 0) \ + UX_prim_check_errno (name); \ + } while (0) + +#define STD_UINT_SYSTEM_CALL(name, result, expression) \ + do { \ + while (((result) = (expression)) < 0) \ + UX_prim_check_errno (name); \ + } while (0) + +#define STD_PTR_SYSTEM_CALL(name, result, expression) \ + do { \ + while (((result) = (expression)) == 0) \ + UX_prim_check_errno (name); \ + } while (0) + +#define STD_FD_SYSTEM_CALL(name, result, expression) \ + do { \ + while (((result) = (expression)) < 0) \ + UX_prim_check_fd_errno (name); \ + } while (0) #endif /* SCM_UX_H */ diff --git a/v7/src/microcode/uxfile.c b/v7/src/microcode/uxfile.c index c7c81f206..d761ad17a 100644 --- a/v7/src/microcode/uxfile.c +++ b/v7/src/microcode/uxfile.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: uxfile.c,v 1.19 2009/04/15 03:02:48 riastradh Exp $ +$Id: uxfile.c,v 1.20 2009/04/15 13:00:29 riastradh Exp $ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, @@ -68,35 +68,12 @@ OS_open_fd (int fd) terminal_open (channel); return (channel); } - + static Tchannel open_file (const char * filename, int oflag) { - static bool out_of_files_p = false; int fd; - while ((fd = (UX_open (filename, oflag, MODE_REG))) < 0) - { - switch (errno) - { - case EINTR: - deliver_pending_interrupts (); - break; - - case EMFILE: - case ENFILE: - if (!out_of_files_p) - { - out_of_files_p = true; - REQUEST_GC (0); - signal_interrupt_from_primitive (); - } - /* Fall through. */ - - default: - error_system_call (errno, syscall_open); - } - } - out_of_files_p = false; + STD_FD_SYSTEM_CALL (syscall_open, fd, (UX_open (filename, oflag, MODE_REG))); #ifdef SLAVE_PTY_P if ((SLAVE_PTY_P (filename)) && (!UX_setup_slave_pty (fd))) { diff --git a/v7/src/microcode/uxio.c b/v7/src/microcode/uxio.c index 64e19e967..61de04d21 100644 --- a/v7/src/microcode/uxio.c +++ b/v7/src/microcode/uxio.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: uxio.c,v 1.63 2009/03/21 21:23:22 riastradh Exp $ +$Id: uxio.c,v 1.64 2009/04/15 13:00:32 riastradh Exp $ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, @@ -333,7 +333,8 @@ OS_make_pipe (Tchannel * readerp, Tchannel * writerp) { int pv [2]; transaction_begin (); - STD_VOID_SYSTEM_CALL (syscall_pipe, (UX_pipe (pv))); + while ((UX_pipe (pv)) < 0) + UX_prim_check_fd_errno (syscall_pipe); MAKE_CHANNEL ((pv[0]), channel_type_unix_pipe, (*readerp) =); OS_channel_close_on_abort (*readerp); MAKE_CHANNEL ((pv[1]), channel_type_unix_pipe, (*writerp) =); diff --git a/v7/src/microcode/uxsock.c b/v7/src/microcode/uxsock.c index d37ff8612..2cc2b2401 100644 --- a/v7/src/microcode/uxsock.c +++ b/v7/src/microcode/uxsock.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: uxsock.c,v 1.37 2008/01/30 20:02:22 cph Exp $ +$Id: uxsock.c,v 1.38 2009/04/15 13:00:32 riastradh Exp $ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, @@ -43,7 +43,7 @@ OS_open_tcp_stream_socket (void * host, unsigned int port) Tchannel channel; transaction_begin (); - STD_UINT_SYSTEM_CALL + STD_FD_SYSTEM_CALL (syscall_socket, s, (UX_socket (AF_INET, SOCK_STREAM, 0))); MAKE_CHANNEL (s, channel_type_tcp_stream_socket, channel =); OS_channel_close_on_abort (channel); @@ -229,7 +229,7 @@ OS_open_unix_stream_socket (const char * filename) Tchannel channel; transaction_begin (); - STD_UINT_SYSTEM_CALL + STD_FD_SYSTEM_CALL (syscall_socket, s, (UX_socket (AF_UNIX, SOCK_STREAM, 0))); MAKE_CHANNEL (s, channel_type_unix_stream_socket, channel =); OS_channel_close_on_abort (channel); @@ -248,7 +248,7 @@ Tchannel OS_create_tcp_server_socket (void) { int s; - STD_UINT_SYSTEM_CALL + STD_FD_SYSTEM_CALL (syscall_socket, s, (UX_socket (AF_INET, SOCK_STREAM, 0))); MAKE_CHANNEL (s, channel_type_tcp_server_socket, return); }