23 Aug, 2009, Lancsta wrote in the 1st comment:
Votes: 0
Ok so just browsing around looking to make sure I don't have any open files and what not, I found this command : ls -la /proc/<pid>/fd

using it I get:
ls -la /proc/31318/fdtotal 0
dr-x—— 2 xxx users 0 2009-08-21 22:10 ./
dr-xr-xr-x 6 xxx users 0 2009-08-21 22:10 ../
lrwx—— 1 xxx users 64 2009-08-21 22:11 0 -> /dev/pts/1\ (deleted)
l-wx—— 1 xxx users 64 2009-08-21 22:11 1 -> /xxx/xxx/sunder2.1/log/current.log
lr-x—— 1 xxx users 64 2009-08-21 22:11 10 -> /xxx/xxx/sunder2.1/area/specials/southrd.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 100 -> /xxx/xxx/sunder2.1/area/specials/nashkel.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 101 -> /xxx/xxx/sunder2.1/area/specials/cloakwud.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 102 -> /xxx/xxx/sunder2.1/area/specials/srwood2.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 103 -> /xxx/xxx/sunder2.1/area/specials/necrund1.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 104 -> /xxx/xxx/sunder2.1/area/specials/sklgorge.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 105 -> /xxx/xxx/sunder2.1/area/specials/immilmar.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 106 -> /xxx/xxx/sunder2.1/area/specials/hluthvar.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 107 -> /xxx/xxx/sunder2.1/area/specials/scornube.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 108 -> /xxx/xxx/sunder2.1/area/specials/narzul.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 109 -> /xxx/xxx/sunder2.1/area/specials/durlag.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 11 -> /xxx/xxx/sunder2.1/area/specials/adaria.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 110 -> /xxx/xxx/sunder2.1/area/specials/goblclan.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 111 -> /xxx/xxx/sunder2.1/area/specials/woodst.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 112 -> /xxx/xxx/sunder2.1/area/specials/uldntrl.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 113 -> /xxx/xxx/sunder2.1/area/specials/firedrak.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 114 -> /xxx/xxx/sunder2.1/area/specials/darkhold.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 115 -> /xxx/xxx/sunder2.1/area/specials/iriaebor.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 116 -> /xxx/xxx/sunder2.1/area/specials/grenflds.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 117 -> /xxx/xxx/sunder2.1/area/specials/blakroad.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 118 -> /xxx/xxx/sunder2.1/area/specials/duskrdii.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 119 -> /xxx/xxx/sunder2.1/area/specials/coastway.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 12 -> /xxx/xxx/sunder2.1/area/specials/northrd.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 120 -> /xxx/xxx/sunder2.1/area/specials/caslteth.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 121 -> /xxx/xxx/sunder2.1/area/specials/fearch.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 122 -> /xxx/xxx/sunder2.1/area/specials/innrchmb.specials
lrwx—— 1 xxx users 64 2009-08-21 22:11 123 -> socket:[231446]
lrwx—— 1 xxx users 64 2009-08-23 10:52 124 -> socket:[232319]
lrwx—— 1 xxx users 64 2009-08-23 10:52 125 -> socket:[231888]
lrwx—— 1 xxx users 64 2009-08-23 10:52 127 -> socket:[231938]
lr-x—— 1 xxx users 64 2009-08-21 22:11 13 -> /xxx/xxx/sunder2.1/area/specials/swroad.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 14 -> /xxx/xxx/sunder2.1/area/specials/galdamar.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 15 -> /xxx/xxx/sunder2.1/area/specials/newby.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 16 -> /xxx/xxx/sunder2.1/area/specials/malathar.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 17 -> /xxx/xxx/sunder2.1/area/specials/halfling.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 18 -> /xxx/xxx/sunder2.1/area/specials/tohell.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 19 -> /xxx/xxx/sunder2.1/area/specials/bazaar.specials
l-wx—— 1 xxx users 64 2009-08-21 22:10 2 -> /xxx/xxx/sunder2.1/log/current.log
lr-x—— 1 xxx users 64 2009-08-21 22:11 20 -> /xxx/xxx/sunder2.1/area/specials/specularum.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 21 -> /xxx/xxx/sunder2.1/area/specials/gnome.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 22 -> /xxx/xxx/sunder2.1/area/specials/mahntor.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 23 -> /xxx/xxx/sunder2.1/area/specials/hitower.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 24 -> /xxx/xxx/sunder2.1/area/specials/wastel.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 25 -> /xxx/xxx/sunder2.1/area/specials/warkeep.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 26 -> /xxx/xxx/sunder2.1/area/specials/donjon.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 27 -> /xxx/xxx/sunder2.1/area/specials/gtown.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 28 -> /xxx/xxx/sunder2.1/area/specials/zoo.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 29 -> /xxx/xxx/sunder2.1/area/specials/aresch75.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 3 -> /dev/null
lr-x—— 1 xxx users 64 2009-08-21 22:11 30 -> /xxx/xxx/sunder2.1/area/specials/trem1.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 31 -> /xxx/xxx/sunder2.1/area/specials/ravenmoor.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 32 -> /xxx/xxx/sunder2.1/area/specials/telepops.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 33 -> /xxx/xxx/sunder2.1/area/specials/karen.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 34 -> /xxx/xxx/sunder2.1/area/specials/under2.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 35 -> /xxx/xxx/sunder2.1/area/specials/docks.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 36 -> /xxx/xxx/sunder2.1/area/specials/dwarven.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 37 -> /xxx/xxx/sunder2.1/area/specials/chapel.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 38 -> /xxx/xxx/sunder2.1/area/specials/grave.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 39 -> /xxx/xxx/sunder2.1/area/specials/newthalos.specials
lrwx—— 1 xxx users 64 2009-08-21 22:11 4 -> socket:[172308]
lr-x—— 1 xxx users 64 2009-08-21 22:11 40 -> /xxx/xxx/sunder2.1/area/specials/duskwood.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 41 -> /xxx/xxx/sunder2.1/area/specials/arkain.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 42 -> /xxx/xxx/sunder2.1/area/specials/fod.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 43 -> /xxx/xxx/sunder2.1/area/specials/progtest.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 44 -> /xxx/xxx/sunder2.1/area/specials/tlouflas.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 45 -> /xxx/xxx/sunder2.1/area/specials/aenoon.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 46 -> /xxx/xxx/sunder2.1/area/specials/dojo.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 47 -> /xxx/xxx/sunder2.1/area/specials/tnanever.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 48 -> /xxx/xxx/sunder2.1/area/specials/vormav.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 49 -> /xxx/xxx/sunder2.1/area/specials/cerrotrag.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 5 -> /xxx/xxx/sunder2.1/data/socials.DAT
lr-x—— 1 xxx users 64 2009-08-21 22:11 50 -> /xxx/xxx/sunder2.1/area/specials/vions.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 51 -> /xxx/xxx/sunder2.1/area/specials/greatplain.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 52 -> /xxx/xxx/sunder2.1/area/specials/prahs.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 53 -> /xxx/xxx/sunder2.1/area/specials/altem.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 54 -> /xxx/xxx/sunder2.1/area/specials/clanwolf.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 55 -> /xxx/xxx/sunder2.1/area/specials/mithmine.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 56 -> /xxx/xxx/sunder2.1/area/specials/blackmoor.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 57 -> /xxx/xxx/sunder2.1/area/specials/trog.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 58 -> /xxx/xxx/sunder2.1/area/specials/freehold.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 59 -> /xxx/xxx/sunder2.1/area/specials/daris.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 6 -> /xxx/xxx/sunder2.1/area/specials/limbo.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 60 -> /xxx/xxx/sunder2.1/area/specials/sivarre1.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 61 -> /xxx/xxx/sunder2.1/area/specials/dlar1.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 62 -> /xxx/xxx/sunder2.1/area/specials/angeldemon.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 63 -> /xxx/xxx/sunder2.1/area/specials/formian.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 64 -> /xxx/xxx/sunder2.1/area/specials/ellindel.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 65 -> /xxx/xxx/sunder2.1/area/specials/blkhnd.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 66 -> /xxx/xxx/sunder2.1/area/specials/knights.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 67 -> /xxx/xxx/sunder2.1/area/specials/circle.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 68 -> /xxx/xxx/sunder2.1/area/specials/scholars.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 69 -> /xxx/xxx/sunder2.1/area/specials/arkaent.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 7 -> /xxx/xxx/sunder2.1/area/specials/global.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 70 -> /xxx/xxx/sunder2.1/area/specials/affero.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 71 -> /xxx/xxx/sunder2.1/area/specials/exodus.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 72 -> /xxx/xxx/sunder2.1/area/specials/amine.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 73 -> /xxx/xxx/sunder2.1/area/specials/dutchman.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 74 -> /xxx/xxx/sunder2.1/area/specials/iskoro.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 75 -> /xxx/xxx/sunder2.1/area/specials/colosseum.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 76 -> /xxx/xxx/sunder2.1/area/specials/sin.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 77 -> /xxx/xxx/sunder2.1/area/specials/ryube.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 78 -> /xxx/xxx/sunder2.1/area/specials/angel.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 79 -> /xxx/xxx/sunder2.1/area/specials/mttempest.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 8 -> /xxx/xxx/sunder2.1/area/specials/immortal.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 80 -> /xxx/xxx/sunder2.1/area/specials/labyrinth.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 81 -> /xxx/xxx/sunder2.1/area/specials/quagmire.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 82 -> /xxx/xxx/sunder2.1/area/specials/roleplay.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 83 -> /xxx/xxx/sunder2.1/area/specials/olympus.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 84 -> /xxx/xxx/sunder2.1/area/specials/welcome.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 85 -> /xxx/xxx/sunder2.1/area/specials/atlantis.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 86 -> /xxx/xxx/sunder2.1/area/specials/elemental.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 87 -> /xxx/xxx/sunder2.1/area/specials/holiday.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 88 -> /xxx/xxx/sunder2.1/area/specials/icefolx.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 89 -> /xxx/xxx/sunder2.1/area/specials/arachnid.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 9 -> /xxx/xxx/sunder2.1/area/specials/home.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 90 -> /xxx/xxx/sunder2.1/area/specials/samuraivillage.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 91 -> /xxx/xxx/sunder2.1/area/specials/shadow.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 92 -> /xxx/xxx/sunder2.1/area/specials/libris.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 93 -> /xxx/xxx/sunder2.1/area/specials/tradway1.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 94 -> /xxx/xxx/sunder2.1/area/specials/tradway2.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 95 -> /xxx/xxx/sunder2.1/area/specials/berdusk.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 96 -> /xxx/xxx/sunder2.1/area/specials/sthrwood.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 97 -> /xxx/xxx/sunder2.1/area/specials/highroad.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 98 -> /xxx/xxx/sunder2.1/area/specials/calimprt.specials
lr-x—— 1 xxx users 64 2009-08-21 22:11 99 -> /xxx/xxx/sunder2.1/area/specials/duskroad.specials


