Use fcntl instead of lockf

#250
This commit is contained in:
ruti 2025-01-18 15:08:39 +03:00
parent 7b46e5958f
commit 1d85d015c2

10
main.c
View File

@ -18,9 +18,6 @@
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <sys/socket.h> #include <sys/socket.h>
#ifndef F_TLOCK
#define lockf(x, y, z) 0
#endif
#define DAEMON #define DAEMON
#else #else
#include <ws2tcpip.h> #include <ws2tcpip.h>
@ -546,7 +543,11 @@ int init_pid_file(const char *fname)
if (params.pid_fd < 0) { if (params.pid_fd < 0) {
return -1; return -1;
} }
if (lockf(params.pid_fd, F_TLOCK, 0) < 0) { struct flock fl = {
.l_whence = SEEK_CUR,
.l_type = F_WRLCK
};
if (fcntl(params.pid_fd, F_SETLK, &fl) < 0) {
return -1; return -1;
} }
params.pid_file = fname; params.pid_file = fname;
@ -566,7 +567,6 @@ void clear_params(void)
#endif #endif
#ifdef DAEMON #ifdef DAEMON
if (params.pid_fd > 0) { if (params.pid_fd > 0) {
lockf(params.pid_fd, F_ULOCK, 0);
close(params.pid_fd); close(params.pid_fd);
} }
if (params.pid_file) { if (params.pid_file) {