[launchd-dev] (re)configure a launchd created UNIX domain socket after Fast User Switching (on El Capitan)

Ludovic Rousseau ludovic.rousseau at gmail.com
Thu Feb 25 05:43:14 PST 2016


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.

It works fine except when Fast User Switching is involved.

My problem is quite similar to the problem "Listening socket and fast user
switching" [1] discussed on this mailing list in 2008. The difference is
that I am using a UNIX domain socket and not a TCP socket.

The problematic scenario is as follows:
1. User A logs in
2. User A can connect to the socket

3. User B logs in using the Fast User Switching
4. User B can connect to the socket
5. User B logs out

6. User A comes back and fast user switch to his session. Since user A
   does not _logs in_ again the socket is not changed/recreated and is still
   only usable by user B

At this step user A gets:
$ telnet /tmp/foobar.socket
Trying /tmp/foobar.socket...
/tmp/foobar.socket: Connection refused

The socket is still present in /tmp/ but it belongs to user B and is no
more usable but user A.

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.

- I use a UNIX domain socket so that only local processes can talk to the
socket and use my agent. I don't want to open my agent to other computer on
the network.
- I use launchd to start my agent on request only. That is a very nice
feature. I can't detect the user switching since my agent code is, most of
the time, not running.
- I can'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.

My /Library/LaunchAgents/com.foobar.plist file contains:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "
<plist version="1.0">

Does launchd provides a solution to my problem?

Should I open a bug at Apple to ask for this new feature in launchd?


[1] https://lists.macosforge.org/pipermail/launchd-dev/2008-May/000298.html

 Dr. Ludovic Rousseau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/launchd-dev/attachments/20160225/43aa687f/attachment.html>

More information about the launchd-dev mailing list