瀏覽代碼

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>
Jan Friesse 7 年之前
父節點
當前提交
9186129ace
共有 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.
  *
@@ -64,7 +64,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);
 }
 
@@ -178,6 +178,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");
@@ -265,14 +266,13 @@ main(int argc, char * const argv[])
 #ifdef HAVE_LIBSYSTEMD
 	sd_notify (0, "READY=1");
 #endif
-	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);
@@ -294,5 +294,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);
 }
 
 /*