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: open fails in daemon



Am Mittwoch, 23.07.03, um 07:32 Uhr (Europe/Berlin) schrieb Steve Cox:

Hi Steve,
I use a modified sample from Apple. <http://developer.apple.com/qa/qa2001/qa1133.html>
In Loginnitification I do the following:
void LoginFunction (CFStringRef UserName, uid_t UID, gid_t GID)
{
const int bufferSize = 80;
char usernameAsCString [bufferSize];
Boolean result = FALSE;

int childPID;
int status;
OSStatus err;
childPID = -1;

/* Now just for reference we will print out all the user information
* we have gathered. However first need to get a CString from
* the CFString since we are going to print to console.
* Thus, we need to get a CString from the CFString using the
* call CFStringGetCString.
* First Argument: The CFString to be converted to a CString. In this
* case we use are using the username passed to this function.
* Second Argument: An empty CString array which will be filled with
* the string which represents the CFString.
* Third Argument: The maximum size of the C String buffer.
* In this case we chose an arbitary length.
* Forth Argument: The encoding style to use when creating the
* CString. In this case since console understands ASCII we
* will stick with ASCII.
* Return Value: A boolean value representing if function
* was successful or not.
*/
result = CFStringGetCString (UserName, usernameAsCString, bufferSize, kCFStringEncodingUTF8);

if (result == FALSE) //weren't able to create the CString
//successfully. so just have empty string for username.
{
usernameAsCString[0] = '\0';
}

//writing to console that login occurred as well as the
//accociated user information.
syslog(1,"Login Occurred.");
syslog(1,"User Information: Username:\t\t%s\nUID:\t\t%d\nGID:\t\t%d\n", usernameAsCString, (int) UID, (int) GID);
childPID = vfork();
if (childPID == 0) // Child
{
// err = chdir(kAppWrapperPath);
// err = EXXXToOSStatus( MoreUNIXErrno(err) );
err = noErr;
if (err == noErr)
{
err = setgid (GID);
err = EXXXToOSStatus( MoreUNIXErrno(err) );
}

if (err == noErr)
{
err = setuid (UID);
err = EXXXToOSStatus( MoreUNIXErrno(err) );
}

if (err == noErr)
{
err = execl(kAppPath, kAppName, NULL);
err = EXXXToOSStatus( MoreUNIXErrno(err) );
}
assert(err != noErr); // otherwise we wouldn't be here
// Use "_exit" rather than "exit" because we're still in the
// same address space as the parent, so exit's closing
// of stdio streams will not be helpful.
_exit(err);
assert(false); // unreached
}
else if (childPID == -1)
{ // Error, Parent
err = EXXXToOSStatus( MoreUNIXErrno(childPID) );
}
else
{
assert(childPID > 0); // Parent
err = waitpid(childPID, &status, 0);
}
}

It works.



email@hidden writes:
The rule Chris and I both cited still stands. If using frameworks above
basic BSD frameworks, you cannot safely proceed after a fork() without
an exec().

I'm throwing in the towel. Thanks so much for all your help, guys, but I
can't spend any more time on this. My final test was to:
launch a tool that did a daemon(0,0), then an execlp(<self>)
when relaunched, the tool subscribed for login notifications and waited
on logout/login, the notifier was called and the tool did an
execlp(<another tool>)
the second tool launched successfully, but crashed when calling either
execlp(<CarbonApp>) or open(<CarbonApp)

Here's the stack dump which looked about the same for both execlp and open:
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000

Thread 0 Crashed:
#0 0x8fe1f460 in strlen
#1 0x8fe02554 in load_executable_image
#2 0x8fe01410 in _dyld_init
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.


--
Christian Weykopf
Meilenstein Mac OS Software

Neue Strasse 5
D-31582 Nienburg
Fax: +49 (0) 5021 91 24 45
<http://www.meilenstein.de/>
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: open fails in daemon (From: "Steve Cox" <email@hidden>)



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.