life_mngr: permit life_mngr in windows to assign VM name

Permit life_mngr in windows to assign the VM name which configure
in scenario XML.

Tracked-On: #8051
Signed-off-by: Fei Li <fei1.li@intel.com>
This commit is contained in:
Fei Li 2022-08-25 09:57:17 +08:00 committed by acrnsi-robot
parent f4e931c762
commit c76f26bdad

View File

@ -27,7 +27,6 @@
#define BUFF_SIZE (32U) #define BUFF_SIZE (32U)
#define MSG_SIZE (8U) #define MSG_SIZE (8U)
#define VM_NAME_LEN (sizeof(WIN_VM_NAME))
#define UVM_SOCKET_PORT (0x2001U) #define UVM_SOCKET_PORT (0x2001U)
#define READ_INTERVAL (100U) /* The time unit is microsecond */ #define READ_INTERVAL (100U) /* The time unit is microsecond */
#define MIN_RESEND_TIME (3U) #define MIN_RESEND_TIME (3U)
@ -180,17 +179,25 @@ HANDLE initCom(const char *szStr)
return hCom; return hCom;
} }
int main() int main(int argc, char **argv)
{ {
DWORD recvsize = 0; DWORD recvsize = 0;
char recvbuf[BUFF_SIZE]; char recvbuf[BUFF_SIZE];
char buf[VM_NAME_LEN + 5]; char buf[BUFF_SIZE];
DWORD dwError; DWORD dwError;
DWORD threadId; DWORD threadId;
bool poweroff = false; bool poweroff = false;
bool reboot = false; bool reboot = false;
unsigned int retry_times; unsigned int retry_times;
if (argc > 2)
return -1;
if ((argc == 2) && (sizeof(argv[1]) + 5 > BUFF_SIZE)) {
printf("VM name (%s) is too long\n", argv[1]);
return -1;
}
hCom2 = initCom("COM2"); hCom2 = initCom("COM2");
if (hCom2 == INVALID_HANDLE_VALUE) if (hCom2 == INVALID_HANDLE_VALUE)
return -1; return -1;
@ -200,7 +207,8 @@ int main()
if (ClearCommError(hCom2, &dwError, NULL)) { if (ClearCommError(hCom2, &dwError, NULL)) {
PurgeComm(hCom2, PURGE_TXABORT | PURGE_TXCLEAR); PurgeComm(hCom2, PURGE_TXABORT | PURGE_TXCLEAR);
} }
snprintf(buf, sizeof(buf), SYNC_FMT, WIN_VM_NAME);
snprintf(buf, sizeof(buf), SYNC_FMT, (argc == 1) ? WIN_VM_NAME : argv[1]);
start_uart_resend(buf, MIN_RESEND_TIME); start_uart_resend(buf, MIN_RESEND_TIME);
send_message_by_uart(hCom2, buf, strlen(buf)); send_message_by_uart(hCom2, buf, strlen(buf));
/** /**