From 932601b8850dd65a0ed96e5c1718ca4eaf8a8474 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Thu, 8 May 2003 18:59:31 +0000 Subject: [PATCH] Added timeout check to mbuser --- ChangeLog | 3 + mbsebbs/bye.c | 182 ++++++++++++++++++++++----------------------- mbsebbs/exitinfo.c | 121 +++++++++++++++--------------- mbsebbs/mbuser.c | 3 + 4 files changed, 158 insertions(+), 151 deletions(-) diff --git a/ChangeLog b/ChangeLog index 264e469f..14edce60 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,9 @@ v0.37.3 09-Apr-2003. Added menu function display file. Display ascii textfiles now uses the More Y/n/= prompt. + mbuser: + Added nopper code during pack. + mbcico: Removed some heavy debug code from ttyio functions to increase throughput. diff --git a/mbsebbs/bye.c b/mbsebbs/bye.c index 340dd95c..c75a0e3e 100644 --- a/mbsebbs/bye.c +++ b/mbsebbs/bye.c @@ -4,7 +4,7 @@ * Purpose ...............: Hangup functions * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2003 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -51,117 +51,117 @@ int do_mailout = FALSE; void Good_Bye(int onsig) { - FILE *pUsrConfig, *pExitinfo; - char *temp; - long offset; - time_t t_end; + FILE *pUsrConfig, *pExitinfo; + char *temp; + long offset; + time_t t_end; - IsDoing("Hangup"); - temp = calloc(PATH_MAX, sizeof(char)); - Syslog('+', "Good_Bye()"); + IsDoing("Hangup"); + temp = calloc(PATH_MAX, sizeof(char)); + Syslog('+', "Good_Bye()"); - if (onsig != SIGHUP) - DisplayFile((char *)"goodbye"); + if (onsig != SIGHUP) + DisplayFile((char *)"goodbye"); - if (do_mailout) - CreateSema((char *)"mailout"); + if (do_mailout) + CreateSema((char *)"mailout"); - SaveLastCallers(); - - /* - * Update the users database record. - */ - sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT")); - if ((pUsrConfig = fopen(temp,"r+b")) != NULL) { - sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name); - if ((pExitinfo = fopen(temp,"rb")) != NULL) { - fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig); - offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize); - - fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo); - - usrconfig = exitinfo; - fclose(pExitinfo); - - usrconfig.iLastFileArea = iAreaNumber; - if (!iAreaNumber) - WriteError("Setting filearea to zero"); - - /* If time expired, do not say say successful logoff */ - if(!iExpired) - Syslog('+', "User successfully logged off BBS"); - - usrconfig.iLastMsgArea = iMsgAreaNumber; - - offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize); - if(fseek(pUsrConfig, offset, 0) != 0) { - WriteError("Can't move pointer in file %s", temp); - ExitClient(MBERR_GENERAL); - } - - fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig); - fclose(pUsrConfig); - } - } - - t_end = time(NULL); - Syslog(' ', "MBSEBBS finished in %s", t_elapsed(t_start, t_end)); - - /* - * Start shutting down this session - */ - socket_shutdown(mypid); - sprintf(temp, "%s/tmp/mbsebbs%d", getenv("MBSE_ROOT"), getpid()); - unlink(temp); + SaveLastCallers(); + /* + * Update the users database record. + */ + sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT")); + if ((pUsrConfig = fopen(temp,"r+b")) != NULL) { sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name); - unlink(temp); - free(temp); - unlink("taglist"); + if ((pExitinfo = fopen(temp,"rb")) != NULL) { + fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig); + offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize); + fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo); - /* - * Flush all data to the user, wait 5 seconds to - * be sure the user received all data, this program - * and parent are also finished. - */ - colour(7, 0); - fflush(stdout); - fflush(stdin); - sleep(5); + usrconfig = exitinfo; + fclose(pExitinfo); - Unsetraw(); - Free_Language(); - free(pTTY); + usrconfig.iLastFileArea = iAreaNumber; + if (!iAreaNumber) + WriteError("Setting filearea to zero"); + + /* If time expired, do not say say successful logoff */ + if (!iExpired) + Syslog('+', "User successfully logged off BBS"); + + usrconfig.iLastMsgArea = iMsgAreaNumber; + + offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize); + Syslog('b', "Good_Bye: write users.data at offset %ld", offset); + if (fseek(pUsrConfig, offset, 0) != 0) { + WriteError("Can't move pointer in file %s", temp); + ExitClient(MBERR_GENERAL); + } + + fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig); + fclose(pUsrConfig); + } + } + + t_end = time(NULL); + Syslog(' ', "MBSEBBS finished in %s", t_elapsed(t_start, t_end)); + + /* + * Start shutting down this session + */ + socket_shutdown(mypid); + sprintf(temp, "%s/tmp/mbsebbs%d", getenv("MBSE_ROOT"), getpid()); + unlink(temp); + + sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name); + unlink(temp); + free(temp); + unlink("taglist"); + + /* + * Flush all data to the user, wait 5 seconds to + * be sure the user received all data, this program + * and parent are also finished. + */ + colour(7, 0); + fflush(stdout); + fflush(stdin); + sleep(5); + + Unsetraw(); + Free_Language(); + free(pTTY); #ifdef MEMWATCH - mwTerm(); + mwTerm(); #endif - exit(onsig); + exit(onsig); } void Quick_Bye(int onsig) { - char *temp; + char *temp; - temp = calloc(PATH_MAX, sizeof(char)); - Syslog('+', "Quick_Bye"); - socket_shutdown(mypid); - sprintf(temp, "%s/tmp/mbsebbs%d", getenv("MBSE_ROOT"), getpid()); - unlink(temp); - free(temp); + temp = calloc(PATH_MAX, sizeof(char)); + Syslog('+', "Quick_Bye"); + socket_shutdown(mypid); + sprintf(temp, "%s/tmp/mbsebbs%d", getenv("MBSE_ROOT"), getpid()); + unlink(temp); + free(temp); - colour(7, 0); - fflush(stdout); - fflush(stdin); - sleep(3); + colour(7, 0); + fflush(stdout); + fflush(stdin); + sleep(3); - Free_Language(); - free(pTTY); + Free_Language(); + free(pTTY); #ifdef MEMWATCH - mwTerm(); + mwTerm(); #endif - exit(MBERR_OK); + exit(MBERR_OK); } diff --git a/mbsebbs/exitinfo.c b/mbsebbs/exitinfo.c index 677df0b4..d0392096 100644 --- a/mbsebbs/exitinfo.c +++ b/mbsebbs/exitinfo.c @@ -54,45 +54,46 @@ */ int InitExitinfo() { - FILE *pUsrConfig, *pExitinfo; - char *temp; - long offset; + FILE *pUsrConfig, *pExitinfo; + char *temp; + long offset; - temp = calloc(PATH_MAX, sizeof(char)); - sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT")); + temp = calloc(PATH_MAX, sizeof(char)); + sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT")); - if ((pUsrConfig = fopen(temp,"r+b")) == NULL) { - WriteError("$Can't open %s for writing", temp); - free(temp); - return FALSE; - } - - fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig); - offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize); - if(fseek(pUsrConfig, offset, 0) != 0) { - WriteError("$Can't move pointer in %s", temp); - free(temp); - return FALSE; - } - - fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig); - - exitinfo = usrconfig; - fclose(pUsrConfig); - - sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, usrconfig.Name); - if ((pExitinfo = fopen(temp, "w+b")) == NULL) { - WriteError("$Can't open %s for writing", temp); - free(temp); - return FALSE; - } else { - fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo); - fclose(pExitinfo); - if (chmod(temp, 0600)) - WriteError("$Can't chmod 0600 %s", temp); - } + if ((pUsrConfig = fopen(temp,"r+b")) == NULL) { + WriteError("$Can't open %s for writing", temp); free(temp); - return TRUE; + return FALSE; + } + + fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig); + offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize); + Syslog('b', "InitExitinfo: read users.data offset %ld", offset); + if (fseek(pUsrConfig, offset, 0) != 0) { + WriteError("$Can't move pointer in %s", temp); + free(temp); + return FALSE; + } + + fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig); + + exitinfo = usrconfig; + fclose(pUsrConfig); + + sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, usrconfig.Name); + if ((pExitinfo = fopen(temp, "w+b")) == NULL) { + WriteError("$Can't open %s for writing", temp); + free(temp); + return FALSE; + } else { + fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo); + fclose(pExitinfo); + if (chmod(temp, 0600)) + WriteError("$Can't chmod 0600 %s", temp); + } + free(temp); + return TRUE; } @@ -103,20 +104,20 @@ int InitExitinfo() */ void ReadExitinfo() { - FILE *pExitinfo; - char *temp; + FILE *pExitinfo; + char *temp; - temp = calloc(PATH_MAX, sizeof(char)); - sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName); - mkdirs(temp, 0770); - if ((pExitinfo = fopen(temp,"r+b")) == NULL) - InitExitinfo(); - else { - fflush(stdin); - fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo); - fclose(pExitinfo); - } - free(temp); + temp = calloc(PATH_MAX, sizeof(char)); + sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName); + mkdirs(temp, 0770); + if ((pExitinfo = fopen(temp,"r+b")) == NULL) + InitExitinfo(); + else { + fflush(stdin); + fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo); + fclose(pExitinfo); + } + free(temp); } @@ -127,19 +128,19 @@ void ReadExitinfo() */ void WriteExitinfo() { - FILE *pExitinfo; - char *temp; + FILE *pExitinfo; + char *temp; - temp = calloc(PATH_MAX, sizeof(char)); + temp = calloc(PATH_MAX, sizeof(char)); - sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName); - if ((pExitinfo = fopen(temp,"w+b")) == NULL) - WriteError("$WriteExitinfo() failed"); - else { - fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo); - fclose(pExitinfo); - } - free(temp); + sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName); + if ((pExitinfo = fopen(temp,"w+b")) == NULL) + WriteError("$WriteExitinfo() failed"); + else { + fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo); + fclose(pExitinfo); + } + free(temp); } diff --git a/mbsebbs/mbuser.c b/mbsebbs/mbuser.c index fb8198b0..6f1396ae 100644 --- a/mbsebbs/mbuser.c +++ b/mbsebbs/mbuser.c @@ -252,6 +252,7 @@ void UserPack(int days, int level, int pack) memset(&usr, 0, sizeof(usr)); if (CFG.slow_util && do_quiet) usleep(1); + Nopper(); } fclose(fin); delete = 0; @@ -311,6 +312,7 @@ void UserPack(int days, int level, int pack) if (CFG.slow_util && do_quiet) usleep(1); + Nopper(); if (usr.Deleted) { if (!do_quiet) { printf("Delete user %s\n", usr.Name); @@ -371,6 +373,7 @@ void UserPack(int days, int level, int pack) record = 0; while (fread(&usr, sizeof(usr), 1,fout) == 1) { + Nopper(); record++; fwrite(&usr, sizeof(usr), 1, fin); if (record >= highest)