Просмотр исходного кода

qdevice: Propagate error to exit code

Net model never returned error when qdevice_model_run was called. This
was incorrect because with exception of local ipc close all other
disconnect reasons are errors.

Solution is to return proper error code.

Also instead of exit right after qdevice_model_run it's better to store
result value, try clean resources and use stored value to return correct
exit code.

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

(backported from corosync-qdevice project commit
 9186129ace564183932cc4b0fb64c24115fd4965)
Jan Friesse 7 лет назад
Родитель
Сommit
918bc47812
2 измененных файлов с 22 добавлено и 11 удалено
  1. 9 9
      qdevices/corosync-qdevice.c
  2. 13 2
      qdevices/qdevice-model-net.c

+ 9 - 9
qdevices/corosync-qdevice.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2017 Red Hat, Inc.
+ * Copyright (c) 2015-2018 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -60,7 +60,7 @@ signal_int_handler(int sig)
 static void
 signal_term_handler(int sig)
 {
-	qdevice_log(LOG_DEBUG, "SIGTERM received - closing server socket");
+	qdevice_log(LOG_DEBUG, "SIGTERM received - closing local unix socket");
 	qdevice_ipc_close(global_instance);
 }
 
@@ -174,6 +174,7 @@ main(int argc, char * const argv[])
 	int force_debug;
 	int lock_file;
 	int another_instance_running;
+	int model_run_res;
 
 	if (qdevice_advanced_settings_init(&advanced_settings) != 0) {
 		errx(1, "Can't alloc memory for advanced settings");
@@ -258,14 +259,13 @@ main(int argc, char * const argv[])
 	signal_handlers_register();
 
 	qdevice_log(LOG_DEBUG, "Running qdevice model");
-	if (qdevice_model_run(&instance) != 0) {
-		return (1);
-	}
+	model_run_res = qdevice_model_run(&instance);
 
 	qdevice_log(LOG_DEBUG, "Removing cmap tracking");
-	if (qdevice_cmap_del_track(&instance) != 0) {
-		return (1);
-	}
+	/*
+	 * Ignore error intentionally
+	 */
+	(void)qdevice_cmap_del_track(&instance);
 
 	qdevice_log(LOG_DEBUG, "Destroying qdevice model");
 	qdevice_model_destroy(&instance);
@@ -287,5 +287,5 @@ main(int argc, char * const argv[])
 
 	qdevice_advanced_settings_destroy(&advanced_settings);
 
-	return (0);
+	return (model_run_res == 0 ? 0 : 2);
 }

+ 13 - 2
qdevices/qdevice-model-net.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2017 Red Hat, Inc.
+ * Copyright (c) 2015-2018 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -162,11 +162,14 @@ qdevice_model_net_run(struct qdevice_instance *instance)
 	int res;
 	enum tlv_vote vote;
 	int delay_before_reconnect;
+	int ret_val;
 
 	net_instance = instance->model_data;
 
 	qdevice_log(LOG_DEBUG, "Executing qdevice-net");
 
+	ret_val = -1;
+
 	try_connect = 1;
 	while (try_connect) {
 		net_instance->state = QDEVICE_NET_INSTANCE_STATE_WAITING_CONNECT;
@@ -239,6 +242,13 @@ qdevice_model_net_run(struct qdevice_instance *instance)
 			try_connect = 0;
 		}
 
+		/*
+		 * Return 0 only when local socket was closed -> regular exit
+		 */
+		if (net_instance->disconnect_reason == QDEVICE_NET_DISCONNECT_REASON_LOCAL_SOCKET_CLOSED) {
+			ret_val = 0;
+		}
+
 		if (net_instance->socket != NULL) {
 			if (PR_Close(net_instance->socket) != PR_SUCCESS) {
 				qdevice_log_nss(LOG_WARNING, "Unable to close connection");
@@ -270,10 +280,11 @@ qdevice_model_net_run(struct qdevice_instance *instance)
 			(void)poll(NULL, 0, delay_before_reconnect);
 		}
 
+
 		qdevice_net_instance_clean(net_instance);
 	}
 
-	return (0);
+	return (ret_val);
 }
 
 /*