From: Son Hyunjun Date: Fri, 6 Apr 2012 11:22:34 +0000 (+0900) Subject: [Title] enhance graceful shutdown in abnormal case X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~1668 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f2fa3fcf047dbbe5db2f6e63bbc397c5d0393811;p=sdk%2Femulator%2Fqemu.git [Title] enhance graceful shutdown in abnormal case [Type] Enhancement [Module] Skin [Priority] Minor [CQ#] [Redmine#] [Problem] [Cause] [Solution] Change-Id: I413b5906011bb503e0e2e73998fbb8c5a5908402 --- diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 97f914e8ae..095a90ee3b 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -274,7 +274,6 @@ void prepare_maru(void) construct_main_window(skin_argc, skin_argv, qemu_argc, qemu_argv ); - //TODO get port number by args from emulator manager int guest_server_port = tizen_base_port + SDB_UDP_SENSOR_INDEX; start_guest_server( guest_server_port ); diff --git a/tizen/src/skin/maruskin_operation.c b/tizen/src/skin/maruskin_operation.c index 3829f6efd2..8c9f97e118 100644 --- a/tizen/src/skin/maruskin_operation.c +++ b/tizen/src/skin/maruskin_operation.c @@ -52,6 +52,8 @@ MULTI_DEBUG_CHANNEL(qemu, skin_operation); #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 ); @@ -330,6 +332,8 @@ void request_close( void ) 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" ); @@ -338,6 +342,10 @@ void shutdown_qemu_gracefully( void ) { } +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 ); diff --git a/tizen/src/skin/maruskin_operation.h b/tizen/src/skin/maruskin_operation.h index 1b331055a1..6f2cae4516 100644 --- a/tizen/src/skin/maruskin_operation.h +++ b/tizen/src/skin/maruskin_operation.h @@ -70,4 +70,6 @@ void request_close( void ); void shutdown_qemu_gracefully( void ); +int is_requested_shutdown_qemu_gracefully( void ); + #endif /* MARUSKIN_OPERATION_H_ */ diff --git a/tizen/src/skin/maruskin_server.c b/tizen/src/skin/maruskin_server.c index 9840ef9bf2..9df5778468 100644 --- a/tizen/src/skin/maruskin_server.c +++ b/tizen/src/skin/maruskin_server.c @@ -155,21 +155,73 @@ int start_skin_server( int argc, char** argv, int qemu_argc, char** qemu_argv ) } 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 ) { @@ -384,6 +436,7 @@ static void* run_skin_server( void* args ) { while ( 1 ) { if ( stop_server ) { + INFO( "close server socket normally.\n" ); break; } @@ -410,7 +463,7 @@ static void* run_skin_server( void* args ) { while ( 1 ) { if ( stop_server ) { - INFO( "stop receiving this socket.\n" ); + INFO( "stop receiving current client socket.\n" ); break; } @@ -746,15 +799,13 @@ static void* run_skin_server( void* args ) { 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" ); @@ -970,18 +1021,34 @@ static void* do_heart_beat( void* args ) { 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 ); + + } } @@ -994,7 +1061,15 @@ static void* do_heart_beat( void* args ) { 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;