Re: execv bug???
Re: execv bug???
- Subject: Re: execv bug???
- From: email@hidden (Peter Seebach)
- Date: Sun, 27 Jan 2008 11:56:49 -0600
In message <email@hidden>, Steve Checkoway w
rites:
>On Jan 27, 2008, at 12:12 AM, Peter Seebach wrote:
>> In message <email@hidden>, Steve writes:
>>> if (chdir(auto_qmail) == -1) _exit(61);
>>> execv(*binqqargs,binqqargs);
>>> _exit(120);
>> Calling _exit from user code is nearly always a mistake.
>This is not true at all.
In general it is, but..
>If you call fork(2) and a subsequent exec*
>fails, then you must call _exit(2).
Well, not necessarily. You may need to, if...
>exit(3) calls functions registered
>with atexit, flushes open output streams, closes open streams, and
>unlinks files created with tmpfile(3).Calling exit(3) will cause the
>open output streams to flush twice.
I somehow doubt that djb's code uses tmpfile(). It is possible that it
leaves output streams unflushed, but I'd be surprised. But yes -- this is
presumably the path leading to an exec, so failures should avoid doing
all that cleanup. If there is any, which I would rather doubt.
>So the program you want to execute is /var/qmail/bin/qmail-queue?
>Seems like a strange place for it.
It is a strange place, but that's how qmail works -- it puts everything
in /var/qmail.
>> static char *ev[] = { 0, 0 };
>>
>> int
>> main(void) {
>> ev[0] = "bin/ls";
>> chdir("/");
>> execv(*ev, ev);
>> return 23;
>> }
>>
>You're assigning a const char * to a char *.
No I'm not.
>I'm not sure why gcc
>doesn't warn about this, but I suspect that it should. In fact, if you
>assign "bin/ls" to a const char * first, then it does warn, "warning:
>assignment discards qualifiers from pointer target type."
Well, yes. Because then there'd be a const char * involved.
String literals are not const-qualified, even though their contents may not be
modified.
-s
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden