• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Unable to unload Launch Daemon using Cocoa Application.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unable to unload Launch Daemon using Cocoa Application.


  • Subject: Unable to unload Launch Daemon using Cocoa Application.
  • From: JanakiRam <email@hidden>
  • Date: Sat, 22 Mar 2008 21:33:31 +0530

Hi All,

       I'm developing a cocoa application which needs to unload my Launch
Daemon for one particular requirement. I've used Authorization Services to
perform unload of Launch Daemon ( previlaged action ). But couldn't succeed
in this. I'm getting the following error on executed  my code.

*Output :*
**
*lauchctl : Error in unloading mydaemon*
**
*Note :* Attaching my code snippet for your reference.

          Please help me to solve this problem. Thanks in Advance.

-JanakiRam

 *Code Snippet :*
**
*- (void) UnloadDaemon
{
    // setup our authorization environment.
    AuthorizationItem authItems[1];  // we only want to get authorization
for one command
    BOOL authorized = NO;  // are we authorized?
    char *args[4];

    char *command = "/bin/launchctl";

    authItems[0].name = kAuthorizationRightExecute; // we want the right to
execute
    authItems[0].value = command;  // the path to the startup script
    authItems[0].valueLength = strlen(command); // length of the command
    authItems[0].flags = 0;    // no extra flags

    authRights.count = 1;  // we have one item
    authRights.items = authItems; // here is the values for our item

    authFlags = kAuthorizationFlagInteractionAllowed |
kAuthorizationFlagExtendRights;

    // lets find out if we are authorized

    ourStatus = AuthorizationCopyRights(authorizationRef,&authRights,
                kAuthorizationEmptyEnvironment, authFlags, NULL);

    authorized = (errAuthorizationSuccess==ourStatus);

    if (authorized)
    {
        // we are authorized, so let's tell the security framework to
execute
        // our command as root
  args[0] = "unload";
        args[1] = "-w";
  args[2] = "/Library/LaunchDaemons/org.mycompany.launchdaemon.plist";
  args[3] = NULL;

        ourStatus = AuthorizationExecuteWithPrivileges(authorizationRef,
                                             command,
                                             kAuthorizationFlagDefaults,
args, NULL);

        if(ourStatus != errAuthorizationSuccess)
        {
            NSLog(@"unload has failed");
        }
    }
    else
    {
      NSLog(@"error in authentication");
    }
}*
_______________________________________________

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

  • Follow-Ups:
    • Re: Unable to unload Launch Daemon using Cocoa Application.
      • From: Chris Hanson <email@hidden>
    • Re: Unable to unload Launch Daemon using Cocoa Application.
      • From: JanakiRam <email@hidden>
  • Prev by Date: Re: Creating custom sheets
  • Next by Date: Installer is automatically diverting the applications location in Leopard
  • Previous by thread: Re: [iPhone] NSTableView and NSIndexPath
  • Next by thread: Re: Unable to unload Launch Daemon using Cocoa Application.
  • Index(es):
    • Date
    • Thread