summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2022-02-06 12:16:52 -0500
committerDavid Thompson <dthompson2@worcester.edu>2022-02-06 12:16:52 -0500
commitab0b722b0719e3370a21359e4d511af9c4f14e60 (patch)
tree5f98f6cb1551b2711d2336ad4317af055c9488fa
parent3e406cbef274ad83c44674a8ee404684eb16bdbe (diff)
Do not compile or load inotify module when inotify is not available.
-rw-r--r--Makefile.am7
-rw-r--r--configure.ac3
-rw-r--r--haunt/ui/serve.scm12
3 files changed, 20 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index e3eb96f..1bddaa4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -46,7 +46,6 @@ bin_SCRIPTS = \
SOURCES = \
haunt/config.scm \
haunt/utils.scm \
- haunt/inotify.scm \
haunt/post.scm \
haunt/page.scm \
haunt/asset.scm \
@@ -81,6 +80,12 @@ SOURCES += \
endif
+if HAVE_INOTIFY
+
+SOURCES += haunt/inotify.scm
+
+endif
+
TESTS = \
tests/helper.scm \
tests/post.scm \
diff --git a/configure.ac b/configure.ac
index bb9550c..2a80cdf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,4 +21,7 @@ AM_CONDITIONAL([HAVE_GUILE_READER], [test "x$have_guile_reader" = "xyes"])
GUILE_MODULE_AVAILABLE([have_guile_commonmark], [(commonmark)])
AM_CONDITIONAL([HAVE_GUILE_COMMONMARK], [test "x$have_guile_commonmark" = "xyes"])
+AC_CHECK_FUNCS(inotify_init)
+AM_CONDITIONAL([HAVE_INOTIFY], [test "x$HAVE_INOTIFY_INIT" = "xyes"])
+
AC_OUTPUT
diff --git a/haunt/ui/serve.scm b/haunt/ui/serve.scm
index 62fbc6b..8511d87 100644
--- a/haunt/ui/serve.scm
+++ b/haunt/ui/serve.scm
@@ -30,7 +30,6 @@
#:use-module (ice-9 ftw)
#:use-module (ice-9 threads)
#:use-module (haunt config)
- #:use-module (haunt inotify)
#:use-module (haunt serve web-server)
#:use-module (haunt site)
#:use-module (haunt ui)
@@ -90,6 +89,17 @@ Start an HTTP server for the current site.~%")
;; TODO: Detect new directories and watch them, too.
(define (watch/linux config-file check-dir? check-file?)
+ ;; Lazy load inotify procedures. Requiring the module in the
+ ;; define-module definition would cause crashes on non-Linux
+ ;; platforms where the FFI cannot bind to inotify functions.
+ (define make-inotify (@ (haunt inotify) make-inotify))
+ (define inotify-add-watch! (@ (haunt inotify) inotify-add-watch!))
+ (define inotify-pending-events? (@ (haunt inotify) inotify-pending-events?))
+ (define inotify-read-event (@ (haunt inotify) inotify-read-event))
+ (define inotify-watch-file-name (@ (haunt inotify) inotify-watch-file-name))
+ (define inotify-event-watch (@ (haunt inotify) inotify-event-watch))
+ (define inotify-event-file-name (@ (haunt inotify) inotify-event-file-name))
+ (define inotify-event-type (@ (haunt inotify) inotify-event-type))
(let ((inotify (make-inotify)))
(define (no-op name stat result) result)
(define (watch-directory name stat result)