#include #include #include #include #include #define sock_path "/tmp/.s.PGSQL.5432" main() { struct sockaddr_un saddr; int fd, lock_fd; memset((char *) &saddr, 0, sizeof(saddr)); saddr.sun_family = AF_UNIX; strcpy(saddr.sun_path, sock_path); fd=socket(PF_UNIX, SOCK_STREAM, 0); if (fd>=0) { bind(fd, &saddr, SUN_LEN(&saddr)); if ((lock_fd = open(sock_path, O_WRONLY | O_NONBLOCK, 0666)) >= 0) { struct flock lck; lck.l_whence = SEEK_SET; lck.l_start = lck.l_len = 0; lck.l_type = F_WRLCK; fcntl(lock_fd, F_SETLK, &lck); } } }