This is the mail archive of the cygwin-apps@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: two questions


On Sun, Jul 16, 2000 at 03:24:35PM +1000, Robert Collins wrote:
>This sample program demonstrates the problem. I am using execvp for my my
>code, by exec() I actually meant the exec family of calls... I'll try to be
>clearer next time..
>
>#include <stdio.h>
>
>int
>main (int argc, char **argv)
>{
>  char *prog;
>  char passarg[]="A";
>  fprintf (stderr, "argv[0] '%s', argv[1] '%s'\n", argv[0], argv[1]);
>  prog=(char *)strdup(argv[0]);
>  if (argv[1]==NULL)
>  {
>    fprintf(stderr, "called with no args going to run '%s' with '%s'
>\n",prog,passarg);
>    sleep(5);
>    execl (prog,prog,passarg );
>    /* SHOULD NEVER REACH */
>    fprintf(stderr, "exec failed!\n");
>    sleep(10);
>    }
>  sleep(10);
>}

Both of our test programs had bugs in them.  Mine would core dump if
there was more than one argument.  Yours SEGVs every time for me, although
it could also just SEGV randomly, I suppose.

The reason is that execl needs to be terminated with a NULL final
argument.

Regardless, my analysis of what was going wrong is still probably
correct.  You didn't report on the output of any of the test
cases but I would guess that, when run from explorer, you'd see
something like:

argv[0] '"c:\cygwin\usr\local\pathtest\pathtest"', argv[1] '(null)'
        ^^                                     ^^

The extra levels of quoting are what was screwing up cygwin.  As
I mentioned, I just checked in a patch to fix this.

cgf

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]