<div dir="ltr"><div><div><div><div><div>Hello,<br><br></div>I am using launchd to create a Unix domain socket /tmp/foobar.socket so that launchd starts my agent when someone connects to the sockets.<br><br></div>It works fine except when Fast User Switching is involved.<br><br><div>My problem is quite similar to the problem &quot;Listening socket and 
fast user switching&quot; [1] discussed on this mailing list in 2008. The difference is that I am using a
 UNIX domain socket and not a TCP socket.<br></div><br><br></div>The problematic scenario is as follows:<br></div>1. User A logs in<br>2. User A can connect to the socket<br><br>3. User B logs in using the Fast User Switching<br>4. User B can connect to the socket<br>5. User B logs out<br></div><br><div>6. User A comes back and fast user switch to his session. Since user A<br>   does not _logs in_ again the socket is not changed/recreated and is still<br>   only usable by user B<br><br></div><div>At this step user A gets:<br>$ telnet /tmp/foobar.socket<br>Trying /tmp/foobar.socket...<br>/tmp/foobar.socket: Connection refused<br clear="all"></div><div><div><div><div><div><div><br></div><div>The socket is still present in /tmp/ but it belongs to user B and is no more usable but user A.<br><br></div><div>What I would like is the ability for launchd to (re)configure the Unix domain socket each time a user authenticates to the console, either the first time or using the fast user switching method.<br><br><br></div><div>- I use a UNIX domain socket so that only local processes can talk to the socket and use my agent. I don&#39;t want to open my agent to other computer on the network.<br></div><div>- I use launchd to start my agent on request only. That is a very nice feature. I can&#39;t detect the user switching since my agent code is, most of the time, not running.<br></div><div>- I can&#39;t use a different socket name per user since the client of my agent does not know who is currently logged. My client application is talking to the socket configured for whoever is logged at that time.<br></div><br><br><div>My /Library/LaunchAgents/com.foobar.plist file contains:<br><br>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;<a href="http://www.apple.com/DTDs/PropertyList-1.0.dtd">http://www.apple.com/DTDs/PropertyList-1.0.dtd</a>&quot;&gt;<br>&lt;plist version=&quot;1.0&quot;&gt;<br>&lt;dict&gt;<br>    &lt;key&gt;Label&lt;/key&gt;<br>    &lt;string&gt;com.foobar&lt;/string&gt;<br>    &lt;key&gt;ProgramArguments&lt;/key&gt;<br>    &lt;array&gt;<br>        &lt;string&gt;/usr/local/lib/foobar_exe&lt;/string&gt;<br>    &lt;/array&gt;<br>    &lt;key&gt;Sockets&lt;/key&gt;<br>    &lt;dict&gt;<br>        &lt;key&gt;Listeners&lt;/key&gt;<br>        &lt;dict&gt;<br>            &lt;key&gt;SockPathName&lt;/key&gt;<br>            &lt;string&gt;/tmp/foobar.socket&lt;/string&gt;<br>        &lt;/dict&gt;<br>    &lt;/dict&gt;<br>    &lt;key&gt;ProcessType&lt;/key&gt;<br>    &lt;string&gt;Interactive&lt;/string&gt;<br>&lt;/dict&gt;<br>&lt;/plist&gt;<br><br><br></div><div>Does launchd provides a solution to my problem?<br></div><div><br>Should I open a bug at Apple to ask for this new feature in launchd?<br><br></div><div>Thanks<br></div><div><br></div>[1] <a href="https://lists.macosforge.org/pipermail/launchd-dev/2008-May/000298.html" target="_blank">https://lists.macosforge.org/pipermail/launchd-dev/2008-May/000298.html</a><br><div><br></div><div>-- <br><div> Dr. Ludovic Rousseau</div>
</div></div></div></div></div></div></div>