Signed-off-by: Jan Beulich --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -199,11 +199,25 @@ static int acquire_lock(void) fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif fd_lock = open(lockfile, O_WRONLY|O_CREAT|O_CLOEXEC, S_IWUSR); if (fd_lock < 0) { fprintf(stderr, "cannot open the lockfile %s errno=%d\n", lockfile, errno); return ERROR_FAIL; } +#if !O_CLOEXEC + { + int flags = fcntl(fd_lock, F_GETFD); + + if (flags < 0 || + fcntl(fd_lock, F_SETFD, flags | FD_CLOEXEC) < 0) + fprintf(stderr, + "cannot mark lockfile %s close-on-exec errno=%d\n", + lockfile, errno); + } +#endif get_lock: rc = fcntl(fd_lock, F_SETLKW, &fl); if (rc < 0 && errno == EINTR)