Make virtio block driver be the default for the appliance.
[libguestfs.git] / daemon / inotify.c
index 96b9681..24ce76e 100644 (file)
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+
+#ifdef HAVE_SYS_INOTIFY_H
 #include <sys/inotify.h>
+#endif
 
 #include "../src/guestfs_protocol.h"
 #include "daemon.h"
 #include "actions.h"
+#include "optgroups.h"
 
+#ifdef HAVE_SYS_INOTIFY_H
 /* Currently open inotify handle, or -1 if not opened. */
 static int inotify_fd = -1;
 
 static char inotify_buf[64*1024*1024]; /* Event buffer, [0..posn-1] is valid */
 static size_t inotify_posn = 0;
 
+int
+optgroup_inotify_available (void)
+{
+  return 1;
+}
+#else /* !HAVE_SYS_INOTIFY_H */
+int
+optgroup_inotify_available (void)
+{
+  return 0;
+}
+#endif
+
 /* Because inotify_init does NEED_ROOT, NEED_INOTIFY implies NEED_ROOT. */
 #define NEED_INOTIFY(errcode)                                          \
   do {                                                                 \
@@ -49,6 +67,7 @@ static size_t inotify_posn = 0;
 int
 do_inotify_init (int max_events)
 {
+#ifdef HAVE_SYS_INOTIFY_H
   FILE *fp;
 
   NEED_ROOT (return -1);
@@ -99,11 +118,15 @@ do_inotify_init (int max_events)
 #endif
 
   return 0;
+#else
+  NOT_AVAILABLE (-1);
+#endif
 }
 
 int
 do_inotify_close (void)
 {
+#ifdef HAVE_SYS_INOTIFY_H
   NEED_INOTIFY (-1);
 
   if (inotify_fd == -1) {
@@ -120,16 +143,19 @@ do_inotify_close (void)
   inotify_posn = 0;
 
   return 0;
+#else
+  NOT_AVAILABLE (-1);
+#endif
 }
 
 int64_t
-do_inotify_add_watch (char *path, int mask)
+do_inotify_add_watch (const char *path, int mask)
 {
+#ifdef HAVE_SYS_INOTIFY_H
   int64_t r;
   char *buf;
 
   NEED_INOTIFY (-1);
-  ABS_PATH (path, return -1);
 
   buf = sysroot_path (path);
   if (!buf) {
@@ -145,11 +171,15 @@ do_inotify_add_watch (char *path, int mask)
   }
 
   return r;
+#else
+  NOT_AVAILABLE (-1);
+#endif
 }
 
 int
 do_inotify_rm_watch (int wd)
 {
+#ifdef HAVE_SYS_INOTIFY_H
   NEED_INOTIFY (-1);
 
   if (inotify_rm_watch (inotify_fd, wd) == -1) {
@@ -158,11 +188,15 @@ do_inotify_rm_watch (int wd)
   }
 
   return 0;
+#else
+  NOT_AVAILABLE (-1);
+#endif
 }
 
 guestfs_int_inotify_event_list *
 do_inotify_read (void)
 {
+#ifdef HAVE_SYS_INOTIFY_H
   int space;
   guestfs_int_inotify_event_list *ret;
 
@@ -268,11 +302,15 @@ do_inotify_read (void)
   xdr_free ((xdrproc_t) xdr_guestfs_int_inotify_event_list, (char *) ret);
   free (ret);
   return NULL;
+#else
+  NOT_AVAILABLE (NULL);
+#endif
 }
 
 char **
 do_inotify_files (void)
 {
+#ifdef HAVE_SYS_INOTIFY_H
   char **ret = NULL;
   int size = 0, alloc = 0;
   unsigned int i;
@@ -340,4 +378,7 @@ do_inotify_files (void)
  error:
   unlink ("/tmp/inotify");
   return NULL;
+#else
+  NOT_AVAILABLE (NULL);
+#endif
 }