1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-29 19:30:36 +02:00

Allow piped-process and system* to exist when fork is undefined

piped-process only uses fork to match legacy behavior, but on systems
that never had fork, there is no need to match that behavior.
piped-process and system* can be provided without fork.

* libguile/posix.c (piped_process): allow function definition without HAVE_FORK,
    but stub out internal dummy process with HAVE_FORK
  (restore_sigaction, scm_dynwind_sigaction, scm_system_star): don't
    require HAVE_FORK
  (scm_init_popen): don't require HAVE_FORK
  (scm_init_posix): don't require HAVE_FORK to add posix feature or
    register popen extension
This commit is contained in:
Michael Gran 2023-06-20 15:38:54 -07:00
parent 87402c849e
commit 9c86c5936e
2 changed files with 12 additions and 5 deletions

8
NEWS
View file

@ -60,6 +60,14 @@ capability to search for "libfoo" as "msys-foo.dll" on MSYS.
The load-foreign-library option #:rename-on-cygwin? has been changed to
#:host-type-rename?, and handles both Cygwin and MSYS.
** Make piped-process and system* available on systems without fork
Now that piped-process and system* are implemented in terms of
`posix_spawn', they can be made available on systems without fork().
Note that currently Guile does use fork in piped-process to set exit
codes, so piped-process on systems without fork will have a different
behavior with regards to exit codes.
* Performance improvements
** `copy-file` now relies on `sendfile` rather than a read/write loop

View file

@ -1529,7 +1529,6 @@ SCM_DEFINE (scm_spawn_process, "spawn", 2, 0, 1,
}
#undef FUNC_NAME
#ifdef HAVE_FORK
static int
piped_process (pid_t *pid, SCM prog, SCM args, SCM from, SCM to)
#define FUNC_NAME "piped-process"
@ -1630,11 +1629,13 @@ scm_piped_process (SCM prog, SCM args, SCM from, SCM to)
/* Create a dummy process that exits with value 127 to mimic the
previous fork + exec implementation. TODO: This is a
compatibility shim to remove in the next stable series. */
#ifdef HAVE_FORK
pid = fork ();
if (pid == -1)
SCM_SYSERROR;
if (pid == 0)
_exit (127);
#endif /* HAVE_FORK */
}
return scm_from_int (pid);
@ -1690,7 +1691,6 @@ SCM_DEFINE (scm_system_star, "system*", 0, 0, 1,
return scm_from_int (status);
}
#undef FUNC_NAME
#endif /* HAVE_FORK */
#ifdef HAVE_UNAME
SCM_DEFINE (scm_uname, "uname", 0, 0, 0,
@ -2566,13 +2566,12 @@ SCM_DEFINE (scm_gethostname, "gethostname", 0, 0, 0,
#endif /* HAVE_GETHOSTNAME */
#ifdef HAVE_FORK
static void
scm_init_popen (void)
{
scm_c_define_gsubr ("piped-process", 2, 2, 0, scm_piped_process);
}
#endif /* HAVE_FORK */
void
scm_init_posix ()
@ -2690,10 +2689,10 @@ scm_init_posix ()
#ifdef HAVE_FORK
scm_add_feature ("fork");
#endif /* HAVE_FORK */
scm_add_feature ("popen");
scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
"scm_init_popen",
(scm_t_extension_init_func) scm_init_popen,
NULL);
#endif /* HAVE_FORK */
}