ctdb: Fix build on AIX
[vlendec/samba-autobuild/.git] / ctdb / server / ctdb_cluster_mutex.c
index fbeeb92fb6be1bbe7a5c858c30c7974a7bb14dac..804c6d5dd8ca08989d1a44b3ec0ca3c6b55704cc 100644 (file)
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <tevent.h>
-
 #include "replace.h"
 #include "system/network.h"
 
+#include <tevent.h>
+
 #include "lib/util/debug.h"
 #include "lib/util/time.h"
 #include "lib/util/strv.h"
 #include "lib/util/strv_util.h"
+#include "lib/util/sys_rw.h"
+#include "lib/util/blocking.h"
 
 #include "ctdb_private.h"
 #include "common/common.h"
 #include "common/logging.h"
-#include "common/system.h"
 
 #include "ctdb_cluster_mutex.h"
 
@@ -40,6 +41,8 @@ struct ctdb_cluster_mutex_handle {
        struct ctdb_context *ctdb;
        cluster_mutex_handler_t handler;
        void *private_data;
+       cluster_mutex_lost_handler_t lost_handler;
+       void *lost_data;
        int fd[2];
        struct tevent_timer *te;
        struct tevent_fd *fde;
@@ -94,6 +97,13 @@ static void cluster_mutex_handler(struct tevent_context *ev,
        /* Don't call the handler more than once.  It only exists to
         * process the initial response from the helper. */
        if (h->have_response) {
+               /* Only deal with EOF due to process exit.  Silently
+                * ignore any other output. */
+               if (ret == 0) {
+                       if (h->lost_handler != NULL) {
+                               h->lost_handler(h->lost_data);
+                       }
+               }
                return;
        }
        h->have_response = true;
@@ -180,7 +190,9 @@ ctdb_cluster_mutex(TALLOC_CTX *mem_ctx,
                   const char *argstring,
                   int timeout,
                   cluster_mutex_handler_t handler,
-                  void *private_data)
+                  void *private_data,
+                  cluster_mutex_lost_handler_t lost_handler,
+                  void *lost_data)
 {
        struct ctdb_cluster_mutex_handle *h;
        char **args;
@@ -264,6 +276,8 @@ ctdb_cluster_mutex(TALLOC_CTX *mem_ctx,
        h->ctdb = ctdb;
        h->handler = handler;
        h->private_data = private_data;
+       h->lost_handler = lost_handler;
+       h->lost_data = lost_data;
 
        return h;
 }