[hobbit] Arithmetic exception in hobbitd_client

Henrik Stoerner henrik at hswn.dk
Wed Aug 3 18:32:27 CEST 2005


On Wed, Aug 03, 2005 at 04:50:05PM +0200, cits.bogajewski at daimlerchrysler.com wrote:
> would you mind take a look on my next problem? :)

Sure ;-)

> As just reported, hobbitd_client module stopped work. This is probably 
> because i copied the fresh compiled hpux-meminfo tool to my client 
> machine. On this machine this tool reports following:
> [memory]
> Total:0
> Free:0

Oops - doesn't look good. Could it be that the system you compiled 
hpux-meminfo on is a different OS version than the one you're running it
on ? Still I'd expect the code to be runnable across the two.

The obvious thing to try is to compile it on the machine where it
fails - I know that might be easier said than done.

One thing you could try: There's a bug in the hpux-meminfo tool, the
line that reads:
    pstat_getdynamic(&dbuf, sizeof(sbuf), 1, 0);
should be
    pstat_getdynamic(&dbuf, sizeof(dbuf), 1, 0);

i.e. an "d" instead of an "s" in the "sizeof(Xbuf)". You could try
fixing this and recompiling the tool, although it shouldn't cause the 
problem you see. 

> Anyway, hobbitd_client crashes leaving a core file. It seems to be a 
> problem with zero values.

Yeah, it doesn't like doing a divide by zero. Patch attached.


Regards,
Henrik

-------------- next part --------------
--- hobbitd/hobbitd_client.c	2005/07/25 13:57:56	1.21
+++ hobbitd/hobbitd_client.c	2005/08/03 16:24:18
@@ -363,16 +363,16 @@
 
 	get_memory_thresholds(hinfo, &physyellow, &physred, &swapyellow, &swapred, &actyellow, &actred);
 
-	memphyspct = (100 * memphysused) / memphystotal;
+	memphyspct = (memphystotal > 0) ? ((100 * memphysused) / memphystotal) : 0;
 	if (memphyspct > physyellow) physcolor = COL_YELLOW;
 	if (memphyspct > physred)    physcolor = COL_RED;
 
-	memswappct = (100 * memswapused) / memswaptotal;
+	memswappct = (memswaptotal > 0) ? ((100 * memswapused) / memswaptotal) : 0;
 	if (memswappct > swapyellow) swapcolor = COL_YELLOW;
 	if (memswappct > swapred)    swapcolor = COL_RED;
 
 	if (memactused != -1) {
-		memactpct = (100 * memactused) / memphystotal;
+		memactpct = (memphystotal > 0) ? ((100 * memactused) / memphystotal) : 0;
 		if (memactpct  > actyellow)  actcolor  = COL_YELLOW;
 		if (memactpct  > actred)     actcolor  = COL_RED;
 	}
@@ -386,6 +386,11 @@
 		memorysummary = "CRITICAL";
 	}
 
+	if ((memphystotal == 0) && (memorycolor == COL_GREEN)) {
+		memorycolor = COL_YELLOW;
+		memorysummary = "detection FAILED"
+	}
+
 	init_status(memorycolor);
 	sprintf(msgline, "status %s.memory %s %s - Memory %s\n",
 		commafy(hostname), colorname(memorycolor), timestr, memorysummary);


More information about the Xymon mailing list