commit c8394ca19a1a29adc4f41a8c4b17f4bebe32996b from: Omar Polo date: Tue Aug 01 08:05:37 2023 UTC use icbirc_quit() instead of setting a global flag commit - a3ace556e41271fcdec9ed53401171618bd2b142 commit + c8394ca19a1a29adc4f41a8c4b17f4bebe32996b blob - ebc761247f78ab664a591786033015e1199b42ce blob + 841ab73b7ddff7e6bc620c8c1d91c868c71901ac --- icb.c +++ icb.c @@ -37,6 +37,7 @@ #include "icb.h" #include "irc.h" +extern void icbirc_quit(void); extern int sync_write(int, const char *, int); static unsigned char icb_args(const char *, unsigned char, char [255][255]); @@ -46,7 +47,6 @@ static void icb_iwl(int, const char *, const char *, long, const char *, const char *); static void icb_send_hw(int, const char *); -extern int terminate_client; int icb_logged_in; static char icb_protolevel[256]; @@ -330,7 +330,7 @@ icb_cmd(const char *cmd, unsigned char len, int fd, in case 'g': /* Exit */ irc_send_notice(fd, "ICB Exit"); warnx("server Exit\n"); - terminate_client = 1; + icbirc_quit(); break; case 'i': /* Command Output */ if (!strcmp(args[0], "co")) { blob - 9cdf01853cb5fe6445274adef51b199a311c4223 blob + 87cf1ee5d96f3f46b996add411dce107b4dc4d1c --- icbirc.c +++ icbirc.c @@ -50,12 +50,15 @@ #include "icb.h" #include "irc.h" +void icbirc_quit(void); int sync_write(int, const char *, int); static void usage(void); -int terminate_client; static struct sockaddr_in sa_connect; +time_t t; +unsigned long bytes_in, bytes_out; + static void usage(void) { @@ -74,8 +77,6 @@ main(int argc, char *argv[]) unsigned port_connect = 7326; int ch; int listen_fd = -1, server_fd = -1; - time_t t; - unsigned long bytes_in, bytes_out; #ifdef __OpenBSD__ if (pledge("stdio inet dns", NULL) == -1) @@ -205,9 +206,16 @@ main(int argc, char *argv[]) } } + icbirc_quit(); +} + +void +icbirc_quit(void) +{ irc_send_notice(1, "*** Closing connection " "(%u seconds, %lu:%lu bytes)", time(NULL) - t, bytes_out, bytes_in); + exit(0); } int blob - f5c679be798f6b9f38fe35cce46877181ce6d9dc blob + 3587f0597b9fb900f14bc97b9b03687be5a84343 --- irc.c +++ irc.c @@ -39,14 +39,13 @@ extern void scan(const char **, char *, size_t, const char *, const char *); +extern void icbirc_quit(void); extern int sync_write(int, const char *, int); static void irc_cmd(char *, int, int); static void irc_send_pong(int, const char *); -extern int terminate_client; - char irc_pass[256]; char irc_ident[256]; char irc_nick[256]; @@ -194,7 +193,7 @@ irc_cmd(char *cmd, int client_fd, int server_fd) irc_send_pong(client_fd, argv[1]); } else if (!strcasecmp(argv[0], "QUIT")) { warnx("client QUIT\n"); - terminate_client = 1; + icbirc_quit(); } else warnx("irc_cmd: unknown command '%s'\n", argv[0]); }