diff options
Diffstat (limited to 'src/libstddjb/ipc_bind_reuse_lock.c')
| -rw-r--r-- | src/libstddjb/ipc_bind_reuse_lock.c | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/src/libstddjb/ipc_bind_reuse_lock.c b/src/libstddjb/ipc_bind_reuse_lock.c deleted file mode 100644 index 09e440c..0000000 --- a/src/libstddjb/ipc_bind_reuse_lock.c +++ /dev/null @@ -1,35 +0,0 @@ -/* ISC license. */ - -#include <skalibs/nonposix.h> - -#include <fcntl.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <sys/socket.h> - -#include <skalibs/djbunix.h> -#include <skalibs/socket.h> - -int ipc_bind_reuse_lock (int s, char const *p, int *fdlock) -{ - unsigned int opt = 1 ; - size_t len = strlen(p) ; - int fd ; - int r ; - char lockname[len + 6] ; - memcpy(lockname, p, len) ; - memcpy(lockname + len, ".lock", 6) ; - fd = open3(lockname, O_WRONLY | O_NONBLOCK | O_CREAT | O_CLOEXEC, 0600) ; - if (fd < 0) return -1 ; - r = fd_lock(fd, 1, 1) ; - if (r < 0) return -1 ; - if (!r) return (errno = EBUSY, -1) ; - r = errno ; - setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof opt) ; - errno = r ; - unlink_void(p) ; - if (ipc_bind(s, p) < 0) return -1 ; - *fdlock = fd ; - return 0 ; -} |
