diff --git a/misc/services/life_mngr/command_handler.c b/misc/services/life_mngr/command_handler.c index 8b0a49604..796952096 100644 --- a/misc/services/life_mngr/command_handler.c +++ b/misc/services/life_mngr/command_handler.c @@ -174,7 +174,7 @@ int socket_req_user_vm_reboot_handler(void *arg, int fd) return req_user_vm_shutdown_reboot(arg, fd, USER_VM_REBOOT, ACK_REQ_USER_VM_REBOOT); } -int socket_req_system_reboot_handler(void *arg, int fd) +int req_system_shutdown_reboot(void *arg, int fd, char *msg, char *ack_msg) { int ret; struct channel_dev *c_dev = NULL; @@ -187,43 +187,27 @@ int socket_req_system_reboot_handler(void *arg, int fd) return 0; } - ret = send_socket_ack(arg, fd, ACK_REQ_SYS_REBOOT); + ret = send_socket_ack(arg, fd, ack_msg); if (ret < 0) { LOG_WRITE("Failed to send ACK by socket\n"); return 0; } - LOG_WRITE("Foward reboot req to service VM by UART\n"); - start_uart_channel_dev_resend(c_dev, REQ_SYS_REBOOT, MIN_RESEND_TIME); - ret = send_message_by_uart(c_dev->uart_device, REQ_SYS_REBOOT, strlen(REQ_SYS_REBOOT)); + LOG_PRINTF("Foward (%s) req to service VM by UART\n", msg); + start_uart_channel_dev_resend(c_dev, msg, MIN_RESEND_TIME); + ret = send_message_by_uart(c_dev->uart_device, msg, strlen(msg)); if (ret < 0) - LOG_WRITE("Failed to foward system reboot request to service VM by UART\n"); + LOG_PRINTF("Failed to foward (%s) to service VM by UART\n", msg); return ret; } +int socket_req_system_reboot_user_vm_handler(void *arg, int fd) +{ + return req_system_shutdown_reboot(arg, fd, REQ_SYS_REBOOT, ACK_REQ_SYS_REBOOT); + } + int socket_req_system_shutdown_user_vm_handler(void *arg, int fd) { - int ret; - struct channel_dev *c_dev = NULL; - - usleep(LISTEN_INTERVAL + SECOND_TO_US); - c_dev = (struct channel_dev *)LIST_FIRST(&channel->tty_conn_head); - if (c_dev == NULL) { - (void) send_socket_ack(arg, fd, USER_VM_DISCONNECT); - LOG_WRITE("User VM is disconnect\n"); - return 0; - } - - ret = send_socket_ack(arg, fd, ACK_REQ_SYS_SHUTDOWN); - if (ret < 0) { - LOG_WRITE("Failed to send ACK by socket\n"); - return 0; - } - LOG_WRITE("Foward shutdown req to service VM by UART\n"); - start_uart_channel_dev_resend(c_dev, REQ_SYS_SHUTDOWN, MIN_RESEND_TIME); - ret = send_message_by_uart(c_dev->uart_device, REQ_SYS_SHUTDOWN, strlen(REQ_SYS_SHUTDOWN)); - if (ret < 0) - LOG_WRITE("Failed to foward system shutdown request to service VM by UART\n"); - return ret; + return req_system_shutdown_reboot(arg, fd, REQ_SYS_SHUTDOWN, ACK_REQ_SYS_SHUTDOWN); } static int is_allowed_s5_channel_dev(struct life_mngr_config *conf, struct channel_dev *c_dev) @@ -418,7 +402,7 @@ int acked_sync_handler(void *arg, int fd) * @param fd the file directory of the uart which receives message * @return indicate this command is handled successful or not */ -int acked_req_shutdown_handler(void *arg, int fd) +int acked_req_shutdown_reboot_handler(void *arg, int fd) { struct channel_dev *c_dev = NULL; struct uart_channel *c = (struct uart_channel *)arg; diff --git a/misc/services/life_mngr/command_handler.h b/misc/services/life_mngr/command_handler.h index c0b69fe48..a249f2ea6 100644 --- a/misc/services/life_mngr/command_handler.h +++ b/misc/services/life_mngr/command_handler.h @@ -30,7 +30,10 @@ int socket_req_user_vm_shutdown_handler(void *arg, int fd); */ int socket_req_user_vm_reboot_handler(void *arg, int fd); -int socket_req_system_reboot_handler(void *arg, int fd); +/** + * @brief The handler of request system reboot command on socket in user VM + */ +int socket_req_system_reboot_user_vm_handler(void *arg, int fd); /** * @brief The handler of request system shutdown command on socket in user VM */ @@ -109,7 +112,7 @@ int acked_sync_handler(void *arg, int fd); * @param fd the file directory of the uart which receives message * @return indicate this command is handled successful or not */ -int acked_req_shutdown_handler(void *arg, int fd); +int acked_req_shutdown_reboot_handler(void *arg, int fd); /** * @brief The handler of poweroff command of lifecycle manager in user VM * diff --git a/misc/services/life_mngr/monitor.c b/misc/services/life_mngr/monitor.c index 20e1c5785..f8ca0693f 100644 --- a/misc/services/life_mngr/monitor.c +++ b/misc/services/life_mngr/monitor.c @@ -98,7 +98,7 @@ int init_socket_server_and_shutdown_commands(bool service_vm) } else { register_command_handler(socket_req_system_shutdown_user_vm_handler, sock_server, REQ_SYS_SHUTDOWN); - register_command_handler(socket_req_system_reboot_handler, + register_command_handler(socket_req_system_reboot_user_vm_handler, sock_server, REQ_SYS_REBOOT); } return ret; @@ -133,7 +133,8 @@ int init_uart_channel_devs_and_shutdown_commands(bool service_vm, char *uart_dev register_command_handler(poweroff_cmd_handler, channel, POWEROFF_CMD); register_command_handler(user_vm_shutdown_cmd_handler, channel, USER_VM_SHUTDOWN); register_command_handler(user_vm_reboot_cmd_handler, channel, USER_VM_REBOOT); - register_command_handler(acked_req_shutdown_handler, channel, ACK_REQ_SYS_SHUTDOWN); + register_command_handler(acked_req_shutdown_reboot_handler, channel, ACK_REQ_SYS_SHUTDOWN); + register_command_handler(acked_req_shutdown_reboot_handler, channel, ACK_REQ_SYS_REBOOT); register_command_handler(ack_timeout_default_handler, channel, ACK_TIMEOUT); c_dev = create_uart_channel_dev(channel, uart_dev_name, monitor_cmd_dispatch); diff --git a/misc/services/life_mngr/system_reboot_trigger_linux_rtvm.py b/misc/services/life_mngr/system_reboot_trigger_linux_rtvm.py index 13f9be3e4..6f60964a0 100644 --- a/misc/services/life_mngr/system_reboot_trigger_linux_rtvm.py +++ b/misc/services/life_mngr/system_reboot_trigger_linux_rtvm.py @@ -11,7 +11,7 @@ class SocketClient: pass def connect_to_server(self): SOKET_ADDR = '/var/lib/life_mngr/monitor.sock' - SHUTDOWN_REQ = 'req_sys_reboot' + SYS_REBOOT_REQ = 'req_sys_reboot' BUF_LEN = 1024 # unix domain sockets @@ -21,7 +21,7 @@ class SocketClient: sock = socket.socket(socket_family, socket_type) sock.connect(server_address) - sock.sendall(SHUTDOWN_REQ.encode()) + sock.sendall(SYS_REBOOT_REQ.encode()) data = sock.recv(BUF_LEN) print(f"Waiting for ACK message...: {data.decode()}") sock.close()