Richard W.M. Jones
2009-Aug-06 14:56 UTC
[Libguestfs] [PATCH] RHEL5 fix: no inotify_init1 in RHEL 5
-- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/ -------------- next part -------------->From 82ef93775e63cf08a22c293043dbd333065b7408 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at trick.home.annexia.org> Date: Thu, 6 Aug 2009 15:44:20 +0100 Subject: [PATCH 1/2] RHEL 5: inotify_init1 call did not exist on RHEL 5. --- daemon/configure.ac | 2 +- daemon/inotify.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletions(-) diff --git a/daemon/configure.ac b/daemon/configure.ac index 126e125..b038d17 100644 --- a/daemon/configure.ac +++ b/daemon/configure.ac @@ -67,7 +67,7 @@ AC_CHECK_LIB([portablexdr],[xdrmem_create],[],[ ]) dnl Functions which may not be available in older distributions. -AC_CHECK_FUNCS([futimens listxattr llistxattr getxattr lgetxattr setxattr lsetxattr removexattr lremovexattr]) +AC_CHECK_FUNCS([futimens listxattr llistxattr getxattr lgetxattr setxattr lsetxattr removexattr lremovexattr inotify_init1]) dnl For modified printf, we need glibc either (old-style) dnl register_printf_function or (new-style) register_printf_specifier. diff --git a/daemon/inotify.c b/daemon/inotify.c index 4bc6f17..1b90f2b 100644 --- a/daemon/inotify.c +++ b/daemon/inotify.c @@ -21,6 +21,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> +#include <fcntl.h> #include <sys/inotify.h> #include "../src/guestfs_protocol.h" @@ -70,11 +72,31 @@ do_inotify_init (int max_events) if (do_inotify_close () == -1) return -1; +#ifdef HAVE_INOTIFY_INIT1 inotify_fd = inotify_init1 (IN_NONBLOCK | IN_CLOEXEC); if (inotify_fd == -1) { reply_with_perror ("inotify_init"); return -1; } +#else + inotify_fd = inotify_init (); + if (inotify_fd == -1) { + reply_with_perror ("inotify_init"); + return -1; + } + if (fcntl (inotify_fd, F_SETFL, O_NONBLOCK) == -1) { + reply_with_perror ("fcntl: O_NONBLOCK"); + close (inotify_fd); + inotify_fd = -1; + return -1; + } + if (fcntl (inotify_fd, F_SETFD, FD_CLOEXEC) == -1) { + reply_with_perror ("fcntl: FD_CLOEXEC"); + close (inotify_fd); + inotify_fd = -1; + return -1; + } +#endif return 0; } -- 1.6.2.5