PR29262, memory leak in pr_function_type
[binutils-gdb.git] / gdb / ser-pipe.c
index 61d5708ea09cc490648e048c72fd3f480e999df9..80bb73e041826b6723de448db140139f05813e7a 100644 (file)
@@ -1,5 +1,5 @@
 /* Serial interface for a pipe to a separate program
-   Copyright (C) 1999-2019 Free Software Foundation, Inc.
+   Copyright (C) 1999-2022 Free Software Foundation, Inc.
 
    Contributed by Cygnus Solutions.
 
@@ -30,6 +30,7 @@
 #include "gdbsupport/gdb_sys_time.h"
 #include <fcntl.h>
 #include "gdbsupport/filestuff.h"
+#include "gdbsupport/pathstuff.h"
 
 #include <signal.h>
 
@@ -61,6 +62,12 @@ pipe_open (struct serial *scb, const char *name)
   int err_pdes[2];
   int pid;
 
+  if (*name == '|')
+    {
+      name++;
+      name = skip_spaces (name);
+    }
+
   if (gdb_socketpair_cloexec (AF_UNIX, SOCK_STREAM, 0, pdes) < 0)
     return -1;
   if (gdb_socketpair_cloexec (AF_UNIX, SOCK_STREAM, 0, err_pdes) < 0)
@@ -122,7 +129,9 @@ pipe_open (struct serial *scb, const char *name)
        }
 
       close_most_fds ();
-      execl ("/bin/sh", "sh", "-c", name, (char *) 0);
+
+      const char *shellfile = get_shell ();
+      execl (shellfile, shellfile, "-c", name, (char *) 0);
       _exit (127);
     }
 
@@ -228,8 +237,9 @@ static const struct serial_ops pipe_ops =
   ser_unix_write_prim
 };
 
+void _initialize_ser_pipe ();
 void
-_initialize_ser_pipe (void)
+_initialize_ser_pipe ()
 {
   serial_add_interface (&pipe_ops);
 }