]> jfr.im git - solanum.git/blobdiff - ircd/sslproc.c
client: always purge a client from the connid table, as connid is not related to FD
[solanum.git] / ircd / sslproc.c
index fa3afba7d97690c1c2fb42972ccf92736b22bdf5..9b79a2461d3c48be709adc92623c894b05cb1bd4 100644 (file)
@@ -66,6 +66,7 @@ struct _ssl_ctl
        pid_t pid;
        rb_dlink_list readq;
        rb_dlink_list writeq;
+       uint8_t shutdown;
        uint8_t dead;
 };
 
@@ -150,6 +151,31 @@ static time_t last_spin;
 static int ssld_wait = 0;
 
 
+void
+restart_ssld(void)
+{
+       rb_dlink_node *ptr, *next;
+       ssl_ctl_t *ctl;
+
+       RB_DLINK_FOREACH_SAFE(ptr, next, ssl_daemons.head)
+       {
+               ctl = ptr->data;
+               if(ctl->dead)
+                       continue;
+               if(ctl->shutdown)
+                       continue;
+               ctl->shutdown = 1;
+               ssld_count--;
+               if(!ctl->cli_count)
+               {
+                       rb_kill(ctl->pid, SIGKILL);
+                       free_ssl_daemon(ctl);
+               }
+       }
+
+       start_ssldaemon(ServerInfo.ssld_count, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params, ServerInfo.ssl_cipher_list);
+}
+
 static void
 ssl_killall(void)
 {
@@ -161,8 +187,11 @@ ssl_killall(void)
                if(ctl->dead)
                        continue;
                ctl->dead = 1;
-               ssld_count--;
+               if(!ctl->shutdown)
+                       ssld_count--;
                rb_kill(ctl->pid, SIGKILL);
+               if(!ctl->cli_count)
+                       free_ssl_daemon(ctl);
        }
 }
 
@@ -173,11 +202,15 @@ ssl_dead(ssl_ctl_t * ctl)
                return;
 
        ctl->dead = 1;
-       ssld_count--;
        rb_kill(ctl->pid, SIGKILL);     /* make sure the process is really gone */
-       ilog(L_MAIN, "ssld helper died - attempting to restart");
-       sendto_realops_snomask(SNO_GENERAL, L_ALL, "ssld helper died - attempting to restart");
-       start_ssldaemon(1, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params, ServerInfo.ssl_cipher_list);
+
+       if(!ctl->shutdown)
+       {
+               ssld_count--;
+               ilog(L_MAIN, "ssld helper died - attempting to restart");
+               sendto_realops_snomask(SNO_GENERAL, L_ALL, "ssld helper died - attempting to restart");
+               start_ssldaemon(1, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params, ServerInfo.ssl_cipher_list);
+       }
 }
 
 static void
@@ -541,6 +574,8 @@ which_ssld(void)
                ctl = ptr->data;
                if(ctl->dead)
                        continue;
+               if(ctl->shutdown)
+                       continue;
                if(lowest == NULL)
                {
                        lowest = ctl;
@@ -703,6 +738,8 @@ start_ssld_accept(rb_fde_t * sslF, rb_fde_t * plainF, uint32_t id)
        buf[0] = 'A';
        uint32_to_buf(&buf[1], id);
        ctl = which_ssld();
+       if(!ctl)
+               return NULL;
        ctl->cli_count++;
        ssl_cmd_write_queue(ctl, F, 2, buf, sizeof(buf));
        return ctl;
@@ -721,6 +758,8 @@ start_ssld_connect(rb_fde_t * sslF, rb_fde_t * plainF, uint32_t id)
        uint32_to_buf(&buf[1], id);
 
        ctl = which_ssld();
+       if(!ctl)
+               return NULL;
        ctl->cli_count++;
        ssl_cmd_write_queue(ctl, F, 2, buf, sizeof(buf));
        return ctl;
@@ -733,6 +772,11 @@ ssld_decrement_clicount(ssl_ctl_t * ctl)
                return;
 
        ctl->cli_count--;
+       if(ctl->shutdown && !ctl->cli_count)
+       {
+               ctl->dead = 1;
+               rb_kill(ctl->pid, SIGKILL);
+       }
        if(ctl->dead && !ctl->cli_count)
        {
                free_ssl_daemon(ctl);
@@ -832,6 +876,12 @@ start_zlib_session(void *data)
        add_to_cli_connid_hash(server);
 
        server->localClient->z_ctl = which_ssld();
+       if(!server->localClient->z_ctl)
+       {
+               exit_client(server, server, server, "Error finding available ssld");
+               rb_free(buf);
+               return;
+       }
        server->localClient->z_ctl->cli_count++;
        ssl_cmd_write_queue(server->localClient->z_ctl, F, 2, buf, len);
        rb_free(buf);
@@ -887,6 +937,20 @@ get_ssld_count(void)
        return ssld_count;
 }
 
+void
+ssld_foreach_info(void (*func)(void *data, pid_t pid, int cli_count, enum ssld_status status), void *data)
+{
+       rb_dlink_node *ptr, *next;
+       ssl_ctl_t *ctl;
+       RB_DLINK_FOREACH_SAFE(ptr, next, ssl_daemons.head)
+       {
+               ctl = ptr->data;
+               func(data, ctl->pid, ctl->cli_count,
+                       ctl->dead ? SSLD_DEAD :
+                               (ctl->shutdown ? SSLD_SHUTDOWN : SSLD_ACTIVE));
+       }
+}
+
 void
 init_ssld(void)
 {