Re: exec() with pmset
Re: exec() with pmset
- Subject: Re: exec() with pmset
- From: Andrew Farmer <email@hidden>
- Date: Wed, 31 Oct 2007 20:38:56 -0700
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:
This email sent to email@hidden