[launchd-dev] Setting up an AF_UNIX based launchd server
mailist at ericgorr.net
mailist at ericgorr.net
Mon Jul 25 04:04:48 PDT 2011
On Mon, 25 Jul 2011 10:51:51 +0100, Quinn "The Eskimo!" wrote:
> On 24 Jul 2011, at 23:15, mailist at ericgorr.net wrote:
>
>> One question is how should /var/tmp/net.ericgorr.testserver/Socket
>> be created?
>
> This is your fundamental problem. The launchd infrastructure will
> take care of creating the UNIX domain socket for you, but it won't
> create intermediate directories. So the socket has to live within a
> directory that already exists. The standard path is for your service
> would be "/var/run/net.ericgorr.testserver.socket" ("/var/run" not
> "/var/tmp", and ".socket" not "/socket").
Ok. So, using /var/run and .socket also takes care of the issue
mentioned in the CFLocalServer sample code:
// This routine is called to safely bind the UNIX domain socket
// specified by sockFD to the path specificed by socketPath. To avoid
// security problems, socketPath must point it to a sticky directory
// (such as "/var/tmp"). This allows us to create the socket with
// very specific permissions, without us having to worry about a
malicious
// process switching stuff out from underneath us.
I got a little farther, but my client still won't connect. After
rebuilding the server and loading it into launchd, I do see:
srw-rw-rw- 1 root daemon 0 Jul 25 06:54
net.ericgorr.testserver.socket=
in /var/run
In common.h, I now have:
#define kServerSocketPath "/var/run/net.ericgorr.testserver.socket"
and the client_connect function in the client code remained:
int client_connect( void )
{
int socketFD = socket( AF_UNIX, SOCK_STREAM, 0 );
assert( socketFD != -1 );
struct sockaddr_un addr;
addr.sun_len = sizeof( addr );
addr.sun_family = AF_UNIX;
strcpy( addr.sun_path, kServerSocketPath );
int result;
int err;
result = connect( socketFD, (struct sockaddr *)&socketFD, sizeof(
socketFD ) );
err = MoreUNIXErrno( result );
CFShow( CFStringCreateWithFormat( NULL, NULL, CFSTR(
"client_connect: %d" ), err ) );
assert( err == 0 );
return socketFD;
}
However, errno is still set to 2.
I have updated the sample project at:
http://ericgorr.net/pq/AF_UNIX.zip
Thank you.
More information about the launchd-dev
mailing list