jcs
/subtext
/amendments
/347
sysop: Handle malloc failure, add 'i' option to menu to do binkp update
jcs made amendment 347 about 1 year ago
--- sysop.c Mon Feb 27 13:45:30 2023
+++ sysop.c Wed Mar 1 17:26:42 2023
@@ -18,6 +18,7 @@
#include "subtext.h"
#include "ansi.h"
+#include "binkp.h"
#include "board.h"
#include "serial_local.h"
#include "session.h"
@@ -39,11 +40,12 @@ sysop_menu(struct session *s)
{
static const struct session_menu_option opts[] = {
{ 'm', "Mm", "Edit Message of the Day" },
- { 'h', "Hh", "Hang Up Modem" },
- { 'b', "Bb", "Manage Boards" },
- { 'f', "Ff", "Manage File Folders" },
- { 'u', "Uu", "Manage Users" },
- { 's', "Ss", "Change BBS Settings" },
+ { 'i', "Ii", "Force FidoNet Binkp processing" },
+ { 'h', "Hh", "Hang up modem" },
+ { 'b', "Bb", "Manage boards" },
+ { 'f', "Ff", "Manage file folders" },
+ { 'u', "Uu", "Manage users" },
+ { 's', "Ss", "Change BBS settings" },
{ 'q', "QqXx", "Return to main menu" },
{ '?', "?", "List menu options" },
};
@@ -73,6 +75,17 @@ sysop_menu(struct session *s)
session_flush(s);
serial_hangup();
break;
+ case 'i':
+ if (binkp_thread) {
+ session_printf(s, "Waking up binkp thread...\r\n");
+ session_flush(s);
+ uthread_wakeup(binkp_thread);
+ } else {
+ session_printf(s, "No binkp thread, starting...\r\n");
+ session_flush(s);
+ uthread_add(binkp_process, NULL);
+ }
+ break;
case 'm':
sysop_edit_motd(s);
break;
@@ -148,8 +161,9 @@ sysop_edit_boards(struct session *s)
if (dopts != NULL)
xfree(&dopts);
dopts = xmalloc(sizeof(opts) +
- (db->nboards * sizeof(struct session_menu_option)),
- "sysop_edit_boards opts");
+ (db->nboards * sizeof(struct session_menu_option)));
+ if (dopts == NULL)
+ return;
for (n = 0; n < db->nboards; n++) {
board = &db->boards[n];
opt = &dopts[n];
@@ -210,8 +224,9 @@ sysop_edit_boards(struct session *s)
}
break;
case 'n':
- board = xmalloczero(sizeof(struct board),
- "sysop_edit_boards board");
+ board = xmalloczero(sizeof(struct board));
+ if (board == NULL)
+ continue;
board->id = bile_next_id(db->bile, DB_BOARD_RTYPE);
board->restricted_posting = false;
board->restricted_viewing = false;
@@ -224,6 +239,10 @@ sysop_edit_boards(struct session *s)
}
new_board_bile = db_board_create(db, new_board, false);
+ if (new_board_bile == NULL) {
+ xfree(&board);
+ continue;
+ }
bile_close(new_board_bile);
db_cache_boards(db);
@@ -258,8 +277,7 @@ sysop_edit_boards(struct session *s)
memcpy(&db->boards[n], new_board, sizeof(struct board));
ret = bile_marshall_object(db->bile, board_object_fields,
- nboard_object_fields, &db->boards[n], &data, &size,
- "sysop_edit_boards");
+ nboard_object_fields, &db->boards[n], &data, &size);
if (ret != 0 || size == 0)
panic("db_board_create: failed to marshall object");
@@ -315,8 +333,9 @@ sysop_edit_folders(struct session *s)
if (dopts != NULL)
xfree(&dopts);
dopts = xmalloc(sizeof(opts) +
- (db->nboards * sizeof(struct session_menu_option)),
- "sysop_edit_folders opts");
+ (db->nboards * sizeof(struct session_menu_option)));
+ if (dopts == NULL)
+ return;
for (n = 0; n < db->nfolders; n++) {
folder = &db->folders[n];
opt = &dopts[n];
@@ -333,8 +352,9 @@ sysop_edit_folders(struct session *s)
switch (c) {
case 'n':
- folder = xmalloczero(sizeof(struct folder),
- "sysop_edit_folders folder");
+ folder = xmalloczero(sizeof(struct folder));
+ if (folder == NULL)
+ continue;
folder->id = bile_next_id(db->bile, DB_FOLDER_RTYPE);
folder->restricted_posting = false;
folder->restricted_viewing = false;
@@ -347,6 +367,11 @@ sysop_edit_folders(struct session *s)
}
new_folder_bile = db_folder_create(db, new_folder, false);
+ if (new_folder_bile == NULL) {
+ xfree(&folder);
+ xfree(&new_folder);
+ continue;
+ }
bile_close(new_folder_bile);
db_cache_folders(db);
@@ -381,8 +406,7 @@ sysop_edit_folders(struct session *s)
memcpy(&db->folders[n], new_folder, sizeof(struct folder));
ret = bile_marshall_object(db->bile, folder_object_fields,
- nfolder_object_fields, &db->folders[n], &data, &size,
- "sysop_edit_folders");
+ nfolder_object_fields, &db->folders[n], &data, &size);
if (ret != 0 || size == 0)
panic("db_folder_create: failed to marshall object");
@@ -646,9 +670,10 @@ sysop_find_user_ids(size_t nall_user_ids, unsigned lon
if (nuser_ids > limit)
nuser_ids = limit;
- *user_ids = xcalloc(sizeof(unsigned long), nuser_ids,
- "sysop_find_user_ids");
-
+ *user_ids = xcalloc(sizeof(unsigned long), nuser_ids);
+ if (*user_ids == NULL)
+ return 0;
+
for (n = 0; n < nuser_ids; n++) {
(*user_ids)[n] = all_user_ids[offset + n];
}