Hi,
There is a very funny construction in a bit of scsh code that I am
wondering about...
In the file scsh-tramp.c (the wrapper for starting up the vm with
an initial image), the code to reconstruct argv looks like this...
newav[0] = argv[0]; /* Install new header args. */
newav[1] = "-o";
newav[2] = VM;
newav[3] = "-i";
newav[4] = IMAGE;
for(ap=&argv[0], aq=&newav[4]; *ap;) /* Copy over orignal argv */
*++aq = *++ap; /* & the terminating NULL. */
execv(VM, newav); /* Do it. */
perror(argv[0]);
exit(-1);
If you look at the my man page (NeXT) for execv ...
The path argument is a pointer to the name of the file to be
executed. The pointers arg[0], arg[1]... address null-
terminated strings. Conventionally arg[0] is the name of
the file.
Execl is useful when a known file with known arguments is
being called; the arguments to execl are the character
strings constituting the file and the arguments; the first
argument is conventionally the same as the file name (or its
last component). A 0 argument must end the argument list.
The execv version is useful when the number of arguments is
unknown in advance; the arguments to execv are the name of
the file to be executed and a vector of strings containing
the arguments. The last argument string must be followed by
a 0 pointer.
The above code puts in argv[0] the original file invoked, so a
normal invocation of scsh would have an execv that looked something
like:
execv("/usr/local/lib/scsh/scshvm",
["/usr/local/bin/scsh",
"-o", "/usr/local/lib/scsh/scshvm",
"-i", "/usr/local/lib/scsh/scsh.image",
"-s"]
Is there any good reason why the first argument to execv() is
different from the first argument of the array passed in (what
becomes argv[0])? It seems to me that they are "conventionally" the
same, and I can't think of any reason for them to be different.
That would be trivially accomplished by changing the line:
newav[0] = argv[0]; /* Install new header args. */
to
newav[0] = VM; /* Install new header args. */
As it turns out, my NeXT does not like the original form, and gives
me a "Malformed Mach-o file" error message after the execv() fails.
The second form works just fine.
Later...
- Charlie Conklin conklic@swissbank.com
|