PR29262, memory leak in pr_function_type
[binutils-gdb.git] / gdb / ser-pipe.c
index cc72010ae46fb945fdde9cb6af40b47e0d76132d..80bb73e041826b6723de448db140139f05813e7a 100644 (file)
@@ -1,5 +1,5 @@
 /* Serial interface for a pipe to a separate program
-   Copyright (C) 1999-2021 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);
     }