Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
parse description bug
Dec 15, 2017, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, DotBot

Members: 0
Guests: 7
Stats
Files
Topics
Posts
Members
Newest Member
477
3,706
19,240
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SmaugFUSS » Files that don't get closed w...
Forum Rules | Mark all | Recent Posts

Files that don't get closed will eventually lock out players
< Newer Topic :: Older Topic > Hi Priority bug as far as my mud co

Pages:<< prev 1 next >>
Post is unread #1 Aug 20, 2005, 4:13 pm
Go to the top of the page
Go to the bottom of the page

Conner
Sorcerer
GroupMembers
Posts870
JoinedMay 8, 2005

Rogue wrote this snippet for distribution after resolving the problem on our mud for us this way.

In SmaugFUSS (presumably in Smaug 1.4a as well) there is a known bug in which after awhile too many files will have been left open to continue opeing any more files.

This results in returning players being told that they can not log on because their character does not exist and that the name is now illegal as well, it also results in players already online not being able to save (though they will still see the standard 'ok' when they try to do so.) Sadly, this also results in immortals currently online being spammed to death by bug reports and many other things not saving properly, as well as having the last log reset.

The attached snippet fixes all of these errors by watching for files that get opened and if they are not closed after a few seconds, it closes them. This snippet also outputs to your log file the names of each file being opened and closed and whether it was opened or closed so that you can see the sequence thereof and ensure nothing is being missed. There are a few special case files which appear to need to remain opened, but that is addressed here as well.

Many thanks to Rogue for providing this wonderful fix to the mud community. However, please be warned that this snippet has thus far only been tested on our own mud which is a heavily modified version of SmaugFUSS 1.6 but the nature of this snippet should allow it to work as written on any smaug mud.

/* (c) 2005 By Rogue. Use this software any way you want.. just don't be stingy
(This is a message for anybody who might possibly get their hands on this ..
ever). If you make cool changes, submit them online, somewhere where people
have easy access to it (a website)

Install instructions: Copy/paste the stuff from this file to your base */

/* add to mud.h */
// {{{ File Manipulation structure and support functions
// Support functions are defined in misc.cpp
#ifndef FILEMANIP
typedef struct  {
        char *buf[1024];
        FILE *ints[1024];
        int downcount[1024];
        int lastbuf;
        int size;
} filemanipulation;
extern void fmanipsetup();
extern FILE *fmanipopenf(char *fname, char *file_desc);
extern void fmanipclosef(FILE *file_desc, int reallyclose);
extern void fmanipreportOpen();
extern filemanipulation fmanip;
#define fopen2(x, y) (fmanipopenf(x, y))
#define fclose2(x) (fmanipclosef(x, 1))
#define FILEMANIP
#endif
// }}}
/* pretty much anywhere after the includes, before all the massive 
typedef struct references.......

Supporting functions in misc.cpp

right after the includes is just fine. */
#define EXTRAWMESSAGES // undefine this to remove all the open/close messages
//simply erasing it is enough

//Set up the file wrapper, set default values {{{
//call this from int main() { .... };
void fmanipsetup() {
        printf("Setting up file wrapper\n\r";);
        //this could all be used to potentially build a real DB interface
        //to SQL and such
        int x;
        for(x = 0;x < 1024; x++) fmanip.buf[x] = NULL;
        for(x = 0;x < 1024; x++) fmanip.downcount[x] = 0; //actually counts up
        fmanip.lastbuf = 0;
        fmanip.size = 0;
};
// }}}
// Open a file, encapsulates fopen() {{{
//this is called by the macro: fopen2(char *filename, char *method);
FILE *fmanipopenf(char *fname, char *opts) {
        FILE *x = fopen(fname, opts);
        fmanip.buf[fmanip.size] = (char *)malloc(strlen(fname));
        strncpy(fmanip.buf[fmanip.size],(const char *) fname, strlen(fname));
        fmanip.ints[fmanip.size] = x;
#ifdef EXTRAWMESSAGES
        printf("%s OPENED \n\r", fmanip.buf[fmanip.size]);
#endif
        fmanip.size += 1;
        fmanip.lastbuf += 1;
        //if a file doesn't exist, automatically close it.
        //that's one of the things that wasn't happening before.
        if(!x) fmanipclosef(x, 0);
        return x;

};
// }}}
//Close a file, remove {{{ it from the arrays, try to close it if it's not a null
//pointer.
//oh, it also, very very simply, pushes eveything down the list when something
//is erased from it. This ensures the oldest ones will be at the bottom
//and the newest ones at the top. It also allows very easy re-use

/* Called by the macro: fclose2(FILE) */
void fmanipclosef(FILE *file_desc) {
        int x = 0;
        bool freed = FALSE;
        for(; x < fmanip.size; x++) {
                if(file_desc == fmanip.ints[x]) {
                        int y = x+1;
                        if(freed == FALSE) {
#ifdef EXTRAWMESSAGES
                                printf("%s CLOSED \n\r", fmanip.buf[x]);
#endif
//                              if(fmanip.buf[x] != NULL)
                                memset(fmanip.buf[x], 0, sizeof(fmanip.buf[x]));
                                free(fmanip.buf[x]); // do free this
                                freed = TRUE;
                        }
                        for(; y < fmanip.size; y++) {
                                fmanip.ints[y-1] = fmanip.ints[y];
                                fmanip.buf[y-1] = fmanip.buf[y];
                        }
                }
        }
        if(!file_desc) ;
        else
        fclose(file_desc);
        fmanip.size = fmanip.size -1;
//free(file_desc); don't free it
};
// }}}
// report files that failed to close and close then {{{
//this function is run on a timer called every 1 second (in smaug update.c)
// --pulse_second  ;
void fmanipreportOpen() {
        int x = 0;
        for(; x < fmanip.size; x++) {
                printf("%s \n\r", fmanip.buf[x]);
                fmanip.downcount[x] += 1;
                if(fmanip.downcount[x] > 10) {
                        if(!fmanip.ints[x]) {
                                printf("LOG: NULL file failed to close itself: %s \n\r", fmanip.buf[x])
                                fmanipclosef(fmanip.ints[x], 0);
                        } else {
                                printf("LOG: NON NULL file failed to close itself: %s \n\r", fmanip.buf[x]);
                                fmanipclosef(fmanip.ints[x], 1);
                        }
                }
        }
};
// }}}


btw, Rogue had told me that he'd come up with a revision to this, but I don't know what it entails as he never got back to me with the updated info, so if any of the great and powerful gurus amongst us (Samson, Remcon, etc) want to double check this... well, you're quite welcome. :)
       
Pages:<< prev 1 next >>