#define DATA_DELIMITER "#" // in detail info data
#define TIMEOUT_FOR_SHUTDOWN 10 // seconds
+static int requested_shutdown_qemu_gracefully = 0;
+
static void* run_timed_shutdown_thread( void* args );
static void send_to_emuld( const char* request_type, int request_size, const char* send_buf, int buf_size );
void shutdown_qemu_gracefully( void ) {
+ requested_shutdown_qemu_gracefully = 1;
+
pthread_t thread_id;
if( 0 > pthread_create( &thread_id, NULL, run_timed_shutdown_thread, NULL ) ) {
ERR( "!!! Fail to create run_timed_shutdown_thread. shutdown qemu right now !!!\n" );
}
+int is_requested_shutdown_qemu_gracefully( void ) {
+ return requested_shutdown_qemu_gracefully;
+}
+
static void* run_timed_shutdown_thread( void* args ) {
send_to_emuld( "system\n\n\n\n", 10, "shutdown", 8 );
}
void shutdown_skin_server( void ) {
+
+ INFO( "shutdown_skin_server\n" );
+
if ( client_sock ) {
+
INFO( "send shutdown to skin.\n" );
+
if ( 0 > send_skin_header_only( client_sock, SEND_SHUTDOWN ) ) {
+
ERR( "fail to send SEND_SHUTDOWN to skin.\n" );
// force close
+ is_force_close_client = 1;
#ifdef _WIN32
closesocket( client_sock );
#else
close( client_sock );
#endif
+
} else {
// skin sent RECV_RESPONSE_SHUTDOWN.
}
}
+ if ( client_sock ) {
+#ifdef _WIN32
+ closesocket( client_sock );
+#else
+ close( client_sock );
+#endif
+ }
+
+ int close_server_socket = 0;
+ int count = 0;
+ int max_sleep_count = 10;
+
+ while( 1 ) {
+
+ if( max_sleep_count < count ) {
+ close_server_socket = 1;
+ break;
+ }
+
+ if( stop_server ) {
+ INFO( "skin client sent normal shutdown response.\n" );
+ break;
+ }else {
+#ifdef _WIN32
+ Sleep( 1 ); // 1ms
+#else
+ usleep( 1000 ); // 1ms
+#endif
+ count++;
+ }
+ }
+
+ if ( close_server_socket ) {
+ WARN( "skin client did not send normal shutdown response.\n" );
+ stop_server = 1;
+ if ( server_sock ) {
+#ifdef _WIN32
+ closesocket( server_sock );
+#else
+ close( server_sock );
+#endif
+ }
+ }
+
}
void notify_sensor_daemon_start( void ) {
while ( 1 ) {
if ( stop_server ) {
+ INFO( "close server socket normally.\n" );
break;
}
while ( 1 ) {
if ( stop_server ) {
- INFO( "stop receiving this socket.\n" );
+ INFO( "stop receiving current client socket.\n" );
break;
}
stop_heart_beat();
cleanup:
+ if ( server_sock ) {
#ifdef _WIN32
- if(server_sock) {
closesocket( server_sock );
- }
#else
- if ( server_sock ) {
close( server_sock );
- }
#endif
+ }
if( shutdown_qmu ) {
ERR( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );
break;
} else {
- send_fail_count = 0;
- recv_heartbeat_count = 0;
- need_restart_skin_client = 0;
- restart_client_count++;
+ if ( is_requested_shutdown_qemu_gracefully() ) {
+ INFO( "requested shutdown_qemu_gracefully, do not retry starting skin client process.\n" );
+ break;
+ }else {
- WARN( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );
- WARN( "!!! restart skin client process !!!\n" );
- WARN( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );
+ send_fail_count = 0;
+ recv_heartbeat_count = 0;
+ need_restart_skin_client = 0;
+ restart_client_count++;
+
+ WARN( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );
+ WARN( "!!! restart skin client process !!!\n" );
+ WARN( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );
+
+ is_force_close_client = 1;
+ if ( client_sock ) {
+ if ( client_sock ) {
+#ifdef _WIN32
+ closesocket( client_sock );
+#else
+ close( client_sock );
+#endif
+ }
+ }
- is_force_close_client = 1;
- shutdown_skin_server();
- start_skin_client( skin_argc, skin_argv );
+ start_skin_client( skin_argc, skin_argv );
+
+ }
}
INFO( "[HB] shutdown skin_server by heartbeat thread.\n" );
is_force_close_client = 1;
- shutdown_skin_server();
+ if ( client_sock ) {
+ if ( client_sock ) {
+#ifdef _WIN32
+ closesocket( client_sock );
+#else
+ close( client_sock );
+#endif
+ }
+ }
stop_server = 1;