Is this normal? Having all these area files open? And when I do a copyover, I all of these duplicate, meaning there are two of each. I'm still trying to figure this out, any help is appreciated :) Thanks
23 Aug, 2009, David Haley wrote in the 2nd comment:
Votes: 0
It means that there's a "memory leak" of file descriptors. That is, the code is opening files but not closing them. I strongly suspect that the 'specials' files are opened during initialization, read, and then never closed. Several of those entries are normal, though, such as the log file, or the various sockets.
23 Aug, 2009, Lancsta wrote in the 3rd comment:
Votes: 0
Yeah I figured those being as there are well open sockets. I've gone through the initialization and where it was opened, it was followed by fclose. I'm still trying to track it. But I was just needing some outside input as to make sure I wasn't beating a dead horse. Also, normally when you fclose ( fpArea ); for example, would you follow it with a fpArea = NULL; ? Running through Nick Gammon's site I came across a few posts where someone had suggested it in SMAUG. Thanks for the quick reply too David. Much appreciated.
23 Aug, 2009, Lancsta wrote in the 4th comment:
Votes: 0
I just can't seem to find where it's not closed. Everything referring to /specials and the rest of the area files are followed by fclose….. Is there a command or anything I can use to help track it?
23 Aug, 2009, Lobotomy wrote in the 5th comment:
Votes: 0
Lancsta said:
I've gone through the initialization and where it was opened, it was followed by fclose.

