From 4eebf079e1ccbab7c5f40cf051d808678cc1f439 Mon Sep 17 00:00:00 2001 From: Nils <> Date: Thu, 2 Jul 2020 01:45:40 +0200 Subject: [PATCH] Improve console log messages by using actual client names, especially when clients hang and wait. Enable client developers to figure out if it is their client that is wrong or not --- src/nsmd.cpp | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/nsmd.cpp b/src/nsmd.cpp index 8abcf4b..cbeebd4 100644 --- a/src/nsmd.cpp +++ b/src/nsmd.cpp @@ -235,6 +235,14 @@ public: strstr( capabilities, capability ); } + const char * name_with_id ( void ) const + { + char *full_client_id; + asprintf( &full_client_id, "%s.%s", name, client_id ); + return full_client_id; + } + + Client ( ) { _label = 0; @@ -335,11 +343,11 @@ handle_client_process_death ( int pid ) if ( dead_because_we_said ) { - GUIMSG( "Client %s terminated by server instruction.", c->name ); + GUIMSG( "Client %s terminated by server instruction.", c->name_with_id() ); } else { - GUIMSG( "Client %s terminated itself.", c->name ); + GUIMSG( "Client %s terminated itself.", c->name_with_id() ); } @@ -365,7 +373,7 @@ handle_client_process_death ( int pid ) * Compatible compromise is to use the label field to relay info the user, * which was the goal. There is nothing we can do about a failed launch anyway. */ - GUIMSG("Client %s had a launch error.", c->name); + GUIMSG("Client %s had a launch error.", c->name_with_id()); osc_server->send( gui_addr, "/nsm/gui/client/label", c->client_id, "launch error!" ); //do not set the client objects label. } } @@ -706,7 +714,7 @@ launch ( const char *executable, const char *client_id ) c->pending_command( COMMAND_START ); c->pid = pid; - MESSAGE( "Process %s has pid: %i", executable, pid ); + MESSAGE( "Process %s has pid: %i", executable, pid ); //We do not have a name yet, use executable if ( gui_is_active ) { @@ -725,7 +733,7 @@ command_client_to_save ( Client *c ) { if ( c->active ) { - MESSAGE( "Telling %s to save", c->name ); + MESSAGE( "Telling %s to save", c->name_with_id() ); osc_server->send( c->addr, "/nsm/client/save" ); c->pending_command( COMMAND_SAVE ); @@ -749,7 +757,7 @@ void command_client_to_switch ( Client *c, const char *new_client_id ) char *client_project_path = get_client_project_path( session_path, c ); - MESSAGE( "Commanding %s to switch \"%s\"", c->name, client_project_path ); + MESSAGE( "Commanding %s to switch \"%s\"", c->name_with_id(), client_project_path ); char *full_client_id; asprintf( &full_client_id, "%s.%s", c->name, c->client_id ); @@ -893,7 +901,7 @@ OSC_HANDLER( announce ) (*i)->pending_command() == COMMAND_START ) { // I think we've found the slot we were looking for. - MESSAGE( "Client was expected." ); + MESSAGE( "Client %s was expected.", (*i)->name ); c = *i; break; } @@ -910,7 +918,7 @@ OSC_HANDLER( announce ) if ( major > NSM_API_VERSION_MAJOR ) { - MESSAGE( "Client is using incompatible and more recent API version %i.%i", major, minor ); + MESSAGE( "Client %s is using incompatible and more recent API version %i.%i", c->name_with_id(), major, minor ); osc_server->send( lo_message_get_source( msg ), "/error", path, @@ -926,7 +934,7 @@ OSC_HANDLER( announce ) c->name = strdup( client_name ); c->active = true; - MESSAGE( "Process %s has pid: %i", c->name, pid ); + MESSAGE( "Process %s has pid: %i", c->name_with_id(), pid ); if ( ! expected_client ) client.push_back( c ); @@ -1014,7 +1022,10 @@ dumb_clients_are_alive ( ) ++i ) { if ( (*i)->is_dumb_client() && (*i)->pid > 0 ) - return true; + { + MESSAGE( "Waiting for %s", (*i)->name_with_id() ); //This replaced the Loop 1, Loop 2 ... 60 message from wait_for_dumb_clients_to_die where you couldn't see which client actually was hanging + return true; + } } return false; @@ -1029,8 +1040,6 @@ wait_for_dumb_clients_to_die ( ) for ( int i = 0; i < 6; i++ ) { - MESSAGE( "Loop %i", i ); - if ( ! dumb_clients_are_alive() ) break; @@ -1063,7 +1072,10 @@ killed_clients_are_alive ( ) if ( ( (*i)->pending_command() == COMMAND_QUIT || (*i)->pending_command() == COMMAND_KILL ) && (*i)->pid > 0 ) - return true; + { + MESSAGE( "Waiting for %s", (*i)->name_with_id() ); //This replaced the Loop 1, Loop 2 ... 60 message from wait_for_killed_clients_to_die where you couldn't see which client actually was hanging + return true; + } } return false; @@ -1078,8 +1090,6 @@ wait_for_killed_clients_to_die ( ) for ( int i = 0; i < 60; i++ ) { - MESSAGE( "Loop %i", i ); - if ( ! killed_clients_are_alive() ) goto done; @@ -1132,7 +1142,7 @@ command_all_clients_to_save ( ) void command_client_to_stop ( Client *c ) { - GUIMSG( "Stopping client %s", c->name ); + GUIMSG( "Stopping client %s", c->name_with_id() ); if ( c->pid > 0 ) { @@ -1148,7 +1158,7 @@ command_client_to_stop ( Client *c ) void command_client_to_quit ( Client *c ) { - MESSAGE( "Commanding %s to quit", c->name ); + MESSAGE( "Commanding %s to quit", c->name_with_id() ); if ( c->active ) { @@ -1226,7 +1236,7 @@ tell_client_session_is_loaded( Client *c ) if ( c->active ) //!c->is_dumb_client() ) { - MESSAGE( "Telling client %s that session is loaded.", c->name ); + MESSAGE( "Telling client %s that session is loaded.", c->name_with_id() ); osc_server->send( c->addr, "/nsm/client/session_is_loaded" ); } } @@ -2048,7 +2058,7 @@ OSC_HANDLER( error ) c->set_reply( err_code, message ); - MESSAGE( "Client \"%s\" replied with error: %s (%i) in %fms", c->name, message, err_code, c->milliseconds_since_last_command() ); + MESSAGE( "Client \"%s\" replied with error: %s (%i) in %fms", c->name_with_id(), message, err_code, c->milliseconds_since_last_command() ); c->pending_command( COMMAND_NONE ); if ( gui_is_active ) @@ -2069,7 +2079,7 @@ OSC_HANDLER( reply ) { c->set_reply( ERR_OK, message ); - MESSAGE( "Client \"%s\" replied with: %s in %fms", c->name, message, c->milliseconds_since_last_command() ); + MESSAGE( "Client \"%s\" replied with: %s in %fms", c->name_with_id(), message, c->milliseconds_since_last_command() ); c->pending_command( COMMAND_NONE );