mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 11:50:28 +02:00
Run the GC and retry open-file' when getting
EMFILE'.
* libguile/fports.c (scm_open_file): Run the GC and retry when getting `EMFILE'.
This commit is contained in:
parent
4c7b997519
commit
64e3a89c35
1 changed files with 22 additions and 12 deletions
|
@ -318,11 +318,9 @@ SCM_DEFINE (scm_open_file, "open-file", 2, 0, 0,
|
||||||
#define FUNC_NAME s_scm_open_file
|
#define FUNC_NAME s_scm_open_file
|
||||||
{
|
{
|
||||||
SCM port;
|
SCM port;
|
||||||
int fdes;
|
int fdes, flags = 0;
|
||||||
int flags = 0;
|
unsigned int retries;
|
||||||
char *file;
|
char *file, *md, *ptr;
|
||||||
char *md;
|
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
scm_dynwind_begin (0);
|
scm_dynwind_begin (0);
|
||||||
|
|
||||||
|
@ -367,15 +365,27 @@ SCM_DEFINE (scm_open_file, "open-file", 2, 0, 0,
|
||||||
}
|
}
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (retries = 0, fdes = -1;
|
||||||
|
fdes < 0 && retries < 2;
|
||||||
|
retries++)
|
||||||
|
{
|
||||||
SCM_SYSCALL (fdes = open_or_open64 (file, flags, 0666));
|
SCM_SYSCALL (fdes = open_or_open64 (file, flags, 0666));
|
||||||
if (fdes == -1)
|
if (fdes == -1)
|
||||||
{
|
{
|
||||||
int en = errno;
|
int en = errno;
|
||||||
|
|
||||||
|
if (en == EMFILE && retries == 0)
|
||||||
|
/* Run the GC in case it collects open file ports that are no
|
||||||
|
longer referenced. */
|
||||||
|
scm_i_gc (FUNC_NAME);
|
||||||
|
else
|
||||||
SCM_SYSERROR_MSG ("~A: ~S",
|
SCM_SYSERROR_MSG ("~A: ~S",
|
||||||
scm_cons (scm_strerror (scm_from_int (en)),
|
scm_cons (scm_strerror (scm_from_int (en)),
|
||||||
scm_cons (filename, SCM_EOL)), en);
|
scm_cons (filename, SCM_EOL)), en);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
port = scm_i_fdes_to_port (fdes, scm_i_mode_bits (mode), filename);
|
port = scm_i_fdes_to_port (fdes, scm_i_mode_bits (mode), filename);
|
||||||
|
|
||||||
scm_dynwind_end ();
|
scm_dynwind_end ();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue