Message-ID: <330BE113.5328@cs.com> Date: Wed, 19 Feb 1997 21:28:51 -0800 From: "John M. Aldrich" Reply-To: fighteer AT cs DOT com Organization: Two pounds of chaos and a pinch of salt MIME-Version: 1.0 To: Eli Zaretskii CC: DJGPP Workers Mailing List , "Vyacheslav O. Myskin" , djgpp AT delorie DOT com Subject: Re: Starnge rm behavour References: Content-Type: multipart/mixed; boundary="------------439434646885" This is a multi-part message in MIME format. --------------439434646885 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Eli Zaretskii wrote: > > > I _think_ the problem can be solved by making redir call system() > > instead of spawnvp(). > > This is indeed the solution. Would you please submit the patches? > Thanks. Okay, I've made the patch and am attaching it to this message. It tests out okay with the original 'rm' bug, but I'm worried that the technique I use would be vulnerable to crashes with extremely long command lines. Should I use more than 4096 bytes for the buffer? It's hard to imagine a command line to redir being longer than 51 screen lines, and I don't want to use too much extra memory, but odder things have happened... In any case, it's trivial to increase the size of the buffer. If this patch checks out, I'll submit it as a fixed bug report to the bug tracking system. P.S.: I also fixed a typo in the usage() screen. ("warranty" is the legal right, "warrantee" is the person who receives that right) ;) To Vyacheslav and others: you can apply this patch by downloading 'v2/djlsr201.zip' and 'v2gnu/pat21b.zip'. Place the patch file in the src/utils directory and type "patch * Anything that happens, happens. * Anything that, in happening, causes something else to happen, causes something else to happen. * Anything that, in happening, causes itself to happen again, happens again. * It doesn't necessarily do it in chronological order, though. --- Douglas Adams --------------439434646885 Content-Type: text/plain; charset=us-ascii; name="REDIR.DIF" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="REDIR.DIF" *** redir.c~ Wed Jul 12 04:06:50 1995 --- redir.c Wed Feb 19 21:04:32 1997 *************** *** 46,52 **** { /* ----+----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"); --- 46,52 ---- { /* ----+----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 stdandard input from file\n"); *************** *** 74,79 **** --- 74,81 ---- int main(int argc, char **argv) { + char cmdline[4096]; /* hold command line to pass to system() */ + int i; 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]); --- 153,171 ---- 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(). ! */ ! cmdline[0] = '\0'; ! for ( i = 1; i < argc; i++ ) ! { ! strcat( cmdline, argv[i] ); ! if ( i < argc - 1 ) ! strcat( cmdline, " " ); ! } ! rv = system( cmdline ); ! if (rv < 0) fatal("Error attempting to run program %s\n", argv[1]); --------------439434646885--