life_mngr:fix resend shutdown cmd fail
1) fix a bug,resend shutdown cmd only send one character
2) move out accept routine from while loop, let this thread
can read data from acrn-dm continuously.
@@ -171,8 +171,6 @@ void *sos_socket_thread(void *arg)
listen_fd = setup_socket_listen(SOS_SOCKET_PORT);
LOG_PRINTF("life_mngr:listen_fd=0x%x socket port is 0x%x\r\n", listen_fd, SOS_SOCKET_PORT);
- while (1) {
- memset(buf, 0, BUFF_SIZE);
connect_fd = accept(listen_fd, (struct sockaddr *)&client, &len);
if (connect_fd == -1) {
LOG_WRITE("accept a connection error on a socket\n");
@@ -180,6 +178,9 @@ void *sos_socket_thread(void *arg)
exit(1);
}
+ while (1) {
+ memset(buf, 0, BUFF_SIZE);
+
/* Here assume the socket communication is reliable, no need to try */
num = read(connect_fd, buf, sizeof(SHUTDOWN_CMD));
if (num == -1) {
@@ -250,7 +251,7 @@ void *listener_fn_to_sos(void *arg)
shutdown_self = true;
} else {
if (retry > 0) {
- if (send_message(tty_dev_fd, SHUTDOWN_CMD, sizeof(SHUTDOWN_CMD) != 0)) {
+ if (send_message(tty_dev_fd, SHUTDOWN_CMD, sizeof(SHUTDOWN_CMD)) != 0) {
LOG_PRINTF("Try resend shutdown cmd failed cnt = %d\n", retry);
}
retry--;
