AmendHub

Download:

jcs

/

subtext

/

amendments

/

430

session: Add buf canary stuff, only finalize session log if logged in

This is probably the cause of the session log getting really big...

jcs made amendment 430 about 1 year ago
--- session.c Sat Mar 11 13:47:20 2023 +++ session.c Wed Mar 15 18:38:01 2023 @@ -85,6 +85,11 @@ session_create(char *node, char *via, struct node_func strlcpy(session->via, via, sizeof(session->via)); session->last_input_at = session->established_at = Time; + session->obuf_canary = 0xffffffff; + session->ibuf_canary = 0xffffffff; + session->obuflen_canary = 0xffffffff; + session->ibuflen_canary = 0xffffffff; + for (n = 0; n < MAX_SESSIONS; n++) { if (sessions[n] != NULL) continue; @@ -311,8 +316,8 @@ get_another_char: case ACTION_WHOS_ONLINE: session_who(s); break; - case ACTION_BOARD_LIST_FIDONET: - board_list_fidonet_boards(s); + case ACTION_BOARD_LIST_FTN_AREAS: + board_list_ftn_areas(s); break; case ACTION_BOARD_SHOW_1: board_show(s, 1, NULL); @@ -425,14 +430,16 @@ session_close(struct session *session) session->ending = true; } - /* finalize session log */ - session->log.logged_off_at = Time; + if (session->log.logged_on_at) { + /* finalize session log */ + session->log.logged_off_at = Time; + + if (bile_write(db->sessions_bile, SL_LOG_RTYPE, session->log.id, + &session->log, sizeof(session->log)) != sizeof(session->log)) + panic("bile_write of session log failed: %d", + bile_error(db->sessions_bile)); + } - if (bile_write(db->sessions_bile, SL_LOG_RTYPE, session->log.id, - &session->log, sizeof(session->log)) != sizeof(session->log)) - panic("bile_write of session log failed: %d", - bile_error(db->sessions_bile)); - /* close the node */ session->node_funcs->close(session); @@ -458,6 +465,19 @@ session_close(struct session *session) } void +session_check_buf_canaries(struct session *session) +{ + if (session->obuf_canary != 0xffffffff) + warn("obuf canary dead"); + if (session->ibuf_canary != 0xffffffff) + warn("ibuf canary dead"); + if (session->obuflen_canary != 0xffffffff) + warn("obuflen canary dead"); + if (session->ibuflen_canary != 0xffffffff) + warn("ibuflen canary dead"); +} + +void session_flush(struct session *session) { if (session->ending || session->obuflen == 0) @@ -465,6 +485,7 @@ session_flush(struct session *session) while (session->obuflen != 0) { session->node_funcs->output(session); + session_check_buf_canaries(session); if (session->obuflen != 0) uthread_yield(); if (session->ending) @@ -546,6 +567,8 @@ session_output(struct session *session, const char *st len -= chunk; } + session_check_buf_canaries(session); + return olen; } @@ -694,7 +717,7 @@ session_get_char(struct session *session, unsigned cha if (session->ibuflen == 0) return 0; } - + session->last_input_at = Time; *b = session->ibuf[session->ibufoff]; @@ -707,6 +730,8 @@ session_get_char(struct session *session, unsigned cha session->ibufoff++; } + session_check_buf_canaries(session); + return 1; } @@ -735,6 +760,7 @@ session_wait_for_chars(struct session *session, unsign } session->last_input_at = Time; + session_check_buf_canaries(session); return true; } @@ -1637,16 +1663,19 @@ get_menu_option: } void -session_purge_logs(short days) +session_prune_logs(short days) { struct bile_object *obj; struct session_log log; size_t n, size = 0, count = 0, delta; unsigned long secs, *ids = NULL; + if (days < 1) + return; + secs = (60UL * 60UL * 24UL * (unsigned long)days); - logger_printf("[db] Purging session logs older than %d days", days); + logger_printf("[db] Pruning session logs older than %d days", days); for (n = 0; (obj = bile_get_nth_of_type(db->sessions_bile, n, SL_LOG_RTYPE)); @@ -1663,6 +1692,8 @@ session_purge_logs(short days) xfree(&obj); } + + uthread_yield(); if (count) { logger_printf("[db] Deleting %ld of %ld log entries", count, n);