From: Pekka Riikonen Date: Fri, 25 Sep 2009 09:05:38 +0000 (+0300) Subject: silcd: Fixed SIGUSR1 signal handling X-Git-Tag: silc.client.1.1.9~37 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=dbcb39afedd5dba46a1c5e79e3ff7095c3e86454 silcd: Fixed SIGUSR1 signal handling Fixed the SIGUSR1 signal handling which can be used to dump the server internals to /tmp. Changed also End of Stream handling to handle NULL idata pointer instead of ignoring the EOS in case it is NULL. Changed also the DETACH timeout handling to use the packet stream directly instead of looking up client in the callback. --- diff --git a/apps/silcd/command.c b/apps/silcd/command.c index cafbb7c7..0ddc787e 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -4065,48 +4065,44 @@ SILC_TASK_CALLBACK(silc_server_command_detach_cb) { SilcServer server = app_context; QuitInternal q = (QuitInternal)context; - SilcClientID *client_id = (SilcClientID *)q->sock; - SilcClientEntry client; - SilcPacketStream sock; - SilcIDListData idata; - + SilcPacketStream sock = q->sock; + SilcClientEntry client = silc_packet_get_context(sock); + SilcIDListData idata = (SilcIDListData)client; - client = silc_idlist_find_client_by_id(server->local_list, client_id, - TRUE, NULL); - if (client && client->connection) { - sock = client->connection; + if (!client) { + silc_packet_stream_unref(sock); + silc_free(q); + return; + } - SILC_LOG_DEBUG(("Detaching client %s", - silc_id_render(client->id, SILC_ID_CLIENT))); + SILC_LOG_DEBUG(("Detaching client %s", + silc_id_render(client->id, SILC_ID_CLIENT))); - /* Stop rekey for the client. */ - silc_server_stop_rekey(server, client); + /* Stop rekey for the client. */ + silc_server_stop_rekey(server, client); - /* Abort any active protocol */ - idata = silc_packet_get_context(sock); - if (idata && idata->sconn && idata->sconn->op) { - SILC_LOG_DEBUG(("Abort active protocol")); - silc_async_abort(idata->sconn->op, NULL, NULL); - idata->sconn->op = NULL; - } + /* Abort any active protocol */ + idata = silc_packet_get_context(sock); + if (idata && idata->sconn && idata->sconn->op) { + SILC_LOG_DEBUG(("Abort active protocol")); + silc_async_abort(idata->sconn->op, NULL, NULL); + idata->sconn->op = NULL; + } - /* Close the connection on our side */ - client->router = NULL; - client->connection = NULL; - silc_server_close_connection(server, sock); + /* Close the connection on our side */ + client->router = NULL; + client->connection = NULL; + silc_server_close_connection(server, sock); - /* Mark the client as locally detached. */ - client->local_detached = TRUE; + /* Mark the client as locally detached. */ + client->local_detached = TRUE; - /* - * Decrement the user count; we'll increment it if the user resumes on our - * server. - */ - SILC_VERIFY(&server->stat.my_clients > 0); - server->stat.my_clients--; - } + /* Decrement the user count; we'll increment it if the user resumes on our + server. */ + SILC_VERIFY(&server->stat.my_clients > 0); + server->stat.my_clients--; - silc_free(client_id); + silc_packet_stream_unref(sock); silc_free(q); } @@ -4173,14 +4169,15 @@ SILC_SERVER_CMD_FUNC(detach) SILC_NOTIFY_TYPE_UMODE_CHANGE); q = silc_calloc(1, sizeof(*q)); - q->sock = silc_id_dup(client->id, SILC_ID_CLIENT); + q->sock = cmd->sock; + silc_packet_stream_ref(q->sock); silc_schedule_task_add_timeout(server->schedule, silc_server_command_detach_cb, q, 0, 200000); if (server->config->detach_timeout) { q = silc_calloc(1, sizeof(*q)); - q->sock = silc_id_dup(client->id, SILC_ID_CLIENT); + q->sock = (void *)silc_id_dup(client->id, SILC_ID_CLIENT); silc_schedule_task_add_timeout(server->schedule, silc_server_command_detach_timeout, q, server->config->detach_timeout * 60, 0); diff --git a/apps/silcd/server.c b/apps/silcd/server.c index e18c7de0..c2ba2247 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -196,25 +196,23 @@ static void silc_server_packet_eos(SilcPacketEngine engine, SILC_LOG_DEBUG(("End of stream received, sock %p", stream)); - if (!idata) - return; - if (server->router_conn && server->router_conn->sock == stream && !server->router && server->standalone) { - if (idata->sconn && idata->sconn->callback) + if (idata && idata->sconn && idata->sconn->callback) (*idata->sconn->callback)(server, NULL, idata->sconn->callback_context); silc_server_create_connections(server); silc_server_free_sock_user_data(server, stream, NULL); } else { /* If backup disconnected then mark that resuming will not be allowed */ - if (server->server_type == SILC_ROUTER && !server->backup_router && + if (idata && + server->server_type == SILC_ROUTER && !server->backup_router && idata->conn_type == SILC_CONN_SERVER) { SilcServerEntry server_entry = (SilcServerEntry)idata; if (server_entry->server_type == SILC_BACKUP_ROUTER) server->backup_closed = TRUE; } - if (idata->sconn && idata->sconn->callback) + if (idata && idata->sconn && idata->sconn->callback) (*idata->sconn->callback)(server, NULL, idata->sconn->callback_context); silc_server_free_sock_user_data(server, stream, NULL); } @@ -241,8 +239,8 @@ SILC_TASK_CALLBACK(silc_server_packet_error_timeout) silc_server_free_sock_user_data(server, stream, NULL); } else { /* If backup disconnected then mark that resuming will not be allowed */ - if (server->server_type == SILC_ROUTER && !server->backup_router && - idata->conn_type == SILC_CONN_SERVER) { + if (server->server_type == SILC_ROUTER && !server->backup_router && + idata->conn_type == SILC_CONN_SERVER) { SilcServerEntry server_entry = (SilcServerEntry)idata; if (server_entry->server_type == SILC_BACKUP_ROUTER) server->backup_closed = TRUE; diff --git a/apps/silcd/silcd.c b/apps/silcd/silcd.c index e9694bba..de4ad03a 100644 --- a/apps/silcd/silcd.c +++ b/apps/silcd/silcd.c @@ -309,7 +309,6 @@ SILC_TASK_CALLBACK(dump_stats) #undef STAT_OUTPUT -#ifdef SILC_DEBUG /* Dump internal flags */ fprintf(fdd, "\nDumping internal flags\n"); fprintf(fdd, " server_type : %d\n", silcd->server_type); @@ -340,9 +339,9 @@ SILC_TASK_CALLBACK(dump_stats) if (!silc_socket_stream_get_info(silc_packet_stream_get_stream(s), &sock, &hostname, &ip, &port)) continue; - fprintf(fdd, " %d: host %s ip %s port %d type %d\n", + fprintf(fdd, " %d: host %s ip %s port %d type %d idata %p\n", sock, hostname ? hostname : "N/A", - ip ? ip : "N/A", port, idata ? idata->conn_type : 0); + ip ? ip : "N/A", port, idata ? idata->conn_type : 0, idata); } silc_dlist_uninit(conns); } @@ -361,64 +360,69 @@ SILC_TASK_CALLBACK(dump_stats) if (silc_idcache_get_all(silcd->local_list->servers, &list)) { c = 1; fprintf(fdd, "\nServers in local-list:\n"); + silc_list_start(list); while ((id_cache = silc_list_get(list))) { server_entry = (SilcServerEntry)id_cache->context; - fprintf(fdd, " %d: name %s id %s status 0x%x\n", c, + fprintf(fdd, " %d: name %s id %s status 0x%x idata %p\n", c, server_entry->server_name ? server_entry->server_name : "N/A", server_entry->id ? silc_id_render(server_entry->id, SILC_ID_SERVER) : "N/A", - server_entry->data.status); + server_entry->data.status, server_entry); c++; } } if (silc_idcache_get_all(silcd->global_list->servers, &list)) { fprintf(fdd, "\nServers in global-list:\n"); c = 1; + silc_list_start(list); while ((id_cache = silc_list_get(list))) { server_entry = (SilcServerEntry)id_cache->context; - fprintf(fdd, " %d: name %s id %s status 0x%x\n", c, + fprintf(fdd, " %d: name %s id %s status 0x%x idata %p\n", c, server_entry->server_name ? server_entry->server_name : "N/A", server_entry->id ? silc_id_render(server_entry->id, SILC_ID_SERVER) : "N/A", - server_entry->data.status); + server_entry->data.status, server_entry); c++; } } if (silc_idcache_get_all(silcd->local_list->clients, &list)) { fprintf(fdd, "\nClients in local-list:\n"); c = 1; + silc_list_start(list); while ((id_cache = silc_list_get(list))) { client_entry = (SilcClientEntry)id_cache->context; server_entry = client_entry->router; - fprintf(fdd, " %d: name %s id %s status 0x%x from %s\n", c, + fprintf(fdd, " %d: name %s id %s status 0x%x from %s idata %p\n", c, client_entry->nickname ? client_entry->nickname : (unsigned char *)"N/A", client_entry->id ? silc_id_render(client_entry->id, SILC_ID_CLIENT) : "N/A", client_entry->data.status, server_entry ? server_entry->server_name ? server_entry->server_name : - "N/A" : "local"); + "N/A" : "local", client_entry); c++; } } if (silc_idcache_get_all(silcd->global_list->clients, &list)) { fprintf(fdd, "\nClients in global-list:\n"); c = 1; + silc_list_start(list); while ((id_cache = silc_list_get(list))) { client_entry = (SilcClientEntry)id_cache->context; server_entry = client_entry->router; - fprintf(fdd, " %d: name %s id %s status 0x%x from %s\n", c, + fprintf(fdd, " %d: name %s id %s status 0x%x from %s idata %p\n", c, client_entry->nickname ? client_entry->nickname : (unsigned char *)"N/A", client_entry->id ? silc_id_render(client_entry->id, SILC_ID_CLIENT) : "N/A", client_entry->data.status, server_entry ? server_entry->server_name ? server_entry->server_name : - "N/A" : "local"); + "N/A" : "local", client_entry); c++; } } if (silc_idcache_get_all(silcd->local_list->channels, &list)) { fprintf(fdd, "\nChannels in local-list:\n"); c = 1; + silc_list_start(list); while ((id_cache = silc_list_get(list))) { channel_entry = (SilcChannelEntry)id_cache->context; fprintf(fdd, " %d: name %s id %s\n", c, @@ -431,6 +435,7 @@ SILC_TASK_CALLBACK(dump_stats) if (silc_idcache_get_all(silcd->global_list->channels, &list)) { fprintf(fdd, "\nChannels in global-list:\n"); c = 1; + silc_list_start(list); while ((id_cache = silc_list_get(list))) { channel_entry = (SilcChannelEntry)id_cache->context; fprintf(fdd, " %d: name %s id %s\n", c, @@ -441,7 +446,6 @@ SILC_TASK_CALLBACK(dump_stats) } } } -#endif fflush(fdd); fclose(fdd);