- int result;
- int fd;
- char pidstr[6];
- int pidlen;
-
- struct sockaddr_un addr;
-
- result = fd = socket(PF_UNIX, SOCK_DGRAM, 0);
- if(result == -1) {
- PERROR("socket");
- return -1;
- }
-
- addr.sun_family = AF_UNIX;
-
- result = snprintf(addr.sun_path, UNIX_PATH_MAX, "%s/%d", SOCKETDIR, mypid);
- if(result >= UNIX_PATH_MAX) {
- ERR("string overflow allocating socket name");
- goto close_sock;
- }
- //DBG("opening socket at %s", addr.sun_path);
-
- result = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
- if(result == -1) {
- PERROR("bind");
- goto close_sock;
- }
-
- strcpy(mysocketfile, addr.sun_path);
-
- pfd = fd;
- return 0;
-
- close_sock:
- close(fd);
-
- return -1;