bug-gnulib
[Top][All Lists]
Advanced

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

execute, pipe: allow shell scripts on mingw


From: Bruno Haible
Subject: execute, pipe: allow shell scripts on mingw
Date: Mon, 29 Sep 2008 15:15:01 +0200
User-agent: KMail/1.5.4

This allows the use of shell scripts in place of executables on mingw.


2008-09-29  Bruno Haible  <address@hidden>

        Enable use of shell scripts as executables in mingw.
        * lib/execute.c (execute): When spawnv fails with error ENOEXEC,
        run the program as a shell script.
        * lib/pipe.c (create_pipe): Likewise.
        * lib/w32spawn.h (prepare_spawn): Add a hidden element in front of the
        resulting array.

*** lib/execute.c.orig  2008-09-29 15:13:03.000000000 +0200
--- lib/execute.c       2008-09-29 15:12:38.000000000 +0200
***************
*** 130,135 ****
--- 130,136 ----
    int nullinfd;
    int nulloutfd;
  
+   /* FIXME: Need to free memory allocated by prepare_spawn.  */
    prog_argv = prepare_spawn (prog_argv);
  
    /* Save standard file handles of parent process.  */
***************
*** 160,166 ****
              && ((null_stdout && nulloutfd == STDOUT_FILENO)
                  || (null_stderr && nulloutfd == STDERR_FILENO)
                  || close (nulloutfd) >= 0))))
!     exitcode = spawnvp (P_WAIT, prog_path, prog_argv);
    if (nulloutfd >= 0)
      close (nulloutfd);
    if (nullinfd >= 0)
--- 161,177 ----
              && ((null_stdout && nulloutfd == STDOUT_FILENO)
                  || (null_stderr && nulloutfd == STDERR_FILENO)
                  || close (nulloutfd) >= 0))))
!     {
!       exitcode = spawnvp (P_WAIT, prog_path, prog_argv);
!       if (exitcode < 0 && errno == ENOEXEC)
!       {
!         /* prog is not an native executable.  Try to execute it as a
!            shell script.  Note that prepare_spawn() has already prepended
!            a hidden element "sh.exe" to prog_argv.  */
!         --prog_argv;
!         exitcode = spawnvp (P_WAIT, prog_argv[0], prog_argv);
!       }
!     }
    if (nulloutfd >= 0)
      close (nulloutfd);
    if (nullinfd >= 0)
*** lib/pipe.c.orig     2008-09-29 15:13:03.000000000 +0200
--- lib/pipe.c  2008-09-29 15:12:46.000000000 +0200
***************
*** 145,150 ****
--- 145,151 ----
    int stdinfd;
    int stdoutfd;
  
+   /* FIXME: Need to free memory allocated by prepare_spawn.  */
    prog_argv = prepare_spawn (prog_argv);
  
    if (pipe_stdout)
***************
*** 201,207 ****
         we want in the case of STD*_FILENO) and also orig_stdin,
         orig_stdout, orig_stderr (which is not explicitly wanted but
         harmless).  */
!     child = spawnvp (P_NOWAIT, prog_path, prog_argv);
    if (stdinfd >= 0)
      close (stdinfd);
    if (stdoutfd >= 0)
--- 202,218 ----
         we want in the case of STD*_FILENO) and also orig_stdin,
         orig_stdout, orig_stderr (which is not explicitly wanted but
         harmless).  */
!     {
!       child = spawnvp (P_NOWAIT, prog_path, prog_argv);
!       if (child < 0 && errno == ENOEXEC)
!       {
!         /* prog is not an native executable.  Try to execute it as a
!            shell script.  Note that prepare_spawn() has already prepended
!            a hidden element "sh.exe" to prog_argv.  */
!         --prog_argv;
!         child = spawnvp (P_NOWAIT, prog_argv[0], prog_argv);
!       }
!     }
    if (stdinfd >= 0)
      close (stdinfd);
    if (stdoutfd >= 0)
*** lib/w32spawn.h.orig 2008-09-29 15:13:03.000000000 +0200
--- lib/w32spawn.h      2008-09-29 15:02:53.000000000 +0200
***************
*** 1,5 ****
  /* Auxiliary functions for the creation of subprocesses.  Native Woe32 API.
!    Copyright (C) 2003, 2006, 2007 Free Software Foundation, Inc.
     Written by Bruno Haible <address@hidden>, 2003.
  
     This program is free software: you can redistribute it and/or modify
--- 1,5 ----
  /* Auxiliary functions for the creation of subprocesses.  Native Woe32 API.
!    Copyright (C) 2003, 2006-2008 Free Software Foundation, Inc.
     Written by Bruno Haible <address@hidden>, 2003.
  
     This program is free software: you can redistribute it and/or modify
***************
*** 91,97 ****
      ;
  
    /* Allocate new argument vector.  */
!   new_argv = XNMALLOC (argc + 1, char *);
  
    /* Put quoted arguments into the new argument vector.  */
    for (i = 0; i < argc; i++)
--- 91,105 ----
      ;
  
    /* Allocate new argument vector.  */
!   new_argv = XNMALLOC (1 + argc + 1, char *);
! 
!   /* Add an element upfront that can be used when argv[0] turns out to be a
!      script, not a program.
!      On Unix, this would be "/bin/sh". On native Windows, "sh" is actually
!      "sh.exe".  We have to omit the directory part and rely on the search in
!      PATH, because the mingw "mount points" are not visible inside Win32
!      CreateProcess().  */
!   *new_argv++ = "sh.exe";
  
    /* Put quoted arguments into the new argument vector.  */
    for (i = 0; i < argc; i++)





reply via email to

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