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: exec() with pmset



On 31 Oct 07, at 20:15, Andrew James wrote:
I am really not sure which list to post this to, but this list always seems
to help.


For some reason i can not make pmset work in my "authtool" which has a
setuid to have root privs,
<snip>
The code has to be forked and execl as system() will lose the root privs,
running that code however returns 13 or 256 (is there a way to know what
these values are?

The main issue I see with your code right now is that you're misusing execl(). The line


	execl("/usr/bin/pmset", "-a hibernatemode 3", NULL);

is incorrect - you must specify arguments to the child individually, as well as including its argv[0]. Read 'man execl' for more details.

The libc call perror() will print a human-readable version of errors. Error 13 is "permission denied" (EACCES). 256 isn't a valid error code, but it is a plausible return value from wait() indicating that the child process exited with status 1 (which pmset is expected to do in this situation).

Incidentally, keep in mind that execl() may return if it fails. You should generally follow it up with an exit() to avoid returning to your main program, as the behavior of AppKit in such situations is undefined.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >exec() with pmset (From: "Andrew James" <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.