guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 05/07: fixup! Make system* and piped-process internally


From: Ludovic Courtès
Subject: [Guile-commits] 05/07: fixup! Make system* and piped-process internally use spawn.
Date: Fri, 23 Dec 2022 05:45:31 -0500 (EST)

civodul pushed a commit to branch wip-posix-spawn
in repository guile.

commit 63d496b19d20bf50c99a5b476f07853e98e8921e
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Fri Dec 23 00:40:50 2022 +0100

    fixup! Make system* and piped-process internally use spawn.
    
    indentation + cosmetic changes
---
 libguile/posix.c | 65 ++++++++++++++++++++++++++++----------------------------
 1 file changed, 32 insertions(+), 33 deletions(-)

diff --git a/libguile/posix.c b/libguile/posix.c
index cee3e8e24..de2a31aae 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1344,10 +1344,10 @@ close_inherited_fds (posix_spawn_file_actions_t 
*actions, int max_fd)
   closedir (dirp);
 }
 
-static int
+static pid_t
 do_spawn (char *exec_file, char **exec_argv, char **exec_env, int in, int out, 
int err)
 {
-  int pid = -1;
+  pid_t pid = -1;
 
   posix_spawn_file_actions_t actions;
   posix_spawnattr_t *attrp = NULL;
@@ -1389,16 +1389,16 @@ do_spawn (char *exec_file, char **exec_argv, char 
**exec_env, int in, int out, i
   close_inherited_fds (&actions, max_fd);
 
   if (posix_spawnp (&pid, exec_file, &actions, attrp, exec_argv, environ) != 0)
-      return -1;
+    return -1;
 
   return pid;
 }
 
 SCM_DEFINE (scm_spawn_process, "spawn*", 5, 0, 0,
-           (SCM prog, SCM args, SCM in, SCM out, SCM err),
-"Spawns a new child process executing @var{prog} with arguments\n"
-"@var{args}, with its standard input, output and error file descriptors\n"
-"set to @var{in}, @var{out}, @var{err}.")
+            (SCM prog, SCM args, SCM in, SCM out, SCM err),
+            "Spawns a new child process executing @var{prog} with arguments\n"
+            "@var{args}, with its standard input, output and error file 
descriptors\n"
+            "set to @var{in}, @var{out}, @var{err}.")
 #define FUNC_NAME s_scm_spawn_process
 {
   int pid;
@@ -1417,7 +1417,7 @@ SCM_DEFINE (scm_spawn_process, "spawn*", 5, 0, 0,
   free (exec_file);
 
   if (pid == -1)
-      SCM_SYSERROR;
+    SCM_SYSERROR;
 
   return scm_from_int (pid);
 }
@@ -1474,34 +1474,33 @@ scm_piped_process (SCM prog, SCM args, SCM from, SCM to)
   if (pid == -1)
     {
       /* TODO This is a compatibility shim until the next major release */
-      switch (errno) {
-      /* If the error seemingly comes from fork */
-      case EAGAIN:
-      case ENOMEM:
-      case ENOSYS:
-        free (exec_file);
-
-        if (reading)
-          {
+      switch (errno)
+        {
+          /* If the error seemingly comes from fork */
+        case EAGAIN:
+        case ENOMEM:
+        case ENOSYS:
+          free (exec_file);
+
+          if (reading)
             close (c2p[0]);
-          }
-        if (writing)
-          {
+          if (writing)
             close (p2c[1]);
-          }
-        errno = errno_save;
-        SCM_SYSERROR;
-        break;
-      /* Else create a dummy process that exits with value 127 */
-      default:
-        dprintf (err, "In execvp of %s: %s\n", exec_file,
-                 strerror (errno_save));
-        pid = fork ();
-        if (pid == -1)
+
+          errno = errno_save;
           SCM_SYSERROR;
-        if (pid == 0)
-          _exit (127);
-      }
+          break;
+
+        default:
+          /* Else create a dummy process that exits with value 127 */
+          dprintf (err, "In execvp of %s: %s\n", exec_file,
+                   strerror (errno_save));
+          pid = fork ();
+          if (pid == -1)
+            SCM_SYSERROR;
+          if (pid == 0)
+            _exit (127);
+        }
     }
 
   free (exec_file);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]