Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: execv bug???




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. If you call fork(2) and a subsequent exec* fails, then you must call _exit(2). 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.




So, the chdir on all other platforms goes to /var/qmail, and, the execv
executes from there bin/qmail-queue.

So the program you want to execute is /var/qmail/bin/qmail-queue? Seems like a strange place for it.


No, because as a simple test program shows, that works:

	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 *. 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." That said, execv(3) works for me without an absolute path as well.


--
Steve Checkoway

    "Anyone who says that the solution is to educate the users
    hasn't ever met an actual user." -- Bruce Schneier




Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: execv bug??? (From: email@hidden (Peter Seebach))



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.