delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/05/15/22:21:47

Message-ID: <337B8C14.3403@cs.com>
Date: Thu, 15 May 1997 22:20:04 +0000
From: "John M. Aldrich" <fighteer AT cs DOT com>
Reply-To: fighteer AT cs DOT com
Organization: Two pounds of chaos and a pinch of salt
MIME-Version: 1.0
To: DJGPP Workers Mailing List <djgpp-workers AT delorie DOT com>
Subject: Bugfix for redir.c

This is a multi-part message in MIME format.

--------------19B36316394
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

--- Reposted at the request of DJ Delorie ---

There's a bug in the code for redir from DJGPP v2.01 that causes
wildcards on
the command line to be passed incorrectly to child programs.  For
example, the
following command line:

redir -e err.log rm *.o

will produce:

rm: *.o: No such file or directory (ENOENT)

This problem first appeared in v2.01.

The problem lies in the enhanced command line handling of the v2.01
libc.  redir
uses spawnvp() to pass command lines, but v2.01 programs do not perform
wildcard
expansion on command lines received via spawn*().  Since redir does not
perform
wildcard expansion itself, this caused command lines to be passed
verbatim instead
of being expanded by the child program.

The solution is to switch spawnvp() in redir.c with system().  This also
requires
that redir reconstruct the original command line.  The required patch is
below;
I also modified the makefile for redir to increase the default transfer
buffer
size, since redir could conceivably fail when passed extremely long
command lines.

This patch was also submitted as bug #000153 to the DJGPP bug tracking
system, although I think that it may have been mangled it a bit when I
pasted it into the form.  Sorry.

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I |     mailto:fighteer AT cs DOT com      |
| Descent 2: The Infinite Abyss - The greatest Internet game of all |
| time just got better!  This time, you're going all the way down...|
---------------------------------------------------------------------

--------------19B36316394
Content-Type: text/plain; charset=us-ascii; name="REDIR.DIF"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="REDIR.DIF"

*** src/utils/redir.c~0	Wed Jul 12 04:06:50 1995
--- src/utils/redir.c	Thu May 15 22:09:28 1997
***************
*** 46,55 ****
  {
    /*               ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 */
    fprintf(stderr, "Redir 1.0 Copyright (C) 1995 DJ Delorie (dj AT delorie DOT com) - distribute freely\n");
!   fprintf(stderr, "NO WARRANTEE.  This program is protected by the GNU General Public License.\n");
    fprintf(stderr, "Usage: redir [-i file] [-o file] [-oa file] [-e file] [-ea file]\n");
    fprintf(stderr, "                [-eo] [-oe] [-x] [-t] command [args . . .]\n\n");
!   fprintf(stderr, "  -i file   redirect stdandard input from file\n");
    fprintf(stderr, "  -o file   redirect standard output to file\n");
    fprintf(stderr, "  -oa file  append standard output to file\n");
    fprintf(stderr, "  -e file   redirect standard error to file\n");
--- 46,55 ----
  {
    /*               ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 */
    fprintf(stderr, "Redir 1.0 Copyright (C) 1995 DJ Delorie (dj AT delorie DOT com) - distribute freely\n");
!   fprintf(stderr, "NO WARRANTY.  This program is protected by the GNU General Public License.\n");
    fprintf(stderr, "Usage: redir [-i file] [-o file] [-oa file] [-e file] [-ea file]\n");
    fprintf(stderr, "                [-eo] [-oe] [-x] [-t] command [args . . .]\n\n");
!   fprintf(stderr, "  -i file   redirect standard input from file\n");
    fprintf(stderr, "  -o file   redirect standard output to file\n");
    fprintf(stderr, "  -oa file  append standard output to file\n");
    fprintf(stderr, "  -e file   redirect standard error to file\n");
***************
*** 74,79 ****
--- 74,82 ----
  int
  main(int argc, char **argv)
  {
+   char *cmdline;  /* hold command line to pass to system() */
+   size_t sz;      /* size of allocation for cmdline */
+   int i;          /* arg counter */
  
    if (argc < 2)
      usage();
***************
*** 151,157 ****
      argv++;
    }
  
!   rv = spawnvp(P_WAIT, argv[1], argv+1);
    if (rv < 0)
      fatal("Error attempting to run program %s\n", argv[1]);
  
--- 154,188 ----
      argv++;
    }
  
!   /* The old method of calling spawnvp() breaks v2.01 programs that use
!    * wildcards.  To fix this, build the remaining arguments into one long
!    * string to pass to system().
!    */
!   sz = 16384;   /* initial malloc size */
!   if ((cmdline = malloc(sz)) == NULL)
!   {
!     fprintf(std_err, "redir: malloc failed for %lu bytes", sz);
!     exit(1);
!   }
!   *cmdline = '\0';
!   for (i = 1; i < argc; i++)
!   {
!     if (strlen(cmdline) + strlen(argv[i]) + 1 > sz)
!     {
!       sz += 16384;   /* malloc increment */
!       if ((cmdline = realloc(cmdline,sz)) == NULL)
!       {
! 	fprintf(std_err, "redir: realloc failed for %lu bytes", sz);
! 	exit(1);
!       }
!     }
!     strcat(cmdline, argv[i]);
!     if (i < argc - 1)
! 	strcat(cmdline, " ");
!   }
!   rv = system(cmdline);
!   free(cmdline);
!   
    if (rv < 0)
      fatal("Error attempting to run program %s\n", argv[1]);
  
*** src/utils/makefile.~	Tue Jan 23 22:15:58 1996
--- src/utils/makefile	Thu Feb 20 19:02:46 1997
***************
*** 21,26 ****
--- 21,31 ----
  
  include $(TOP)/../makefile.prg
  
+ $(BIN)/redir.exe : $C redir.o $L
+ 	$(LINK)
+ 	$(EXE)
+ 	$(BIN)/stubedit $(BIN)/redir.exe bufsize=64k
+ 
  $(BIN)/rem.com : rem.asm
  	djasm $^ $@
  

--------------19B36316394--


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019