Gama
Gama

Reputation: 374

LaunchD spawning two instances of LaunchAgent

I have this application that is divided in 3 parts.

Goals

My current set up using LaunchD is as follows.

My Server process plist (relevant part) saved in System/LaunchDaemons

key>MachServices</key>
<dict>
    <key>com.myCompany.Agent.xpc</key>
    <true/>
    <key>com.myCompany.Manager.xpc</key>
    <true/>
</dict>
<key>ProgramArguments</key>
<array>
    <string>PathToExecutable</string>
    <string>-service</string>
</array>
<key>RunAtLoad</key>
<false/>

My agent plist (saved in System/LaunchAgent)

<key>QueueDirectories</key>
<array>
    <string>PathToDirectory</string>
</array>
<key>RunAtLoad</key>
<false/>
<key>ProgramArguments</key>
<array>
    <string>PathToExecutable</string>
    <string>service</string>
</array>

my Manager app plist (saved in System/LaunchAgent)

<key>LimitLoadToSessionType</key>
        <string>Aqua</string>
    <key>RunAtLoad</key>
        <false/>
    <key>ProgramArguments</key>
        <array>
            <string>PathToExecutable</string>
        </array>
    <key>MachServices</key>
        <dict>
            <key>com.myCompany.Agent.manager.xpc</key>
            <true/>
        </dict>

Currently I have another app that saves a file to the path of the QueueDirectories which triggers the launch of my Agent which then triggers the Server and Manager by starting a XPC Connection. QueueDirectories keeps the Agent alive (and hence all other processes) til file is removed and processes are quited through the manager.

XPC Connections

Agent and Manager are owned by the user and server by root

The problems

When I start Agent by saving a file in the QueueDirectories path and connect to the Server over xpc I end up with two Agents, one owned by the user (the one I expect) and one owned by root.

But if I manually start the Agent I do not have that problem.

As I mentioned before, the server listens for a connection from the Agent.

How do I stop getting two instances? or what is a better way to approach this?

Upvotes: 1

Views: 53

Answers (0)

Related Questions