From e75417f852555214c898af5ce8ca46017378f31d Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Wed, 30 Jun 2010 13:55:41 -0400
Subject: [PATCH] Add try_inotify option

There are some special cases where inotify cannot be used, even if
the host OS claims that it is supported. In these cases, it should
be possible to explicitly disable the use of inotify.

https://fedorahosted.org/sssd/ticket/484
---
 src/confdb/confdb.h     |    1 +
 src/man/sssd.conf.5.xml |   28 ++++++++++++++++++++++++++++
 src/monitor/monitor.c   |   19 ++++++++++++++++++-
 3 files changed, 47 insertions(+), 1 deletions(-)

diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h
index ae7502f8df6bb6c351a74d9b524a6b0f31c80496..b498551b1121920f582847d7ebbbe6c9f2c752c2 100644
--- a/src/confdb/confdb.h
+++ b/src/confdb/confdb.h
@@ -60,6 +60,7 @@
 #define CONFDB_MONITOR_ACTIVE_DOMAINS "domains"
 #define CONFDB_MONITOR_NAME_REGEX   "re_expression"
 #define CONFDB_MONITOR_FULL_NAME_FORMAT "full_name_format"
+#define CONFDB_MONITOR_TRY_INOTIFY "try_inotify"
 
 /* NSS */
 #define CONFDB_NSS_CONF_ENTRY "config/nss"
diff --git a/src/man/sssd.conf.5.xml b/src/man/sssd.conf.5.xml
index 497fae630429fd36b11382a8b5e054e3e5f87c0d..83a009df5ffd30203a83d6c8b58e828640feaaac 100644
--- a/src/man/sssd.conf.5.xml
+++ b/src/man/sssd.conf.5.xml
@@ -157,6 +157,34 @@
                             </para>
                         </listitem>
                     </varlistentry>
+                    <varlistentry>
+                        <term>try_inotify (boolean)</term>
+                        <listitem>
+                            <para>
+                                SSSD monitors the state of resolv.conf to
+                                identify when it needs to update its internal
+                                DNS resolver. By default, we will attempt to
+                                use inotify for this, and will fall back to
+                                polling resolv.conf every five seconds if
+                                inotify cannot be used.
+                            </para>
+                            <para>
+                                There are some limited situations where it is
+                                preferred that we should skip even trying to
+                                use inotify. In these rare cases, this option
+                                should be set to 'false'
+                            </para>
+                            <para>
+                                Default: true on platforms where inotify is
+                                supported. False on other platforms.
+                            </para>
+                            <para>
+                                Note: this option will have no effect on
+                                platforms where inotify is unavailable. On
+                                these platforms, polling will always be used.
+                            </para>
+                        </listitem>
+                    </varlistentry>
                 </variablelist>
             </para>
         </refsect2>
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index 41eadf52a37cc936c50fa770cad72e63b2088080..47832c95d0b5254723c57d95130b1d60492b731b 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -1632,6 +1632,7 @@ static int monitor_config_file(TALLOC_CTX *mem_ctx,
                                monitor_reconf_fn fn)
 {
     int ret, err;
+    bool use_inotify;
     struct timeval tv;
     struct stat file_stat;
     struct config_file_callback *cb = NULL;
@@ -1650,8 +1651,24 @@ static int monitor_config_file(TALLOC_CTX *mem_ctx,
         ctx->file_ctx->parent_ctx = mem_ctx;
         ctx->file_ctx->mt_ctx = ctx;
     }
-    ret = try_inotify(ctx->file_ctx, file, fn);
+
+    ret = confdb_get_bool(ctx->cdb, ctx,
+                          CONFDB_MONITOR_CONF_ENTRY,
+                          CONFDB_MONITOR_TRY_INOTIFY,
+                          true, &use_inotify);
     if (ret != EOK) {
+        talloc_free(ctx->file_ctx);
+        return ret;
+    }
+
+    if (use_inotify) {
+        ret = try_inotify(ctx->file_ctx, file, fn);
+        if (ret != EOK) {
+            use_inotify = false;
+        }
+    }
+
+    if (!use_inotify) {
         /* Could not monitor file with inotify, fall back to polling */
         cb = talloc_zero(ctx->file_ctx, struct config_file_callback);
         if (!cb) {
-- 
1.7.0.1

