mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
Set FD_CLOEXEC on the pidfile fd, so that tapdisk does not get it.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
1 parent
e6be7d74b9
commit
62184014df
1 file changed
+13
@@ -629,6 +629,7 @@ static void write_pidfile(long pid)
|
||||
char buf[100];
|
||||
int len;
|
||||
int fd;
|
||||
int flags;
|
||||
|
||||
fd = open(PIDFILE, O_RDWR | O_CREAT, 0600);
|
||||
if (fd == -1) {
|
||||
@@ -640,6 +641,18 @@ static void write_pidfile(long pid)
|
||||
if (lockf(fd, F_TLOCK, 0) == -1)
|
||||
exit(0);
|
||||
|
||||
/* Set FD_CLOEXEC, so that tapdisk doesn't get this file
|
||||
descriptor. */
|
||||
if ((flags = fcntl(fd, F_GETFD)) == -1) {
|
||||
DPRINTF("F_GETFD failed (%d)\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
flags |= FD_CLOEXEC;
|
||||
if (fcntl(fd, F_SETFD, flags) == -1) {
|
||||
DPRINTF("F_SETFD failed (%d)\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
len = sprintf(buf, "%ld\n", pid);
|
||||
if (write(fd, buf, len) != len) {
|
||||
DPRINTF("Writing pid file failed (%d)\n", errno);
|
||||
|
||||