Re: Communicating with Privileged Helper Tool
Re: Communicating with Privileged Helper Tool
- Subject: Re: Communicating with Privileged Helper Tool
- From: Damien DeVille <email@hidden>
- Date: Mon, 28 Dec 2015 15:56:28 +0000
I suspect the problem is that your GUI application cannot find the helper’s Mach service because they are not in the same bootstrap domain.
When using xpc, one can use `XPC_CONNECTION_MACH_SERVICE_PRIVILEGED` or `NSXPCConnectionPrivileged` to connect from a user process to a listener in the root domain. I’m not sure how to achieve this with `CFMachPort` directly… You mentioned supporting 10.6, if you’re able to bump it to 10.7 I’d suggest going with xpc.
> The helper tool *is* launched by launchd, however if I add the MachService name to the plist, won't that mean the connection is going the wrong way? I want the GUI to listen for connections from the helper tool.
I see. Yes, if you add the Mach service to the job plist the helper tool will be the listener. However, I guess your helper tool is initially launched due to an action from the GUI? If so, it would make sense to have the tool be the listener and the GUI connecting to it. You could also load the helper tool on demand the first time the GUI tries to message said Mach service.
Thanks,
Damien
> On Dec 23, 2015, at 6:04 PM, Mark Allan <email@hidden> wrote:
>
> Hi Damien,
>
> Thanks for replying.
>
>> On 23 Dec 2015, at 5:18 pm, Damien DeVille <email@hidden> wrote:
>>
>>> Unfortunately, this gives me the exact same issue:
>>
>> How are you creating the other end of the connection? The remote port will just attempt to connect to the local port and not actually register the mach service. If you never registered the mach service name it will fail as you’re seeing.
>
> Oops, sorry for missing this out. Here's the code in my main GUI application:
>
> CFMessagePortRef localPort = CFMessagePortCreateLocal(NULL, CFSTR("com.example.app.port.server"), Callback, nil, nil);
> if (!localPort) {
> NSLog(@"couldn't open localport");
> }
> CFRunLoopSourceRef runLoopSource = CFMessagePortCreateRunLoopSource(nil, localPort, 0);
> CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
>
> I know the port is getting created, as I can connect from another GUI app, I just can't connect from the helper tool.
>
> I'm using the following to try and connect to it from the helper tool:
>
> CFMessagePortRef remotePort = CFMessagePortCreateRemote(NULL, CFSTR("com.example.app.port.server"));
>
>> You can use `CFMessagePortCreateLocal` in you helper tool. This function will take care of registering the service name with the bootstrap server (on top of giving you a port to listen on). If you’re using objc you can register your mach port directly by calling `NSMachBootstrapServer.registerPort:name:`.
>>
>> If you helper tool is launched by launchd, you can add the MachService name to your job plist and launchd will bootstrap it in the right domain for you.
>
> The helper tool *is* launched by launchd, however if I add the MachService name to the plist, won't that mean the connection is going the wrong way? I want the GUI to listen for connections from the helper tool.
>
> Thanks again
> Mark
>
_______________________________________________
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