watcher: unregister a watcher FD if its thread gets cancelled
authorMartin Willi <martin@revosec.ch>
Mon, 1 Jul 2013 16:38:42 +0000 (18:38 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 18 Jul 2013 14:00:29 +0000 (16:00 +0200)
src/libstrongswan/processing/watcher.c

index ff3e116..84a870f 100644 (file)
@@ -106,12 +106,25 @@ static void update(private_watcher_t *this)
        }
 }
 
+/**
+ * Cleanup function if callback gets cancelled
+ */
+static void unregister(notify_data_t *data)
+{
+       /* if a thread processing a callback gets cancelled, we mark the entry
+        * as cancelled, like the callback would return FALSE. This is required
+        * to not queue this watcher again if all threads have been gone. */
+       data->keep = FALSE;
+}
+
  /**
  * Execute callback of registered FD, asynchronous
  */
 static job_requeue_t notify_async(notify_data_t *data)
 {
+       thread_cleanup_push((void*)unregister, data);
        data->keep = data->cb(data->data, data->fd, data->event);
+       thread_cleanup_pop(FALSE);
        return JOB_REQUEUE_NONE;
 }