You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Paul Sutton <pa...@eu.c2.net> on 1997/11/15 18:11:33 UTC

PATCH NT: spaces in argv[]

On Fri, 14 Nov 1997, Paul Sutton wrote:
> On Fri, 14 Nov 1997, Ben Laurie wrote:
> > Hmmm ... well, we can default the path to something without spaces for
> > now (I think that isn't too painful), and hope not too many people
> > change it to something with spaces. The fix isn't that hard, just
> > totally digusting, and haven't had the time to do it (and I'm cooking
> > major Chinese this evening, so I won't have the time today :-).
> 
> I've already sent a patch for this. It results in the lose of memory
> thought at the moment. If Windows is so braindead we really need to code
> around it, we'll need to pass the parent's pool into the function which
> spawns children. 

Ok, here is a slightly better patch. This doesn't waste space. We don't
care about performance since this function is only called to create child
processes, while most work is done by creating threads inside in a single
process. Win32 must have the world's worst implementation of spawn(). 

//pcs

Index: http_main.c
===================================================================
RCS file: /export/home/cvs/apachen/src/main/http_main.c,v
retrieving revision 1.250
diff -u -r1.250 http_main.c
--- http_main.c	1997/11/13 20:20:46	1.250
+++ http_main.c	1997/11/15 17:07:17
@@ -4183,7 +4183,19 @@
     pass_argv[1] = "-c";
     pass_argv[2] = buf;
     for (i = 1; i < argc; i++) {
-	pass_argv[i + 2] = argv[i];
+        if (strchr(argv[i], ' ')) {
+            /* Incredibly, passing an argument containing spaces within
+             * argv[] does not work. We have to manually quote the argument
+             * here. Ugh.
+             */
+            pass_argv[i+2] = alloca(strlen(argv[i])+2+1);
+            *(pass_argv[i+2]) = '\"';
+            strcpy(pass_argv[i+2]+1, argv[i]);
+            strcat(pass_argv[i+2], "\"");
+        }
+        else {
+	    pass_argv[i + 2] = argv[i];
+        }
     }
     pass_argv[argc + 2] = NULL;
 



Re: PATCH NT: spaces in argv[]

Posted by Ben Laurie <be...@algroup.co.uk>.
Dirk-Willem van Gulik wrote:
> 
> On Sat, 15 Nov 1997, Ben Laurie wrote:
> 
> +1 (tested. though I've done a strcat())
> 
> spewed spawn, so sad, sad, sad.
> 
> Dw.
> 
> > > Index: http_main.c
> > > ===================================================================
> > > RCS file: /export/home/cvs/apachen/src/main/http_main.c,v
> > > retrieving revision 1.250
> > > diff -u -r1.250 http_main.c
> > > --- http_main.c 1997/11/13 20:20:46     1.250
> > > +++ http_main.c 1997/11/15 17:07:17
> > > @@ -4183,7 +4183,19 @@
> > >      pass_argv[1] = "-c";
> > >      pass_argv[2] = buf;
> > >      for (i = 1; i < argc; i++) {
> > > -       pass_argv[i + 2] = argv[i];
> > > +        if (strchr(argv[i], ' ')) {
> > > +            /* Incredibly, passing an argument containing spaces within
> > > +             * argv[] does not work. We have to manually quote the argument
> > > +             * here. Ugh.
> > > +             */
> > > +            pass_argv[i+2] = alloca(strlen(argv[i])+2+1);
> 
> strcat(pass_argv[i+2],"""",argv[i],"""");?

a) strcat don't work like that (you are thinking of pstrcat).
b) if you use pstrcat, you need to terminate the list with NULL.

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686|Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |Apache-SSL author
A.L. Digital Ltd,     |http://www.algroup.co.uk/Apache-SSL
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache

Re: PATCH NT: spaces in argv[]

Posted by Dirk-Willem van Gulik <di...@elect6.jrc.it>.
On Sat, 15 Nov 1997, Ben Laurie wrote:

+1 (tested. though I've done a strcat())

spewed spawn, so sad, sad, sad.

Dw.


> > Index: http_main.c
> > ===================================================================
> > RCS file: /export/home/cvs/apachen/src/main/http_main.c,v
> > retrieving revision 1.250
> > diff -u -r1.250 http_main.c
> > --- http_main.c 1997/11/13 20:20:46     1.250
> > +++ http_main.c 1997/11/15 17:07:17
> > @@ -4183,7 +4183,19 @@
> >      pass_argv[1] = "-c";
> >      pass_argv[2] = buf;
> >      for (i = 1; i < argc; i++) {
> > -       pass_argv[i + 2] = argv[i];
> > +        if (strchr(argv[i], ' ')) {
> > +            /* Incredibly, passing an argument containing spaces within
> > +             * argv[] does not work. We have to manually quote the argument
> > +             * here. Ugh.
> > +             */
> > +            pass_argv[i+2] = alloca(strlen(argv[i])+2+1);

strcat(pass_argv[i+2],"""",argv[i],"""");?

> > +            *(pass_argv[i+2]) = '\"';
> > +            strcpy(pass_argv[i+2]+1, argv[i]);
> > +            strcat(pass_argv[i+2], "\"");
> > +        }
> > +        else {
> > +           pass_argv[i + 2] = argv[i];
> > +        }
> >      }
> >      pass_argv[argc + 2] = NULL;
> > 
> 
> Cool. +1 (untested).
> 
> Cheers,
> 
> Ben.
> 
> -- 
> Ben Laurie            |Phone: +44 (181) 735 0686|Apache Group member
> Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org
> and Technical Director|Email: ben@algroup.co.uk |Apache-SSL author
> A.L. Digital Ltd,     |http://www.algroup.co.uk/Apache-SSL
> London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache
> 


Re: PATCH NT: spaces in argv[]

Posted by Ben Laurie <be...@algroup.co.uk>.
Paul Sutton wrote:
> 
> On Fri, 14 Nov 1997, Paul Sutton wrote:
> > On Fri, 14 Nov 1997, Ben Laurie wrote:
> > > Hmmm ... well, we can default the path to something without spaces for
> > > now (I think that isn't too painful), and hope not too many people
> > > change it to something with spaces. The fix isn't that hard, just
> > > totally digusting, and haven't had the time to do it (and I'm cooking
> > > major Chinese this evening, so I won't have the time today :-).
> >
> > I've already sent a patch for this. It results in the lose of memory
> > thought at the moment. If Windows is so braindead we really need to code
> > around it, we'll need to pass the parent's pool into the function which
> > spawns children.
> 
> Ok, here is a slightly better patch. This doesn't waste space. We don't
> care about performance since this function is only called to create child
> processes, while most work is done by creating threads inside in a single
> process. Win32 must have the world's worst implementation of spawn().
> 
> //pcs
> 
> Index: http_main.c
> ===================================================================
> RCS file: /export/home/cvs/apachen/src/main/http_main.c,v
> retrieving revision 1.250
> diff -u -r1.250 http_main.c
> --- http_main.c 1997/11/13 20:20:46     1.250
> +++ http_main.c 1997/11/15 17:07:17
> @@ -4183,7 +4183,19 @@
>      pass_argv[1] = "-c";
>      pass_argv[2] = buf;
>      for (i = 1; i < argc; i++) {
> -       pass_argv[i + 2] = argv[i];
> +        if (strchr(argv[i], ' ')) {
> +            /* Incredibly, passing an argument containing spaces within
> +             * argv[] does not work. We have to manually quote the argument
> +             * here. Ugh.
> +             */
> +            pass_argv[i+2] = alloca(strlen(argv[i])+2+1);
> +            *(pass_argv[i+2]) = '\"';
> +            strcpy(pass_argv[i+2]+1, argv[i]);
> +            strcat(pass_argv[i+2], "\"");
> +        }
> +        else {
> +           pass_argv[i + 2] = argv[i];
> +        }
>      }
>      pass_argv[argc + 2] = NULL;
> 

Cool. +1 (untested).

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686|Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |Apache-SSL author
A.L. Digital Ltd,     |http://www.algroup.co.uk/Apache-SSL
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache

Re: PATCH NT: spaces in argv[]

Posted by Ben Laurie <be...@algroup.co.uk>.
Paul Sutton wrote:
> 
> On Fri, 14 Nov 1997, Paul Sutton wrote:
> > On Fri, 14 Nov 1997, Ben Laurie wrote:
> > > Hmmm ... well, we can default the path to something without spaces for
> > > now (I think that isn't too painful), and hope not too many people
> > > change it to something with spaces. The fix isn't that hard, just
> > > totally digusting, and haven't had the time to do it (and I'm cooking
> > > major Chinese this evening, so I won't have the time today :-).
> >
> > I've already sent a patch for this. It results in the lose of memory
> > thought at the moment. If Windows is so braindead we really need to code
> > around it, we'll need to pass the parent's pool into the function which
> > spawns children.
> 
> Ok, here is a slightly better patch. This doesn't waste space. We don't
> care about performance since this function is only called to create child
> processes, while most work is done by creating threads inside in a single
> process. Win32 must have the world's worst implementation of spawn().

The snag here is that this only fixes the launch of standby Apaches, but
surely we need to fix _all_ occurences of spawn? I'll try to do a more
general fix.

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686|Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |Apache-SSL author
A.L. Digital Ltd,     |http://www.algroup.co.uk/Apache-SSL
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache