diff options
| author | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-02-10 15:38:14 +0000 |
|---|---|---|
| committer | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-02-10 15:38:14 +0000 |
| commit | bf75d6af1c573fea1043c81cdeb2c634dedb240c (patch) | |
| tree | d9f39d5141832f5bd466f95df8875646ee566017 | |
| parent | 7dedb28137dd5c08c30ca27f4e576fd8f9f3b593 (diff) | |
| download | btpd-bf75d6af1c573fea1043c81cdeb2c634dedb240c.tar.gz btpd-bf75d6af1c573fea1043c81cdeb2c634dedb240c.zip | |
Glibc doesn't support locking in open. Use flock after open instead.
| -rw-r--r-- | btpd/main.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/btpd/main.c b/btpd/main.c index 7d11d64..97690fe 100644 --- a/btpd/main.c +++ b/btpd/main.c @@ -5,6 +5,7 @@ #include <err.h> #include <errno.h> #include <fcntl.h> +#include <file.h> #include <getopt.h> #include <locale.h> #include <stdio.h> @@ -45,14 +46,11 @@ setup_daemon(int daemonize, const char *dir, const char *log) if (mkdir("torrents", 0777) == -1 && errno != EEXIST) err(1, "Couldn't create torrents subdir"); - pidfd = open("pid", O_CREAT|O_WRONLY|O_NONBLOCK|O_EXLOCK, 0666); - if (pidfd == -1) { - if (errno == EAGAIN) - errx(1, "Another instance of btpd is probably running in %s.", - dir); - else - err(1, "Couldn't open 'pid'"); - } + if ((pidfd = open("pid", O_CREAT|O_WRONLY, 0666)) == -1) + err(1, "Couldn't open 'pid'"); + + if (flock(pidfd, LOCK_NB|LOCK_EX) == -1) + errx(1, "Another instance of btpd is probably running in %s.", dir); if (daemonize) { if (daemon(1, 1) != 0) |