I would suggest carefully examining the code in question to make sure that there are no exit conditions causing the code to leave the current code segment before fclose is called. I.e, having there be a return, in the case of a function, that can be called before fclose. If the fclose statement is there, but not being called, that tends to indicate that the code flow is broken in some way.

One way that you can debug a particular section of code, to know that the code is flowing as expected, is to put debugging messages in above/below particular lines. For instance, if you wanted to know each time the fclose in question is sucessfully being called, you could go:

bug( "%s: fclose about to be called on fpArea", __FUNCTION__ );
fclose( fpArea );
bug( "%s: fclose called on fpArea", __FUNCTION__ );


Edit:
You can also check against fclose's return value in the event that there might be a problem with fclose itself, rather than the code flow, such as:

if( fclose( fpArea ) )
bug( "%s: fclose on fpArea failed", __FUNCTION__ );
else
bug( "%s: fclose on fpArea successful", __FUNCTION__ );


That might even work better for you, as having that setup lets you check fclose's output and have messages letting you know if fclose was even called at all - at the same time. Generally, though, a game's code is such that fclose wouldn't be expected to fail, so a lot of codebases don't have code in place to check fclose's return value.
23 Aug, 2009, Lancsta wrote in the 6th comment:
Votes: 0
I think your totally right. As I look in the code I start with boot_db:
I'm chunking this just to show the flow
log_string ( "Booting Areas" );

