How to run multiple instances of an application using startup?

My application is divided into two parts. The main application and auxiliary tool. A helper tool performs a task with higher resolutions.

The launch plugin is as follows: (Only important settings are included.)

<key>UserName</key>
<string>root</string>
<key>ProgramArguments</key>
<array>
    <string>/Library/PrivilegedHelperTools/helperTool</string>
</array>
<key>Sockets</key>
<dict>
    <key>IPC</key>
    <dict>
        <key>SockPathName</key>
        <string>/tmp/TheSocket</string>
    </dict>
</dict>

Is there a way to start a new helper instance for each socket connection?

Or, alternatively, is there an existing template to handle multiple requests? (I am doing this myself at the moment, which is pretty much ugly code.)

+5
source share
1 answer

This is probably my first answer on Stackoverflow :)

First, set inetdCompatibility to Wait to false. This will force launchd to accept the socket.

<key>inetdCompatibility</key>
<dict>
    <key>Instances</key>
    <integer>42</integer>
    <key>Wait</key>
    <false/>
</dict>

, launchd . STDIN_FILENO. : ( sshd )

int sock_in;
int sock_out;           
sock_in = sock_out = dup(STDIN_FILENO);
NSLog(@"socket descriptor: %d", sock_in);

sock_in . , accept.

, plist, . , . launchdd 18411 TCP- IPv4.

<key>Sockets</key>
<dict>
    <key>Listeners</key>
    <dict>
        <key>SockServiceName</key>
        <string>18411</string>
        <key>SockType</key>
        <string>stream</string>
        <key>SockFamily</key>
        <string>IPv4</string>
    </dict>
</dict>
+1

All Articles