Top Mud Sites Forum

Top Mud Sites Forum (http://www.topmudsites.com/forums/index.php)
-   MUD Coding (http://www.topmudsites.com/forums/forumdisplay.php?f=9)
-   -   Weird crash bug at low level writing to descriptor (http://www.topmudsites.com/forums/showthread.php?t=5304)

Hyena 01-09-2009 01:32 AM

Weird crash bug at low level writing to descriptor
 
Codebase is ROM

Program received signal SIGPIPE, Broken pipe.
0x400fc228 in write () from /lib/libc.so.6
(gdb) bt
#0 0x400fc228 in write () from /lib/libc.so.6
#1 0x00000000 in ?? ()
#2 0x0808cf97 in write_to_descriptor (desc=12,
txt=0x42a2f8b0 "You do not see that here.\n\r\n\r^ >oblin patrolman has arrived from the north.\n\r\n\r^ >ded by a force shield.\n\r\n\r^ >fect >s are low and brutal.\n\rRed eyes are psychopathicly seeking for any kind of enemies."..., length=32) at comm.c:1324
#3 0x0808c380 in process_output (d=0x41dfc13c, fPrompt=224 'ā') at comm.c:1016
#4 0x0808b8a6 in game_loop_unix (control=8) at comm.c:501
#5 0x0808af59 in main (argc=2, argv=0x8) at comm.c:136


It happened when a player using jaba mud client typed #99 look goblin and spammed it about 5 times. He then was summoned by another player (which I don't think the problem was) and then it crashed.

Neither me nor he were able to repeat that crash later. Any suggestions?

Edit:
One more thing. That player should have been disconnected by server for overflooding the input but strangely he wasn't and then the crash came. When we repeated the same action we got disconnected by the server every time.

Kylotan 01-09-2009 05:21 AM

Re: Weird crash bug at low level writing to descriptor
 
Sometimes write() can send SIGPIPE. Best to ignore it as it's mostly useless. You may find examples elsewhere in the ROM code for ignoring signals, otherwise look on Google. Do that for SIGPIPE. It seems a bit strange that I've never seen this occur in any networking code I've written though.

Hyena 01-09-2009 08:22 AM

Re: Weird crash bug at low level writing to descriptor
 
in signals.c doesn't the following already ignore all cases of SIGPIPE? If it does then why I still got the crash? How can I fix it?

void init_signals()
{
signal(SIGPIPE, SIG_IGN);
signal(SIGTERM, sig_handler);
signal(SIGSEGV, sig_handler);
signal(SIGFPE, sig_handler);
signal(SIGUSR2, sig_handler);
signal(SIGTSTP, sig_message);
}

void un_init_signals()
{
signal(SIGPIPE, SIG_IGN);
signal(SIGTERM, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGFPE, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
signal(SIGTSTP, SIG_DFL);
}

Kylotan 01-09-2009 08:46 AM

Re: Weird crash bug at low level writing to descriptor
 
I would think init_signals() would do the trick, yes. I guess the next question is: why is there an un_init_signals() function, and has that perhaps been called?

Hyena 01-09-2009 10:01 AM

Re: Weird crash bug at low level writing to descriptor
 
void sig_handler(int sig)
{
un_init_signals(); /* signal caught, don't wanna catch it again, 'cause me might loop */
switch (sig) {
case SIGTERM:
bug("Sig_handler: SIGTERM (crashed or killed)", 0);
do_auto_shutdown(TRUE);
raise(SIGTRAP);
break;
case SIGSEGV:
bug("Sig_handler: SIGSEGV (crashed)", 0);
do_auto_shutdown(TRUE);
raise(SIGTRAP);
break;
case SIGFPE:
bug("Sig_handler: SIGFPE (crashed)", 0);
do_auto_shutdown(TRUE);
raise(SIGTRAP);
break;
case SIGUSR2:
bug("Sig_handler: SIGUSR2 (external signal for auto-rebooting)", 0);
do_auto_shutdown(FALSE);
raise(SIGTRAP);
break;
default:
bug("Sig_handler: Unknown signal caught, shutting down", 0);
do_auto_shutdown(TRUE);
raise(SIGTRAP);
break;
}
}


Seems that if any signal is caught then it un_inits them am I right? As init_signal is executed only once in the very beginning of the whole program. So basically I would have to cancel un_init when there is SIGPIPE?

Kylotan 01-09-2009 10:08 AM

Re: Weird crash bug at low level writing to descriptor
 
Looks like all those signals would result in the mud shutting down though. If a situation arose where the mud wasn't going to shut down immediately, then restoring the signals at the end of the function would seem wise. But it looks like a bit of an awkward design to be honest.

Hyena 01-09-2009 10:49 AM

Re: Weird crash bug at low level writing to descriptor
 
So I added a quick case for SIGPIPE, do you think it should do it?
case SIGPIPE:
logm("SIGPIPE received, ignoring it.",101);
init_signals();
break;


All times are GMT -4. The time now is 07:10 PM.

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright Top Mud Sites.com 2022