summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2007-09-10 16:52:17 +0000
committerLennart Poettering <lennart@poettering.net>2007-09-10 16:52:17 +0000
commita205fe19b78d44170661dbb624b5166220254f72 (patch)
treec2246c01977d0bf5b7807a25240a3a05d5941c8e
parentde3559167423a17422b97ca93b82b7995d0876e9 (diff)
if opening the pid file on O_RDWR doesn't work, fallback to O_RDONLY
git-svn-id: file:///home/lennart/svn/public/libdaemon/trunk@131 153bfa13-eec0-0310-be40-b0cb6a0e1b4b
-rw-r--r--libdaemon/dpid.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/libdaemon/dpid.c b/libdaemon/dpid.c
index 125fada..39c87f4 100644
--- a/libdaemon/dpid.c
+++ b/libdaemon/dpid.c
@@ -69,6 +69,14 @@ static int lock_file(int fd, int enable) {
f.l_len = 0;
if (fcntl(fd, F_SETLKW, &f) < 0) {
+
+ if (enable && errno == EBADF) {
+ f.l_type = F_RDLCK;
+
+ if (fcntl(fd, F_SETLKW, &f) >= 0)
+ return 0;
+ }
+
daemon_log(LOG_WARNING, "fcntl(F_SETLKW) failed: %s", strerror(errno));
return -1;
}
@@ -91,10 +99,12 @@ pid_t daemon_pid_file_is_running(void) {
}
if ((fd = open(fn, O_RDWR, 0644)) < 0) {
- if (errno != ENOENT)
- daemon_log(LOG_WARNING, "Failed to open PID file: %s", strerror(errno));
+ if ((fd = open(fn, O_RDONLY, 0644)) < 0) {
+ if (errno != ENOENT)
+ daemon_log(LOG_WARNING, "Failed to open PID file: %s", strerror(errno));
- goto finish;
+ goto finish;
+ }
}
if ((locked = lock_file(fd, 1)) < 0)