diff --git a/main.c b/main.c index 0ce06c3..6eb85a9 100644 --- a/main.c +++ b/main.c @@ -18,9 +18,6 @@ #include #include - #ifndef F_TLOCK - #define lockf(x, y, z) 0 - #endif #define DAEMON #else #include @@ -546,7 +543,11 @@ int init_pid_file(const char *fname) if (params.pid_fd < 0) { 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; } params.pid_file = fname; @@ -566,7 +567,6 @@ void clear_params(void) #endif #ifdef DAEMON if (params.pid_fd > 0) { - lockf(params.pid_fd, F_ULOCK, 0); close(params.pid_fd); } if (params.pid_file) {