Time is crashing mud... :P

Posted by Creeper386 on Wed 31 Oct 2001 01:49 AM — 20 posts, 67,232 views.

USA #0
Alright I have a problem... I got the Smaug 1.4a for Unix/Cygwin with the MXP added in. After changes to it that I have found on another site. Changes that are for compiling Smaug on an older Cygwin(Can be found at http://www.rafemand.com/infocenter/csmaug.htm) and it compiled with little problems. Now when I run everything seems to be fine. Only problem I have found so far is that using the time command crashes the mud. Now not being a very skilled coder I'm not sure how to fix this.

If I can get help with this that'd be greatful. If noone can help me with this it still be helpful if someone can help me take out the time command so it won't crash the mud.

Creep
USA #1
Alright the good thing is I figured out some things on my own... Well with some help from some files on this site :P. I have currently disabled the time command so I no longer need to know how to do that. Who would think it would be as easy as commenting it out in three places on in act_info.c and two places in table.c... Alright probably all of you who have coded muds... Anyways I still need to know it its possible to get the time to work with a cygwin compile running on a WinME system.

Creep

By the way thanks for this site here. Very benificial.
Australia Forum Administrator #2
The "time" command works OK for me under Cygwin. What you could try is to run under gdb (GNU debugger) and see why it is crashing.

Try starting the mud up like this:


gdb smaug.exe


Then "run" the program, and see what happens when it crashes.


USA #3
When using...

gdb smaug.exe

the run

then log in and use the time command in the Bash window I get...


Program received signal SIGSEGV, Segmentation fault.
0x61055899 in _size_of_stack_reserve__ ()

Now. Not sure what it means my guess is something isn't being recieved correctly... Hehe. SHRUG.

But don't know where or why it is doing it.

I am using an old version of Cygwin as my connection isn't even over 50K. I'm using Cygwin-B20 which a good suggestion is upgrade I know but at less then 50k it takes an hour to get nowhere...

Creep
Australia Forum Administrator #4
When you get that message in gdb try typing "bt" (backtrace) which should show you what routine has called what. That should help to narrow down where the problem is occuring.
USA #5
(gdb) bt
#0 0x61055899 in _size_of_stack_reserve__ ()
Cannot access memory at address 0x2000000.




Is that more helpful?

I have no clue.

Creep
Australia Forum Administrator #6
Sounds like a serious corruption somewhere. Did you get any warnings during the compile that might be relevant?
USA #7
In the following files I get bracer errors, and one int format error or something similar. Nothing that seems relevant that I can see.

act_obj.C
build.c
db.c
handler.c
interp.c
magic.c
save.c
shops.c


Creep


Australia Forum Administrator #8
In the file act_info.c is the code to do the time command, like this:



void do_time( CHAR_DATA *ch, char *argument )
{
    extern char str_boot_time[];
    extern char reboot_time[];
    char *suf;
    int day;

    day     = time_info.day + 1;

     if ( day > 4 && day <  20 ) suf = "th";
    else if ( day % 10 ==  1       ) suf = "st";
    else if ( day % 10 ==  2       ) suf = "nd";
    else if ( day % 10 ==  3       ) suf = "rd";
    else                             suf = "th";

    set_char_color( AT_YELLOW, ch );

    ch_printf( ch,
    "It is %d o'clock %s, Day of %s, %d%s the Month of %s.\n\r"
        "The mud started up at:    %s\r"
        "The system time (E.S.T.): %s\r"
        "Next Reboot is set for:   %s\r",

    (time_info.hour % 12 == 0) ? 12 : time_info.hour % 12,
    time_info.hour >= 12 ? "pm" : "am",
    day_name[day % 7],
    day, suf,
    month_name[time_info.month],
    str_boot_time,
    (char *) ctime( &current_time ),
    reboot_time
    );

    return;
}




I would try commenting out bits of it to see what part is causing the crash.

The most likely part if the ch_printf statement, which unfortunately is quite long and complex (in bold above). You could comment out the whole thing, and if that stops the crash, comment out bits of it so that you can see which part is causing the crash. For example:




    ch_printf( ch,
    "It is %d o'clock %s, Day of %s, %d%s the Month of %s.\n\r"
        "The mud started up at:    %s\r"
         /* "The system time (E.S.T.): %s\r" */ 
        "Next Reboot is set for:   %s\r",

    (time_info.hour % 12 == 0) ? 12 : time_info.hour % 12,
    time_info.hour >= 12 ? "pm" : "am",
    day_name[day % 7],
    day, suf,
    month_name[time_info.month],
    str_boot_time,
     /* (char *) ctime( &current_time ), */ 
    reboot_time
    );




You would need to comment out the line that displays the time (ie. the one with the %s) and the one that calculates it (the "ctime" line). In the example above I have commented out the system time - in bold.
USA #9
Well I figured out which part of the code is crashing the mud, but I still need help fixing it. Though you have helped alot now I got some basic debugging skills. :)


Something in the following bolded code is what is crashing the mude when time command is used. With the code how it is when time command is used it dispays boot_time, current_time, and reboot_time and doesn't crash.


