diff options
author | he <he@pkgsrc.org> | 2017-02-01 09:29:18 +0000 |
---|---|---|
committer | he <he@pkgsrc.org> | 2017-02-01 09:29:18 +0000 |
commit | 10a7e10e5f4dfe032ca8fef87f834cc77281f309 (patch) | |
tree | 43ef6b17834ae1ba81da5b907c0d340e95f38447 /net/tcl-scotty | |
parent | fa248b1e4cbbcfd6c572b889476e65d9bba6a766 (diff) | |
download | pkgsrc-10a7e10e5f4dfe032ca8fef87f834cc77281f309.tar.gz |
Insert a rather ugly workaround in the code handling SNMP trap messages.
It appears that sometimes the reception of SNMP trap messages can somehow
get out of sync, and all too often this results in a scotty process which
apparently endlessly does a read() of 1 byte and gets EAGAIN, just to try
again. Instead, do some rudimentary check on the length of trap messages,
and try to re-sync the stream by finishing re-sync on first EAGAIN.
Bump PKGREVISION.
Diffstat (limited to 'net/tcl-scotty')
-rw-r--r-- | net/tcl-scotty/Makefile | 4 | ||||
-rw-r--r-- | net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c | 101 |
2 files changed, 99 insertions, 6 deletions
diff --git a/net/tcl-scotty/Makefile b/net/tcl-scotty/Makefile index 52538be29d6..c6af59a4f87 100644 --- a/net/tcl-scotty/Makefile +++ b/net/tcl-scotty/Makefile @@ -1,9 +1,9 @@ -# $NetBSD: Makefile,v 1.39 2016/06/02 12:25:47 hauke Exp $ +# $NetBSD: Makefile,v 1.40 2017/02/01 09:29:18 he Exp $ # DISTNAME= scotty-${DIST_VERS} PKGNAME= tcl-scotty-${DIST_VERS} -PKGREVISION= 12 +PKGREVISION= 13 CATEGORIES= net tcl MASTER_SITES= ftp://ftp.ibr.cs.tu-bs.de/pub/local/tkined/ diff --git a/net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c b/net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c index 359adf3916c..71962015676 100644 --- a/net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c +++ b/net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c @@ -1,7 +1,10 @@ -$NetBSD: patch-tnm_snmp_tnmSnmpNet.c,v 1.1 2014/03/05 13:52:29 he Exp $ +$NetBSD: patch-tnm_snmp_tnmSnmpNet.c,v 1.2 2017/02/01 09:29:18 he Exp $ Constify. Avoid use of interp->result. +Add code to try to re-sync trap message stream if we get too +large trap messages, but don't try more than 10 consecutive +attempts and instead abandon trap connection in that case. --- tnm/snmp/tnmSnmpNet.c.orig 1997-08-26 18:55:45.000000000 +0000 +++ tnm/snmp/tnmSnmpNet.c @@ -14,7 +17,97 @@ Avoid use of interp->result. static Tcl_Channel channel = NULL; static char *straps = NULL; -@@ -1060,7 +1060,7 @@ ResponseProc(clientData, mask) +@@ -843,6 +843,8 @@ TrapRecv(interp, packet, packetlen, from + #else + int len, rlen; + char c; ++ static int resync; ++#define RESYNC_MAX 10 + + /* + * Read the message from the straps daemon. We expect the +@@ -868,6 +870,71 @@ TrapRecv(interp, packet, packetlen, from + goto errorExit; + } + ++#if 1 ++ /* ++ * preposterous length? ++ * Do repeated read()s until EAGAIN, ++ * and then say we're done re-syncing trap stream. ++ */ ++ ++ if (len > *packetlen) { ++ char buf[2048]; ++ int l, rem; ++ Tcl_DString dst; ++ ++ Tcl_DStringInit(&dst); ++ ++ DumpPacket(interp, packet, *packetlen, "TrapRecv huge packet", from); ++ ++ Tcl_DStringAppend(&dst, "TrapRecv: preposterous packet length: ", -1); ++ sprintf(buf, "%d\n", len); ++ Tcl_DStringAppend(&dst, buf, -1); ++ ++ again: ++ while((l = read(trap_sock, buf, sizeof(buf))) > 0) { ++ sprintf(buf, "Skipping %d bytes\n", l); ++ Tcl_DStringAppend(&dst, buf, -1); ++ } ++ if (errno == EAGAIN) { ++ Tcl_DStringAppend(&dst, "Hit EAGAIN, attempting re-sync\n", -1); ++ } else if (errno == EINTR) { ++ Tcl_DStringAppend(&dst, "Hit EINTR, skipping more\n", -1); ++ goto again; ++ } else if (l < 0) { ++ Tcl_DStringAppend(&dst, "Hit other error: ", -1); ++ Tcl_DStringAppend(&dst, strerror(errno), -1); ++ Tcl_DStringAppend(&dst, "\nAborting trap connection.\n", -1); ++ TnmWriteMessage(interp, Tcl_DStringValue(&dst)); ++ Tcl_DStringFree(&dst); ++ goto errorExit; ++ } ++ resync++; ++ ++ /* ...and send accumulated output */ ++ TnmWriteMessage(interp, Tcl_DStringValue(&dst)); ++ Tcl_DStringFree(&dst); ++ ++ /* ++ * Don't try too many consecutive re-sync attempts; ++ * it indicates we're unable to re-sync. ++ */ ++ if (resync > RESYNC_MAX) { ++ Tcl_DStringInit(&dst); ++ ++ Tcl_DStringAppend(&dst, ++ "Too many consecutive resync attempts!\n", -1); ++ Tcl_DStringAppend(&dst, ++ "Aborting trap connection.\n", -1); ++ TnmWriteMessage(interp, Tcl_DStringValue(&dst)); ++ Tcl_DStringFree(&dst); ++ goto errorExit; ++ } ++ } else { ++ resync = 0; /* read complete message, OK length */ ++ } ++ ++#else ++ + /* + * Eat up any remaining data-bytes. + */ +@@ -879,6 +946,8 @@ TrapRecv(interp, packet, packetlen, from + len--; + } + ++#endif ++ + *packetlen = rlen; + + if (hexdump) { +@@ -1060,7 +1129,7 @@ ResponseProc(clientData, mask) Tcl_BackgroundError(interp); } if (code == TCL_CONTINUE && hexdump) { @@ -23,7 +116,7 @@ Avoid use of interp->result. TnmWriteMessage(interp, "\n"); } } -@@ -1102,7 +1102,7 @@ TrapProc(clientData, mask) +@@ -1102,7 +1171,7 @@ TrapProc(clientData, mask) Tcl_BackgroundError(interp); } if (code == TCL_CONTINUE && hexdump) { @@ -32,7 +125,7 @@ Avoid use of interp->result. TnmWriteMessage(interp, "\n"); } } -@@ -1147,7 +1147,7 @@ AgentProc(clientData, mask) +@@ -1147,7 +1216,7 @@ AgentProc(clientData, mask) Tcl_BackgroundError(interp); } if (code == TCL_CONTINUE && hexdump) { |