From 32e47b900ca0c0a0badf919f304a59ca89d66d0e Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sat, 20 Oct 2007 23:12:22 +0200 Subject: [PATCH] Fixes to get the /BIP RELOAD command to at least work in a quick test. - reuse existing channel infos - dont clear conn_list on end of irc_main and don't add the listener if conn_list is not empty at start of irc_main --- src/bip.c | 23 ++++++++++++++++------- src/connection.c | 4 +++- src/irc.c | 11 ++++++----- src/util.c | 1 - 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/bip.c b/src/bip.c index e493270..aa9a8bd 100644 --- a/src/bip.c +++ b/src/bip.c @@ -414,7 +414,19 @@ static int add_connection(bip_t *bip, struct user *user, list_t *data) MOVE_STRING(l->vhost, t->pdata); break; case LEX_CHANNEL: - ci = calloc(sizeof(struct chan_info), 1); + name = get_tuple_value(t->pdata, LEX_NAME); + if (name == NULL) { + conf_die("Channel with no name"); + return 0; + } + + ci = hash_get(&l->chan_infos, name); + if (!ci) { + ci = calloc(sizeof(struct chan_info), 1); + hash_insert(&l->chan_infos, name, ci); + /* FIXME: this order is not reloaded */ + list_add_last(&l->chan_infos_order, ci); + } ci->backlog = 1; while ((t2 = list_remove_first(t->pdata))) { @@ -431,9 +443,6 @@ static int add_connection(bip_t *bip, struct user *user, list_t *data) } } list_free(t->pdata); - - hash_insert(&l->chan_infos, ci->name, ci); - list_add_last(&l->chan_infos_order, ci); break; case LEX_FOLLOW_NICK: l->follow_nick = t->ndata; @@ -542,9 +551,9 @@ static int add_user(bip_t *bip, list_t *data) case LEX_NAME: MOVE_STRING(u->name, t->pdata); break; - case LEX_ADMIN: - u->admin = t->ndata; - break; + case LEX_ADMIN: + u->admin = t->ndata; + break; case LEX_PASSWORD: hash_binary(t->pdata, &u->password, &u->seed); free(t->pdata); diff --git a/src/connection.c b/src/connection.c index 946ef23..19aab41 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1011,8 +1011,10 @@ connection_t *accept_new(connection_t *cn) mylog(LOG_DEBUG, "Trying to accept new client on %d", cn->handle); err = accept(cn->handle, &sa, &sa_len); - if (err < 0) + if (err < 0) { + mylog(LOG_ERROR, "accept failed: %s", strerror(errno)); return NULL; + } socket_set_nonblock(err); conn = connection_init(cn->anti_flood, cn->ssl, cn->timeout, 0); diff --git a/src/irc.c b/src/irc.c index 9930e11..c266a66 100644 --- a/src/irc.c +++ b/src/irc.c @@ -2385,9 +2385,12 @@ void irc_main(bip_t *bip) { int timeleft = 1000; - /* XXX: This one MUST be first */ - /* TODO: maybe not anymore, check */ - list_add_first(&bip->conn_list, bip->listener); + /* + * If the list is empty, we are starting. Otherwise we are reloading, + * and conn_list is kept accross reloads. + */ + if (list_is_empty(&bip->conn_list)) + list_add_first(&bip->conn_list, bip->listener); while (!sighup) { connection_t *conn; @@ -2412,8 +2415,6 @@ void irc_main(bip_t *bip) bip_on_event(bip, conn); list_free(ready); } - while (list_remove_first(&bip->conn_list)) - ; while (list_remove_first(&bip->link_list)) ; while (list_remove_first(&bip->connecting_client_list)) diff --git a/src/util.c b/src/util.c index f916c84..e0dd817 100644 --- a/src/util.c +++ b/src/util.c @@ -625,4 +625,3 @@ int ischannel(char p) { return (p == '#' || p == '&' || p == '+' || p == '!'); } -