• 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
Re: Communicate with pipe and AuthorizationExecuteWithPrivileges
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Communicate with pipe and AuthorizationExecuteWithPrivileges


  • Subject: Re: Communicate with pipe and AuthorizationExecuteWithPrivileges
  • From: Bill Bumgarner <email@hidden>
  • Date: Mon, 25 Jun 2001 22:49:49 -0400

You are doing a blocking read on the pipe. That is, fread() is going to sit around and wait until there are at least 4096 bytes available and it'll block until there is. If that never happens and the stdout pipe of the subprocess never closes, fread() will never return.

Look at the man page for fread() and friends-- this isn't an AuthorizationExecuteWithPrivileges level problem.

Check out the source for Xoptimize from mosxland.sourceforge.net. It uses a thread to monitor the FILE * and reads the output from that a character at a time-- certainly not the most effecient means, but perfectly sufficient for the purposes of Xoptimize or anything else (like shutdown) that generates a relatively small or relatively sporadic amount of output.

As opposed to using Distributed Objects to communicate from the monitoring thread to the main event loop, you might want to simply post an NSEvent (Application Defined) to indicate that there is data to be displayed. This is actually fairly easy to do and is a heck of a lot fewer lines than a DO based solution.

b.bum

On Monday, June 25, 2001, at 07:42 PM, email@hidden wrote:

Date: Mon, 25 Jun 2001 18:10:22 +0200
From: Jorge Salvador Caffarena <email@hidden>
To: email@hidden
Subject: Communicate with pipe and AuthorizationExecuteWithPrivileges

Here I am again with a question about
AuthorizationExecuteWithPrivileges. The only documentation I have found
on this function is on its header file, and it is short and not very
helpfull sometimes.

I want to get the output of the tool I execute with
AuthorizationExecuteWithPrivileges, but when I use a FILE * handler,
after trying to read from it my app enter some kind of deadlock and the
Beachball Of Death appears. Here is the code:

err = AuthorizationExecuteWithPrivileges(authorizationRef,
"/sbin/shutdown",0,args,&output);

fread(buffer,1,4096,output);
NSLog(@"%s\n",buffer);

The variable "output" is of type "FILE *" and the NSLog do not execute,
what am I doing wrong?

Thanks in advance,

Jorge Salvador Caffarena
http://homepage.mac.com/eevyl/


  • Prev by Date: Re: How doess Cocoa handle SIGINT?
  • Next by Date: Re: Using file types in Document Based Applications...
  • Previous by thread: Re: field editor oddness
  • Next by thread: Undo in NSTextField?
  • Index(es):
    • Date
    • Thread