Browse Source

ktpd: Transmit retcode to client

Serj Kalichev 2 years ago
parent
commit
6ddb3df2f2
4 changed files with 20 additions and 6 deletions
  1. 9 0
      bin/klish/klish.c
  2. 0 2
      bin/klishd/klishd.c
  3. 1 0
      klish/ktp.h
  4. 10 4
      klish/ktp/ktpd_session.c

+ 9 - 0
bin/klish/klish.c

@@ -72,6 +72,15 @@ int main(int argc, char **argv)
 				faux_str_free(error);
 			}
 		}
+		{
+			int retcode = -1;
+			uint8_t *retcode8bit = NULL;
+			if (faux_msg_get_param_by_type(msg, KTP_PARAM_RETCODE,
+				(void **)&retcode8bit, NULL)) {
+				retcode = (int)(*retcode8bit);
+				printf("Retcode: %d\n", retcode);
+			}
+		}
 		faux_msg_free(msg);
 	}
 

+ 0 - 2
bin/klishd/klishd.c

@@ -63,8 +63,6 @@ static bool_t listen_socket_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	void *associated_data, void *user_data);
 static bool_t wait_for_child_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	void *associated_data, void *user_data);
-static bool_t wait_for_actions_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
-	void *associated_data, void *user_data);
 
 
 /** @brief Main function

+ 1 - 0
klish/ktp.h

@@ -35,6 +35,7 @@ typedef enum {
 	KTP_PARAM_NULL = '\0',
 	KTP_PARAM_LINE = 'L',
 	KTP_PARAM_ERROR = 'E',
+	KTP_PARAM_RETCODE = 'R',
 } ktp_param_e;
 
 

+ 10 - 4
klish/ktp/ktpd_session.c

@@ -183,14 +183,17 @@ static bool_t ktpd_session_process_cmd(ktpd_session_t *ktpd, faux_msg_t *msg)
 	}
 
 	if (rc) {
+		uint8_t retcode8bit = 0;
+		ack = ktp_msg_preform(cmd, KTP_STATUS_NONE);
+		retcode8bit = (uint8_t)(retcode & 0xff);
+		faux_msg_add_param(ack, KTP_PARAM_RETCODE, &retcode8bit, 1);
+		faux_msg_send_async(ack, ktpd->async);
+		faux_msg_free(ack);
+	} else {
 		char *err = faux_error_cstr(error);
 		ktpd_session_send_error(ktpd, cmd, err);
 		faux_str_free(err);
 		return BOOL_FALSE;
-	} else {
-		ack = ktp_msg_preform(cmd, KTP_STATUS_NONE);
-		faux_msg_send_async(ack, ktpd->async);
-		faux_msg_free(ack);
 	}
 
 	faux_error_free(error);
@@ -480,6 +483,7 @@ static bool_t wait_for_actions_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	pid_t child_pid = -1;
 	ktpd_session_t *ktpd = (ktpd_session_t *)user_data;
 	int retcode = -1;
+	uint8_t retcode8bit = 0;
 	faux_msg_t *ack = NULL;
 	ktp_cmd_e cmd = KTP_CMD_ACK;
 
@@ -507,6 +511,8 @@ static bool_t wait_for_actions_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 
 	// Send ACK message
 	ack = ktp_msg_preform(cmd, KTP_STATUS_NONE);
+	retcode8bit = (uint8_t)(retcode & 0xff);
+	faux_msg_add_param(ack, KTP_PARAM_RETCODE, &retcode8bit, 1);
 	faux_msg_send_async(ack, ktpd->async);
 	faux_msg_free(ack);