Browse Source

qdevice: Fix qdevice_heuristics_destroy error

When daemonization is used, heuristics worker is not a child of
the corosync-qdevice process any longer so it's not possible
to wait for its exit.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>

(cherry picked from corosync-qdevice project commit
 9bbf2f240d57e90b94dac866d4f42a81d8c060b9)
Jan Friesse 6 years ago
parent
commit
c71cb72b50
3 changed files with 20 additions and 12 deletions
  1. 1 1
      qdevices/corosync-qdevice.c
  2. 17 10
      qdevices/qdevice-heuristics.c
  3. 2 1
      qdevices/qdevice-heuristics.h

+ 1 - 1
qdevices/corosync-qdevice.c

@@ -278,7 +278,7 @@ main(int argc, char * const argv[])
 	qdevice_cmap_destroy(&instance);
 	qdevice_cmap_destroy(&instance);
 
 
 	qdevice_log(LOG_DEBUG, "Destroying heuristics");
 	qdevice_log(LOG_DEBUG, "Destroying heuristics");
-	qdevice_heuristics_destroy(&instance.heuristics_instance);
+	qdevice_heuristics_destroy(&instance.heuristics_instance, foreground);
 
 
 	qdevice_log(LOG_DEBUG, "Closing log");
 	qdevice_log(LOG_DEBUG, "Closing log");
 	qdevice_log_close(&instance);
 	qdevice_log_close(&instance);

+ 17 - 10
qdevices/qdevice-heuristics.c

@@ -138,23 +138,30 @@ qdevice_heuristics_init(struct qdevice_heuristics_instance *instance,
 }
 }
 
 
 void
 void
-qdevice_heuristics_destroy(struct qdevice_heuristics_instance *instance)
+qdevice_heuristics_destroy(struct qdevice_heuristics_instance *instance, int wait_for_worker_exit)
 {
 {
 	int status;
 	int status;
 
 
 	/*
 	/*
-	 * Close of pipe_cmd_send result is correct and almost instant exit of worker
+	 * Close pipe_cmd_send. Heuristics worker catch the close of the fd and exits
+	 * properly.
 	 */
 	 */
 	close(instance->pipe_cmd_send);
 	close(instance->pipe_cmd_send);
 
 
-	qdevice_log(LOG_DEBUG, "Waiting for heuristics worker to finish");
-	if (waitpid(instance->worker_pid, &status, 0) == -1) {
-		qdevice_log_err(LOG_ERR, "Heuristics worker waitpid failed");
-	} else {
-		/*
-		 * Log what left in worker log buffer. Errors can be ignored
-		 */
-		(void)qdevice_heuristics_log_read_from_pipe(instance);
+	/*
+	 * When daemonization is used, heuristics worker is not a child of the corosync-qdevice
+	 * process any longer so it's not possible to wait for its exit.
+	 */
+	if (wait_for_worker_exit) {
+		qdevice_log(LOG_DEBUG, "Waiting for heuristics worker to finish");
+		if (waitpid(instance->worker_pid, &status, 0) == -1) {
+			qdevice_log_err(LOG_ERR, "Heuristics worker waitpid failed");
+		} else {
+			/*
+			 * Log what left in worker log buffer. Errors can be ignored
+			 */
+			(void)qdevice_heuristics_log_read_from_pipe(instance);
+		}
 	}
 	}
 
 
 	close(instance->pipe_cmd_recv);
 	close(instance->pipe_cmd_recv);

+ 2 - 1
qdevices/qdevice-heuristics.h

@@ -48,7 +48,8 @@ extern "C" {
 extern void		qdevice_heuristics_init(struct qdevice_heuristics_instance *instance,
 extern void		qdevice_heuristics_init(struct qdevice_heuristics_instance *instance,
     struct qdevice_advanced_settings *advanced_settings);
     struct qdevice_advanced_settings *advanced_settings);
 
 
-extern void		qdevice_heuristics_destroy(struct qdevice_heuristics_instance *instance);
+extern void		qdevice_heuristics_destroy(struct qdevice_heuristics_instance *instance,
+    int wait_for_worker_exit);
 
 
 extern int		qdevice_heuristics_exec(struct qdevice_heuristics_instance *instance,
 extern int		qdevice_heuristics_exec(struct qdevice_heuristics_instance *instance,
     int sync_in_progress);
     int sync_in_progress);