summaryrefslogtreecommitdiff
path: root/source3/lib/util_sock.c
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-12-05 00:13:17 +0000
committerLuke Leighton <lkcl@samba.org>1999-12-05 00:13:17 +0000
commit854f35e20fa4748312e4b0fbae6bb38342ab0389 (patch)
treef3fd0a7de90630a4442e54f6214966dd923a3003 /source3/lib/util_sock.c
parentddda7722a673cefc89a55133f99c07dd153b1f19 (diff)
downloadsamba-854f35e20fa4748312e4b0fbae6bb38342ab0389.tar.gz
samba-854f35e20fa4748312e4b0fbae6bb38342ab0389.tar.bz2
samba-854f35e20fa4748312e4b0fbae6bb38342ab0389.zip
created create_pipe_socket() function.
(This used to be commit a3af3b4312144943413894b18b5845b56474ebb5)
Diffstat (limited to 'source3/lib/util_sock.c')
-rw-r--r--source3/lib/util_sock.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index c0ca723e38..71e51d2771 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -894,3 +894,65 @@ int open_pipe_sock(char *path)
return sock;
}
+
+int create_pipe_socket(char *dir, int dir_perms,
+ char *path, int path_perms)
+{
+ int s;
+ struct sockaddr_un sa;
+
+ mkdir(dir, dir_perms);
+
+ if (chmod(dir, dir_perms) < 0)
+ {
+ DEBUG(0, ("chmod on %s failed\n", dir));
+ return -1;
+ }
+
+ if (!remove(path))
+ {
+ DEBUG(0, ("remove on %s failed\n", path));
+ return -1;
+ }
+
+ /* start listening on unix socket */
+ s = socket(AF_UNIX, SOCK_STREAM, 0);
+
+ if (s < 0)
+ {
+ DEBUG(0, ("socket open failed\n"));
+ return -1;
+ }
+
+ ZERO_STRUCT(sa);
+ sa.sun_family = AF_UNIX;
+ safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path)-1);
+
+ if (bind(s, (struct sockaddr*) &sa, sizeof(sa)) < 0)
+ {
+ DEBUG(0, ("socket bind to %s failed\n", sa.sun_path));
+ close(s);
+ remove(path);
+ return -1;
+ }
+
+ if (s == -1)
+ {
+ DEBUG(0,("bind failed\n"));
+ remove(path);
+ return -1;
+ }
+
+ if (path_perms != 0)
+ {
+ chmod(path, path_perms);
+ }
+
+ if (listen(s, 5) == -1)
+ {
+ DEBUG(0,("listen failed\n"));
+ return -1;
+ }
+
+ return s;
+}