From: Dave West Date: Thu, 23 Aug 2007 19:43:29 +0000 (+0000) Subject: Patches from Matt with slight mod from me to do without strlen. Also modified lprintf... X-Git-Tag: v7.86~3119 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=0f911dcac6e52ee8f86a5429f61fc63d3e293a4a Patches from Matt with slight mod from me to do without strlen. Also modified lprintf to be atomic when logging to screen. --- diff --git a/citadel/citadel.c b/citadel/citadel.c index 920f06cc4..e9c979adb 100644 --- a/citadel/citadel.c +++ b/citadel/citadel.c @@ -517,6 +517,8 @@ void gotonext(CtdlIPC *ipc) */ mptr = (struct march *) malloc(sizeof(struct march)); mptr->next = NULL; + mptr->march_order = 0; + mptr->march_floor = 0; strcpy(mptr->march_name, "_BASEROOM_"); if (march == NULL) { march = mptr; @@ -747,8 +749,18 @@ void gotoroomstep(CtdlIPC *ipc, int direction, int mode) struct ctdlroomlisting *rs; int list_it; char rmname[ROOMNAMELEN]; - int rmslot; + int rmslot = 0; int rmtotal; + struct ctdlroom *attr = NULL; + + /* Fetch the existing room config */ + r = CtdlIPCGetRoomAttributes(ipc, &attr, buf); + if (r / 100 != 2) { + scr_printf("%s\n", buf); + return; + } + strcpy (room_name , attr->QRname); + free(attr); /* Ask the server for a room list */ r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf); diff --git a/citadel/citadel_ipc.c b/citadel/citadel_ipc.c index df52ea719..54d076e84 100644 --- a/citadel/citadel_ipc.c +++ b/citadel/citadel_ipc.c @@ -121,7 +121,7 @@ int CtdlIPCEcho(CtdlIPC *ipc, const char *arg, char *cret) int CtdlIPCQuit(CtdlIPC *ipc) { register int ret = 221; /* Default to successful quit */ - char aaa[128]; + char aaa[SIZ]; CtdlIPC_lock(ipc); if (ipc->sock > -1) { @@ -149,7 +149,7 @@ int CtdlIPCQuit(CtdlIPC *ipc) int CtdlIPCLogout(CtdlIPC *ipc) { register int ret; - char aaa[128]; + char aaa[SIZ]; CtdlIPC_lock(ipc); CtdlIPC_putline(ipc, "LOUT"); @@ -2335,6 +2335,7 @@ int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path, char aaa[SIZ]; char buf[4096]; FILE *fd; + int ferr; if (!cret) return -1; if (!path) return -1; @@ -2379,7 +2380,9 @@ int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path, } if (progress_gauge_callback) progress_gauge_callback(ipc, 1, 1); - return (!ferror(fd) ? ret : -2); + ferr = ferror(fd); + fclose(fd); + return (!ferr ? ret : -2); } @@ -2870,8 +2873,8 @@ static void CtdlIPC_getline(CtdlIPC* ipc, char *buf) serv_read(ipc, &buf[i], 1); /* Strip the trailing newline (and carriage return, if present) */ - if (buf[i] == 10) buf[i--] = 0; - if (buf[i] == 13) buf[i--] = 0; + if (i>=0 && buf[i] == 10) buf[i--] = 0; + if (i>=0 && buf[i] == 13) buf[i--] = 0; } void CtdlIPC_chat_recv(CtdlIPC* ipc, char* buf) diff --git a/citadel/citserver.c b/citadel/citserver.c index 87f4f6f82..43c0567bf 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -175,9 +175,6 @@ void master_cleanup(int exitcode) { lprintf(CTDL_INFO, "Closing databases\n"); close_databases(); - /* flush the networker stuff */ -/* destroy_network_queue_room();*/ - /* Do system-dependent stuff */ sysdep_master_cleanup(); @@ -369,8 +366,9 @@ int is_public_client(void) } else ptr++; } - while (isspace((buf[strlen(buf)-1]))) { - buf[strlen(buf)-1] = 0; + ptr--; + while (ptr>buf && isspace(*ptr)) { + *(ptr--) = 0; } if (hostname_to_dotted_quad(addrbuf, buf) == 0) { if ((strlen(public_clients) + diff --git a/citadel/client_chat.c b/citadel/client_chat.c index 535055fc9..a1ad06ce1 100644 --- a/citadel/client_chat.c +++ b/citadel/client_chat.c @@ -84,6 +84,7 @@ void chatmode(CtdlIPC *ipc) strcpy(buf, ""); strcpy(wbuf, ""); + strcpy(last_user, ""); color(BRIGHT_YELLOW); sln_printf_if("\n"); sln_printf("> "); diff --git a/citadel/messages.c b/citadel/messages.c index 79e03b1b4..7de1c2329 100644 --- a/citadel/messages.c +++ b/citadel/messages.c @@ -411,9 +411,11 @@ int read_message(CtdlIPC *ipc, if (r / 100 != 1) { err_printf("*** msg #%ld: %d %s\n", num, r, buf); ++lines_printed; - lines_printed = - checkpagin(lines_printed, pagin, screenheight); + lines_printed = checkpagin(lines_printed, pagin, screenheight); stty_ctdl(0); + free(message->text); + free_parts(message->attachments); + free(message); return (0); } @@ -461,6 +463,9 @@ int read_message(CtdlIPC *ipc, } pprintf("\n"); stty_ctdl(0); + free(message->text); + free_parts(message->attachments); + free(message); return (0); } @@ -669,7 +674,7 @@ int read_message(CtdlIPC *ipc, if (sigcaught == 0) { linelen = strlen(lineptr); - if (lineptr[linelen-1] == '\r') { + if (linelen && (lineptr[linelen-1] == '\r')) { lineptr[--linelen] = 0; } if (dest) { @@ -697,6 +702,7 @@ int read_message(CtdlIPC *ipc, scr_printf("\n"); ++lines_printed; lines_printed = checkpagin(lines_printed, pagin, screenheight); + fr = sigcaught; } } @@ -1630,10 +1636,10 @@ RMSGREAD: scr_flush(); r = CtdlIPCSetMessageSeen(ipc, msg_arr[a], 1, buf); } - if (e == 3) + if (e == SIGQUIT) return; - if (((userflags & US_NOPROMPT) || (e == 2)) - && (((room_flags & QR_MAILBOX) == 0) + if (((userflags & US_NOPROMPT) || (e == SIGINT)) + && (((room_flags & QR_MAILBOX) == 0) || (rc_force_mail_prompts == 0))) { e = 'n'; } else { diff --git a/citadel/modules/network/serv_network.c b/citadel/modules/network/serv_network.c index 71dc40a26..29ad8379b 100644 --- a/citadel/modules/network/serv_network.c +++ b/citadel/modules/network/serv_network.c @@ -1435,6 +1435,7 @@ void network_process_buffer(char *buffer, long size) { * connected that it's inevitable.) */ if (network_usetable(msg) != 0) { + CtdlFreeMessage(msg); return; } @@ -1706,9 +1707,9 @@ void receive_spool(int sock, char *remote_nodename) { return; } if (download_len > 0) - lprintf(CTDL_NOTICE, "Received %ld octets from <%s>", + lprintf(CTDL_NOTICE, "Received %ld octets from <%s>\n", download_len, remote_nodename); - lprintf(CTDL_DEBUG, "%s", buf); + lprintf(CTDL_DEBUG, "%s\n", buf); /* TODO: make move inline. forking is verry expensive. */ snprintf(buf, sizeof buf, diff --git a/citadel/room_ops.c b/citadel/room_ops.c index 3cfd2af32..caed7a305 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -520,7 +520,7 @@ int sort_msglist(long listptrs[], int oldcount) /* and yank any nulls */ while ((numitems > 0) && (listptrs[0] == 0L)) { - memcpy(&listptrs[0], &listptrs[1], + memmove(&listptrs[0], &listptrs[1], (sizeof(long) * (numitems - 1))); --numitems; } @@ -1882,7 +1882,7 @@ void cmd_cre8(char *args) if (CtdlAccessCheck(ac_logged_in)) return; - if (CC->user.axlevel < config.c_createax || CC->internal_pgm) { + if (CC->user.axlevel < config.c_createax && !CC->internal_pgm) { cprintf("%d You need higher access to create rooms.\n", ERROR + HIGHER_ACCESS_REQUIRED); return; diff --git a/citadel/routines.c b/citadel/routines.c index 41d971e8a..30db9a5ce 100644 --- a/citadel/routines.c +++ b/citadel/routines.c @@ -59,7 +59,7 @@ struct utmp *getutline(struct utmp *ut); #define IFNAIDE if (axlevel<6) extern unsigned userflags; -extern char *axdefs[7]; +//extern char *axdefs[8]; extern char sigcaught; extern char rc_floor_mode; extern int rc_ansi_color; @@ -159,7 +159,10 @@ void edituser(CtdlIPC *ipc, int cmd) if (cmd == 96) { scr_printf("Do you want to delete this user? "); - if (!yesno()) return; + if (!yesno()) { + free(user); + return; + } user->axlevel = 0; } diff --git a/citadel/routines2.c b/citadel/routines2.c index 3687f06ea..93c1814e5 100644 --- a/citadel/routines2.c +++ b/citadel/routines2.c @@ -51,7 +51,7 @@ extern char temp[]; extern char tempdir[]; -extern char *axdefs[7]; +extern char *axdefs[8]; extern long highest_msg_read; extern long maxmsgnum; extern unsigned room_flags; @@ -451,6 +451,11 @@ int val_user(CtdlIPC *ipc, char *user, int do_validate) if (a == 11) scr_printf("%s\n", buf); } while (!IsEmptyStr(resp)); + +/* TODODRW: discrepancy here. Parts of the code refer to axdefs[7] as the highest + * but most of it limits it to axdefs[6]. + * Webcit limits to 6 as does the code here but there are 7 in axdefs.h + */ scr_printf("Current access level: %d (%s)\n", ax, axdefs[ax]); } else { scr_printf("%s\n%s\n", user, &cmd[4]); diff --git a/citadel/screen.c b/citadel/screen.c index 398f945ce..a1d8abd75 100644 --- a/citadel/screen.c +++ b/citadel/screen.c @@ -86,7 +86,7 @@ void status_line(const char *humannode, const char *site_location, #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES) void wait_indicator(int state) { - if (!isendwin() && statuswindow) { + if (statuswindow && !isendwin()) { mvwinch(statuswindow, 0, screenwidth - 2); switch (state) { diff --git a/citadel/server.h b/citadel/server.h index 927abb6e8..3d1c9c487 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -237,6 +237,7 @@ enum { S_RPLIST, S_SIEVELIST, S_CHKPWD, + S_LOG, MAX_SEMAPHORES }; diff --git a/citadel/server_main.c b/citadel/server_main.c index 318f72e2b..4c69e6083 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -87,6 +87,11 @@ int main(int argc, char **argv) #ifdef HAVE_RUN_DIR struct stat filestats; #endif + + /* initialise semaphores here. Patch by Matt and davew + * its called here as they are needed by lprintf for thread safety + */ + InitialiseSemaphores(); /* initialize the master context */ InitializeMasterCC(); diff --git a/citadel/setup.c b/citadel/setup.c index 1e741f002..bf1374d5a 100644 --- a/citadel/setup.c +++ b/citadel/setup.c @@ -752,8 +752,8 @@ void edit_value(int curr) config.c_ctdluid = atoi(ctdluidname); } } - } #endif + } break; case 3: diff --git a/citadel/sysdep.c b/citadel/sysdep.c index cd7f12107..94029bc68 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -103,6 +103,7 @@ void DestroyWorkerList(void); * lprintf() ... Write logging information */ void lprintf(enum LogLevel loglevel, const char *format, ...) { + char *buf; va_list arg_ptr; if (enable_syslog) { @@ -112,7 +113,9 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) { } /* stderr output code */ - if (enable_syslog || running_as_daemon) return; + if (enable_syslog || running_as_daemon) { + return; + } /* if we run in forground and syslog is disabled, log to terminal */ if (loglevel <= verbosity) { @@ -124,24 +127,30 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) { /* Promote to time_t; types differ on some OSes (like darwin) */ unixtime = tv.tv_sec; localtime_r(&unixtime, &tim); +// begin_critical_section(S_LOG); + + buf = malloc(SIZ+strlen(format)); + if (CC->cs_pid != 0) { - fprintf(stderr, + sprintf(buf, "%04d/%02d/%02d %2d:%02d:%02d.%06ld [%3d] ", tim.tm_year + 1900, tim.tm_mon + 1, tim.tm_mday, tim.tm_hour, tim.tm_min, tim.tm_sec, (long)tv.tv_usec, CC->cs_pid); } else { - fprintf(stderr, + sprintf(buf, "%04d/%02d/%02d %2d:%02d:%02d.%06ld ", tim.tm_year + 1900, tim.tm_mon + 1, tim.tm_mday, tim.tm_hour, tim.tm_min, tim.tm_sec, (long)tv.tv_usec); } - va_start(arg_ptr, format); - vfprintf(stderr, format, arg_ptr); + strcat(buf, format); + va_start(arg_ptr, buf); + vfprintf(stderr, buf, arg_ptr); va_end(arg_ptr); fflush(stderr); +// end_critical_section(S_LOG); } } @@ -162,11 +171,25 @@ static RETSIGTYPE signal_cleanup(int signum) { master_cleanup(signum); } + + + +void InitialiseSemaphores(void) +{ + int i; + + /* Set up a bunch of semaphores to be used for critical sections */ + for (i=0; i