[launchd-dev] Listening socket and fast user switching

Dave Dribin dave-ml at dribin.org
Thu May 22 11:38:58 PDT 2008


Hello,

I'm writing a launchd agent that opens a TCP listening socket.   
Ideally, I'd like launchd to open and listen to the socket via  
SockServiceName so my agent only gets launched as-needed.

The problem is I'd like to listen to the same port (e.g. 12345), no  
matter which user is logged in.  This is fine when there's only one  
user logged in, but as soon as fast user switching comes into play,  
the socket gets an "address already in use" when the second user logs  
in.

This is to be expected, I suppose.  But is there any way to have  
launchd only listen to the socket when the user is the "active" user,  
and have it *not* listen when the user gets switched out, due to fast  
user switching?

At first glance the LimitLoadToSessionType looked promising, but it  
doesn't look like any of those will do that.

The solution I'm currently entertaining uses launchd to always launch  
my agent, and have my agent do the socket listening.  I can then use  
the user switch notification to close down the listening port when the  
session is deactivated and open it when activated.

Thanks,

-Dave



More information about the launchd-dev mailing list