ch_printf( ch,
/*"It is %d o'clock %s, Day of %s, %d%s the Month of %s.\n\r"*/
"The mud started up at: %s\r"
"The system time (E.S.T.): %s\r"
"Next Reboot is set for: %s\r",

/*(time_info.hour % 12 == 0) ? 12 : time_info.hour % 12,
time_info.hour >= 12 ? "pm" : "am",
day_name[day % 7],
day, suf,
month_name[time_info.month],*/

str_boot_time,
(char *) ctime( &current_time ),
reboot_time
);
Australia Forum Administrator #10
I suppose that would crash if the time_info data was completely wrong, eg. if 'day' was out of range.

Try seeing what values it has by doing something like this:



ch_printf( ch,
"Hour = %d, Day = %d, Month = %d, Year = %d\n\r",
time_info.hour,
time_info.day,
time_info.month,
time_info.year);

USA #11
Well when I added that in(though had to take out a ')' in order for it to compile) I got this in time.

Hour = 4259584, Day = -21, Month = -29, Year = -5

Now don't know how that works... but thats what I got. At least with this code...

ch_printf( ch,
/*"It is %d o'clock %s, Day of %s, %d%s the Month of %s.\n\r"*/
"Hour = %d, Day = %d, Month = %d, Year = %d\n\r", 
	"The mud started up at: %s\r"
	"The system time (E.S.T.): %s\r"
	"Next Reboot is set for: %s\r",

/*(time_info.hour % 12 == 0) ? 12 : time_info.hour % 12, 
time_info.hour >= 12 ? "pm" : "am", 
day_name[day % 7], 
day, suf, 
month_name[time_info.month],*/
time_info.hour, 
time_info.day, 
time_info.month, 
time_info.year, 
str_boot_time, 
(char *) ctime( &current_time ), 
reboot_time
);



But with just your code from the previous post I got...

Hour = -17, Day = -29, Month = -5, Year = -650
Australia Forum Administrator #12
It seems pretty clear that current_time is wrong, possibly uninitialised, which is why the display crashes. It seems to be calculated in a number of places (eg. comm.c) like this:


gettimeofday( &last_time, NULL );
current_time = (time_t) last_time.tv_sec;


Why it is wrong is hard to say.
USA #13
Is the code set up to read the Windows time? I was told windows uses time differently then what smaug is normally set up to run.

Also again I'm using Cygwin B20 so would that do anything?

Creep

Australia Forum Administrator #14
I can't really account for this. The "time" command works OK for me under Windows NT, using Cygwin.
USA #15
Which version of Cygwin are you using? and would different versions affect it?

Also I am on a WinME computer if that would make any difference.

Creep
Australia Forum Administrator #16
I'm not sure how to find that out. :)

I have gcc-2.95.2-6 if that helps.

It was the latest on 12th March 2001.
USA #17
I don't know. Due to internet speed I am not able to download a newer Cygwin. After an hour barely a sliver of it is done.

I have someone else helping out as well so if I get it figured out from him I'll post the results. If not I'll post how far we got.
USA #18
Okay. Well I finnally got source back and a compile. Still using Cygwin B20 though. And I'm still having the time problem. I've tried something new this time and I've change the following code in comm.c to what is there. Just commented out the one that was being used and uncommented the commented out part.


 /*
     * Init time.
     */
    gettimeofday( &now_time, NULL );
    current_time = (time_t) now_time.tv_sec;
    gettimeofday( &boot_time, NULL);  /* okay, so it's kludgy, sue me :) */
/*    boot_time = time(0); */        /*  <-- I think this is what you wanted */
    strcpy( str_boot_time, ctime( &current_time ) );



But I still get the following which seems similar to what I got before.



COMMAND PROMPT
[main] C:\SMAUG\DIST\AREA\SMAUG.EXE 1420 (0) handle_exceptions: Exception: STATU
S_ACCESS_VIOLATION

DGB
[main] SMAUG 1420 (0) handle_exceptions: Dumping stack trace to SMAUG.EXE.core

Program received signal SIGSEGV, Segmentation fault.

BT
0x6105587c in _size_of_stack_reserve__ ()Program received signal SIGSEGV, Segmentation fault.
0x6105587c in _size_of_stack_reserve__ ()

(gdb) step
Single stepping until exit from function _size_of_stack_reserve__,
which has no line number information.
Can't send signals to the child.

Program received signal SIGSEGV, Segmentation fault.
0x6105587c in _size_of_stack_reserve__ ()



Any help would be appreciated
USA #19
Oh.. I also commented out the code that seems to be crashing the mud in do_time which is:

/*"It is %d o'clock %s, Day of %s, %d%s the Month of %s.\n\r" */

and

/*(time_info.hour % 12 == 0) ? 12 : time_info.hour % 12,
time_info.hour >= 12 ? "pm" : "am",
day_name[day % 7],
day, suf,
month_name[time_info.month],*/

And with the rest of the code in do_time I get the following after using the time command:

The mud started up at: Sun Jan 25 00:23:22 1970
The system time (E.S.T.): Sun Jan 25 00:24:18 1970
Next Reboot is set for: Sun Jan 25 22:00:00 1970

Don't know if that well help any.

Thanks,
Creep