From 648aeae3bcd1353644b94e9ab1c2df18cb23e14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 26 Nov 2009 14:22:35 +0000 Subject: [PATCH] * Properly fixed libutil; we should not use O_TRUNC before having exclusive access to the file. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34281 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/libs/util/pidfile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/util/pidfile.c b/src/libs/util/pidfile.c index 092b9a3a1d..0c2d68aaa0 100644 --- a/src/libs/util/pidfile.c +++ b/src/libs/util/pidfile.c @@ -112,9 +112,7 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr) * PID file will be truncated again in pidfile_write(), so * pidfile_write() can be called multiple times. */ - fd = open(pfh->pf_path, - O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode); - + fd = open(pfh->pf_path, O_WRONLY | O_CREAT | O_NONBLOCK, mode); if (fd >= 0) { struct flock lock; lock.l_type = F_WRLCK; @@ -122,7 +120,7 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr) lock.l_start = 0; lock.l_len = 0; - if (fcntl(F_SETLK, &lock) == -1) { + if (fcntl(fd, F_SETLK, &lock) == -1) { close(fd); fd = -1; } @@ -138,6 +136,8 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr) return (NULL); } + ftruncate(fd, 0); + /* * Remember file information, so in pidfile_write() we are sure we write * to the proper descriptor.