This causes a race. If 2 callers to pidfile_create() both a find a
stale PID file using pidfile_pid(). The 1st may then return to
pidfile_create() and create a new PID file, which can then be unlinked
by the 2nd caller.
Consequently, PID file creation can not depend on creating the file,
so drop O_EXCL from the call to open().
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Volker Lendecke <vl@samba.org>
-/* this code is broken - there is a race condition with the unlink (tridge) */
-
/*
Unix SMB/CIFS implementation.
pidfile handling
noproc:
close(fd);
- DEBUG(10, ("Deleting %s, since %d is not a Samba process.\n", pidFile,
- (int)ret));
- unlink(pidFile);
return 0;
}
exit(1);
}
- fd = open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY | O_EXCL, 0644);
+ fd = open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY, 0644);
if (fd == -1) {
DEBUG(0,("ERROR: can't open %s: Error was %s\n", pidFile,
strerror(errno)));