if ( ( fpList = fopen ( AREA_LIST, "r" ) ) == NULL )
{
perror ( AREA_LIST );
exit ( 1 );
}
for ( ;; )
{
strcpy ( filename, fread_word ( fpList ) ); /* Get $
if ( filename[0] == '$' )
break;
db_load_area ( filename ); $
}
fclose( fpList );

Then in load_area:
if ( ( pArea = ( db_load_area_header ( filename ) ) ) == NULL )
{
bugf ("No Header Found for %s!!", filename );
return;
}
db_load_area_rooms ( pArea->filename, pArea );
db_load_area_objects ( pArea->filename, pArea );
db_load_area_mobiles ( pArea->filename, pArea );
db_load_area_resets ( pArea->filename, pArea );
db_load_area_shops ( pArea->filename, pArea );
db_load_area_specials ( pArea->filename, pArea );
db_load_area_progs ( pArea->filename, pArea );

Then load_area_specials gets another fopen, and an fclose.
23 Aug, 2009, David Haley wrote in the 7th comment:
Votes: 0
It's probably easiest to start with the specials list, because that one seems most obviously broken. I would look into db_load_area_specials as a likely first place to look. Lobotomy is correct that usually problems like this occur when people don't manage control flow correctly with respect to consuming and releasing resources.
24 Aug, 2009, Lancsta wrote in the 8th comment:
Votes: 0
void db_load_area_specials ( char *filename, AREA_DATA *pArea )
{
SNP ( strArea, "%s%s.specials", SPEC_DIR, filename );

if ( !( fpArea = fopen ( strArea, "r" ) ) )
{
bugf ( "No %s found for %s", strArea, pArea->name );
return;
}
for ( ;; )
{
MOB_INDEX_DATA *pMobIndex;
char letter;

switch ( letter = fread_letter ( fpArea ) )
{
default:
bugf ( "Load_specials: letter '%c' not *MS.", letter );
exit ( 1 );
case 'S':
return;
case '*':
break;
case 'M':
pMobIndex = get_mob_index ( fread_number ( fpArea ) );
pMobIndex->spec_fun = spec_lookup ( fread_word ( fpArea ) );
if ( pMobIndex->spec_fun == 0 )
{
bugf ( "Load_specials: 'M': vnum %d.", pMobIndex->vnum );
exit ( 1 );
}
break;
}
fread_to_eol ( fpArea );
}

fclose ( fpArea );
return;
}

Looking through it i'm lost. The only thing I would find odd, would be the fread_to_eol ( fpArea ); When I compare it to the other "load_area_" they aren't too different.
24 Aug, 2009, Guest wrote in the 9th comment:
Votes: 0
Line 21, the case 'S' section does not close the file before returning out of the function.
24 Aug, 2009, Lancsta wrote in the 10th comment:
Votes: 0
Duh. I looked right over it so many times. Thanks so much guys always grateful to have another set of eyes. I'm gonna throw in an fclose ( fpArea ); before the return;
24 Aug, 2009, Lancsta wrote in the 11th comment:
Votes: 0
Samson, killer eyes man thank you!. Thank you David and Labotomy too. Definately lead me down the right path. I went from 126 open files, to 7. current.log and socials.dat still duplicate and triplicate but I think it's a similar issue so I'll definately know from now on.
25 Aug, 2009, Bojack wrote in the 12th comment:
Votes: 0
Thank you for posting that command. I personally didnt know bout it myself. Our mud passed without open descriptors but a friends didnt so I want to post this since its related. Anyone that uses quickmud, make sure for qmconfig_read (void) in act_wiz.c that the case 'E': has this:
case 'E':
if (!str_cmp(word, "END"))
{
fclose (fp);
return;
}
break;


I noticed stock quickmud doesnt close the file.
0.0/12