ia64/xen-unstable

changeset 13017:d2f12edc10ee

Set FD_CLOEXEC on the pidfile fd, so that tapdisk does not get it.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Dec 14 10:31:31 2006 +0000 (2006-12-14)
parents ac51e8f37108
children fe2e013ae5cb
files tools/blktap/drivers/blktapctrl.c
line diff
     1.1 --- a/tools/blktap/drivers/blktapctrl.c	Thu Dec 14 10:29:44 2006 +0000
     1.2 +++ b/tools/blktap/drivers/blktapctrl.c	Thu Dec 14 10:31:31 2006 +0000
     1.3 @@ -629,6 +629,7 @@ static void write_pidfile(long pid)
     1.4  	char buf[100];
     1.5  	int len;
     1.6  	int fd;
     1.7 +	int flags;
     1.8  
     1.9  	fd = open(PIDFILE, O_RDWR | O_CREAT, 0600);
    1.10  	if (fd == -1) {
    1.11 @@ -640,6 +641,18 @@ static void write_pidfile(long pid)
    1.12  	if (lockf(fd, F_TLOCK, 0) == -1)
    1.13  		exit(0);
    1.14  
    1.15 +	/* Set FD_CLOEXEC, so that tapdisk doesn't get this file
    1.16 +	   descriptor. */
    1.17 +	if ((flags = fcntl(fd, F_GETFD)) == -1) {
    1.18 +		DPRINTF("F_GETFD failed (%d)\n", errno);
    1.19 +		exit(1);
    1.20 +	}
    1.21 +	flags |= FD_CLOEXEC;
    1.22 +	if (fcntl(fd, F_SETFD, flags) == -1) {
    1.23 +		DPRINTF("F_SETFD failed (%d)\n", errno);
    1.24 +		exit(1);
    1.25 +	}
    1.26 +
    1.27  	len = sprintf(buf, "%ld\n", pid);
    1.28  	if (write(fd, buf, len) != len) {
    1.29  		DPRINTF("Writing pid file failed (%d)\n", errno);