[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [hobbit] msgcache hobbitfetch problems
- To: hobbit (at) hswn.dk
- Subject: Re: [hobbit] msgcache hobbitfetch problems
- From: Cade Robinson <cade.robinson (at) gmail.com>
- Date: Mon, 08 Feb 2010 12:53:48 -0600
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:in-reply-to :references:content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=FSohbbvDrR5yn+59J8U+q3BsUkcDmQfGnJt/b4U4Z9M=; b=eTjL9EGoBfa/yGgFivnrdgXWgRZZW9YiPsCvQ80g/mSYNKF03DgTbMhCc8GrdfggM2 29c5uETkuGHpFMoEsVq3gm8OM9DS6goL1DV3KYNJxSgcUEiV8RgUdtxZO6JYq10XwNI9 kQdGWtE6LaI2Ofjdm/xR3l+Kq+PkFOYnJpyVo=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:in-reply-to:references:content-type:date:message-id :mime-version:x-mailer:content-transfer-encoding; b=FqfSGBcMKvlN2y0sUAVdoyIziEngYHwPs3PORuEYWEk2ydw2GGLgbSiAmYFLp18zrY 9ozwYhRS+pIO5XED66vITbqHaZb8PRBe6ZiuI6pqRtNzafHZ+HutKduyWSAmWi5i8KFF gx4ga5Q1CHGvBrMGro+/aheJ0TVSBy2hPGtYw=
- References: <17bd4d511002080837jae111bi26a2da3186e092f8 (at) mail.gmail.com> <C795A7D3.5B84%dan.mcdonald (at) austinenergy.com> <17bd4d511002081012q7e811e38l578131dffa9707ac (at) mail.gmail.com>
The issue is in the hobbitfetch "grabdata" function.
int n;
char buf[8192];
...
n = read(conn->sockfd, buf, sizeof(buf));
...
else if (n > 0) {
...
buf[n] = '\0';
...
If the "read" reads 8192 bytes then n is 8192 and then buf[n] tries to
get set to NULL. There is no element 8192.
Also only one read happens so if there is more than 8192 bytes to be
fetched not everything is fetched.
I put the "read" and "if"s in a do...while loop and fixed the null
termination on buf and haven't had any issues.
~/hobbitmon/trunk/hobbitd:-> diff -u hobbitfetch.c ./hobbitfetch.c.new
--- hobbitfetch.c 2010-02-08 12:43:22.781543905 -0600
+++ ./hobbitfetch.c.new 2010-02-08 12:52:25.249509306 -0600
@@ -342,8 +342,9 @@
int n;
char buf[8192];
+ do {
/* Read data from a peer connection (client or server) */
- n = read(conn->sockfd, buf, sizeof(buf));
+ n = read(conn->sockfd, buf, sizeof(buf)-2);
if (n == -1) {
if ((errno != EINTR) && (errno != EAGAIN)) {
/* Read failure */
@@ -360,7 +361,7 @@
/* Save the data */
dbgprintf("Got %d bytes of data from %s (req %lu)\n",
n, addrstring(&conn->caddr), conn->seq);
- buf[n] = '\0';
+ buf[n+1] = '\0';
addtobuffer(conn->msgbuf, buf);
}
else if (n == 0) {
@@ -380,6 +381,7 @@
break;
}
}
+ } while (n>0);
}
void set_polltime(clients_t *client)
On Mon, 2010-02-08 at 18:12 +0000, Steinar M. SkÃlason wrote:
>
>
> On Mon, Feb 8, 2010 at 5:36 PM, Daniel McDonald
> <dan.mcdonald (at) austinenergy.com> wrote:
> On 2/8/10 10:37 AM, "Steinar M. SkÃlason"
> <steinarms (at) gmail.com> wrote:
>
> > Hi,
> >
> > I'm having problems with "msgcache" on the client machines
> and "hobbitfetch"
> > on the server machine.
> > It works for a short period and then get's stuck and all my
> client side checks
> > end up with status purple.
>
>
> Yup. Been doing that for a long time here. I sent a bunch of
> corefiles to
> Henrik about it, and he tried a bunch of patches. Eventually,
> we just wrote
> a routine that restarts hobbitfetch whenever a host turns
> purple.
>
> --
> Daniel J McDonald, CCIE # 2495, CISSP # 78281
>
>
> To unsubscribe from the hobbit list, send an e-mail to
> hobbit-unsubscribe (at) hswn.dk
>
>
>
> Ok, good to hear that I am not the only one.
> I wrote a ugly routine that restarts hobbitfetch if there is no new
> entry in the logfile
>
>
> #!/bin/bash
>
> #This is to see if any progress has been made within the hobbitfetch
> utility.
> TMP_FILE=/tmp/tmp.hobbitfetch.last
> LAST_LINE=`tail -1 /usr/lib/xymon/server/log/hobbitfetch.log|awk
> '{print $1 $2}'`
> PREV_LINE=`cat /tmp/tmp.hobbitfetch.last`
> echo $LAST_LINE > $TMP_FILE
>
> if [ "$LAST_LINE" == "$PREV_LINE" ]; then
> echo "Nothing has happend .... killing hobbitfetch!"
> PID=`ps -ef|grep hobbitfetch|awk '{print $2}'`
> kill -9 $PID
> fi
>
> Best Regards,
> Steinar M.