1 /* opensock.c - open a unix domain socket */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2007 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Brian Candler for inclusion
18 * in OpenLDAP Software.
26 #include <ac/string.h>
27 #include <ac/socket.h>
28 #include <ac/unistd.h>
31 #include "back-sock.h"
34 * FIXME: count the number of concurrent open sockets (since each thread
35 * may open one). Perhaps block here if a soft limit is reached, and fail
36 * if a hard limit reached
46 struct sockaddr_un sockun;
48 fd = socket(PF_UNIX, SOCK_STREAM, 0);
50 Debug( LDAP_DEBUG_ANY, "socket create failed\n", 0, 0, 0 );
54 sockun.sun_family = AF_UNIX;
55 sprintf(sockun.sun_path, "%.*s", (int)(sizeof(sockun.sun_path)-1),
57 if ( connect( fd, (struct sockaddr *)&sockun, sizeof(sockun) ) < 0 ) {
58 Debug( LDAP_DEBUG_ANY, "socket connect(%s) failed\n",
59 sockpath ? sockpath : "<null>", 0, 0 );
63 if ( ( fp = fdopen( fd, "r+" ) ) == NULL ) {
64 Debug( LDAP_DEBUG_ANY, "fdopen failed\n", 0, 0, 0 );