Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6839763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:45:31+00:00 2026-05-26T23:45:31+00:00

I’m using AuthorizationExecuteWithPriveleges to execute bash commands from my App with admin privilege. I

  • 0

I’m using AuthorizationExecuteWithPriveleges to execute bash commands from my App with admin privilege. I have found really weird issue. Here what I’m using

    FILE *pipe=nil;
    OSStatus err;
    AuthorizationRef authorizationRef;
    char *command= "/bin/chmod";
  
    
    char *args[] = {"644","folderPath", nil};

   if(err!=0)
    {
                                err = AuthorizationCreate(nil,
                                       kAuthorizationEmptyEnvironment,
                                       kAuthorizationFlagDefaults,
                                       &authorizationRef);
    }
    NSLog(@"test");
    err = AuthorizationExecuteWithPrivileges(authorizationRef,
                                             command,
                                             kAuthorizationFlagDefaults,
                                             args,
                                             &pipe);  

After calling this function about 40 times, it’s starting respond very slowly. And after it is will just die,and freeze application, and I have no idea what is happening to this.It doesn’t show the log "test", and doesn’t do anything, after calling about 40 times.
It doesn’t matter what Bash command or what arguments you are using. It still does the same thing. What is wrong with this ? The reason I’m using this, because my App needs to run on 10.5 as well.

Please if someone have idea, what can I do. I really appreciate it. I need ASAP. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:45:32+00:00Added an answer on May 26, 2026 at 11:45 pm

    Looked at this a bit more, and cooked up the following example, presented without warranty, but which works for me for thousands of invocations of AuthorizationExecuteWithPrivileges without issue:

    void DoOtherStuff(AuthorizationRef auth, char* path);
    
    void DoStuff(char* path)
    {
        AuthorizationItem foo;
        foo.name = kAuthorizationRightExecute;
        foo.value = NULL;
        foo.valueLength = 0;
        foo.flags = 0;
    
        AuthorizationRights rights;
        rights.count = 1;
        rights.items = &foo;
    
        AuthorizationRef authorizationRef;
        OSStatus err = errAuthorizationSuccess;
    
        if (errAuthorizationSuccess != (err = AuthorizationCreate(NULL,  kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef)))    
        {
            NSLog(@"Error on AuthorizationCreate: %lu", (long)err);
            return;
        }
    
        for (NSUInteger i = 0; i < 5000; i++)
        {
            NSLog(@"Doing run: %lu", (long)i+1);
            DoOtherStuff(authorizationRef, "/tmp/foo");
        }
    
        if (errAuthorizationSuccess != (err = AuthorizationFree(authorizationRef, kAuthorizationFlagDefaults)))
        {
            NSLog(@"Error on AuthorizationFree: %lu", (long)err);
            return;
        }
    }
    
    void DoOtherStuff(AuthorizationRef authorizationRef, char* path)
    {    
        OSStatus err = errAuthorizationSuccess;
        FILE *pipe = NULL;
        @try
        {
            char *args[] = {"644", path, NULL};
            if (errAuthorizationSuccess != (err = AuthorizationExecuteWithPrivileges(authorizationRef,
                                                     "/bin/chmod", kAuthorizationFlagDefaults, args, &pipe)))
            {
                NSLog(@"Error on AuthorizationExecuteWithPrivileges: %lu", (long)err);
                return;
            }
    
            int stat;
            wait(&stat);
    
            NSLog(@"Success! Child Process Died!");
        }
        @finally 
        {        
            if (pipe)
                fclose(pipe);
        }
    }
    

    What Chris Suter said is dead on. What happens when you call AuthorizationExecuteWithPrivileges is that it fork()s your process and then exec()s the requested process (chmod in this case) from the child process. The child process won’t be reaped until someone calls wait(), but that’s hard because we don’t get the PID of the child out of AuthorizationExecuteWithPrivileges (it would have been returned by fork()). As he said, if you’re sure there aren’t other threads spawning processes at the same time (i.e. your thread is the only one creating child processes), then you can just call the non-PID specific version of wait() like I do in this example.

    If you don’t call wait() then what happens is you accumulate these zombie child processes that are all waiting to be reaped. Eventually the OS says “no more.”

    I feel kinda bad posting this, since it’s just a retread of what Chris Suter said; I’ve upvoted his answer.

    For completeness, here’s a reworked version of that example that achieves the goal by ignoring SIGCHLD instead of calling wait. It also is presented without warranty, but works for me.

    void DoOtherStuff(AuthorizationRef auth, char* path);
    
    void DoStuff(char* path)
    {
        AuthorizationItem foo;
        foo.name = kAuthorizationRightExecute;
        foo.value = NULL;
        foo.valueLength = 0;
        foo.flags = 0;
    
        AuthorizationRights rights;
        rights.count = 1;
        rights.items = &foo;
    
        AuthorizationRef authorizationRef;
        OSStatus err = errAuthorizationSuccess;
    
        struct sigaction oldAction;
        struct sigaction newAction;
    
        newAction.__sigaction_u.__sa_handler = SIG_IGN;
        newAction.sa_mask = 0;
        newAction.sa_flags = 0;
    
        if(0 != sigaction(SIGCHLD, &newAction, &oldAction))
        {
            NSLog(@"Couldn't ignore SIGCHLD");
            return;
        }
    
        @try
        {
            if (errAuthorizationSuccess != (err = AuthorizationCreate(NULL,  kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef)))    
            {
                NSLog(@"Error on AuthorizationCreate: %lu", (long)err);
                return;
            }
    
            for (NSUInteger i = 0; i < 1000; i++)
            {
                NSLog(@"Doing run: %lu", (long)i+1);
                DoOtherStuff(authorizationRef, "/tmp/foo");
            }
    
            if (errAuthorizationSuccess != (err = AuthorizationFree(authorizationRef, kAuthorizationFlagDefaults)))
            {
                NSLog(@"Error on AuthorizationFree: %lu", (long)err);
                return;
            }
        }
        @finally 
        {
            const struct sigaction cOldAction = oldAction;
            if(0 != sigaction(SIGCHLD, &cOldAction, NULL))
            {
                NSLog(@"Couldn't restore the handler for SIGCHLD");
                return;
            }
    
        }
    }
    
    void DoOtherStuff(AuthorizationRef authorizationRef, char* path)
    { 
        OSStatus err = errAuthorizationSuccess;
        FILE *pipe = NULL;
        @try
        {
            char *args[] = {"644", path, NULL};
            if (errAuthorizationSuccess != (err = AuthorizationExecuteWithPrivileges(authorizationRef,
                                                     "/bin/chmod", kAuthorizationFlagDefaults, args, &pipe)))
            {
                NSLog(@"Error on AuthorizationExecuteWithPrivileges: %lu", (long)err);
                return;
            }
    
            NSLog(@"Success!");
        }
        @finally 
        {        
            if (pipe)
                fclose(pipe);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.