Re: MoreAuthSample
Re: MoreAuthSample
- Subject: Re: MoreAuthSample
- From: Quinn <email@hidden>
- Date: Mon, 27 Jan 2003 12:48:40 +0000
At 12:34 +0100 27/1/03, Tomas Zahradnicky wrote:
Shouldn't one close stdin and stdout prior dup2-ing something into
their numbers (MoreSecExecuteRequestInHelperTool)?
MoreSecurity.c : 1578
The point of using dup2 is that you don't need to close. Here's the
quote from the "man" page.
In dup2(), the value of the new descriptor newd is specified. If this
descriptor is already in use, the descriptor is first deallocated as if a
close(2) call had been done first.
Or am I missing something more subtle?
and second question. wouldn't better be to call vfork instead of fork?
Yes. I intended to do this but it slipped through the cracks. I've
fixed it in our internal CVS repository. This problem by itself
isn't enough to warrant shipping a new version of the sample. You'll
see the change when (hopefully, if :-) I have to fix more significant
issues.
btw "fork" is *radically* slower than "vfork" on Mac OS X. It
probably doesn't make a lot of difference for MoreAuthSample, but if
you spawn a lot of processes it's important to use "vfork" when you
can.
third thing. MoreSecurity.c : 463 & 533 & ..., there's
assert(fdIn >= 0);
assert(fdOut >= 0);
but zero is valid file descriptor.
Yes. But the assertion is that fdIn greater than or *equal* *to* 0,
that is, that fdIn *is* a valid file descriptor.
I suggest testing it either against -1 (invalid fd) or against > 0.
Which is exactly the approach I take when I'm testing for a specific
nil value. Take a look at lines 772, 1618, 1652. However, this is a
pre-condition assert which states that "fdIn must be a valid file
descriptor" not "fdIn must not be an invalid file descriptor".
There's a distinct logic difference between these two statements.
also, calls to UNIX read/write can get interrupted with signals such
as alarm. There should probably be test for EINTR to happen and
retry it rather then returning an error.
Huh? Here's the core code for MoreUNIXRead.
while ( (err == 0) && (bytesLeft != 0) ) {
bytesThisTime = read(fd, cursor, bytesLeft);
if (bytesThisTime > 0) {
cursor += bytesThisTime;
bytesLeft -= bytesThisTime;
} else if (bytesThisTime == 0) {
err = EPIPE;
} else {
assert(bytesThisTime == -1);
err = errno;
assert(err != 0);
if (err == EINTR) {
err = 0; // let's loop again
}
}
}
If the error from "read" is EINTR, the error gets reset to 0 and we
loop. MoreUNIXWrite does the same thing.
CopyDictionaryFromDescriptor & WriteDictionaryToDescriptor functions
will crash on free if dictBuffer failed... or is valid to call
free(NULL)?.. this shows more times in the file...
It's valid to call free(NULL). Again, from the "man" page.
The free() function causes the allocated memory referenced by ptr to be
made available for future allocations. If ptr is NULL, no action occurs.
S+E
--
Quinn "The Eskimo!" <
http://www.apple.com/developer/>
Apple Developer Technical Support * Networking, Communications, Hardware
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.