pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/net/tcl-scotty Insert a rather ugly workaround in the ...
details: https://anonhg.NetBSD.org/pkgsrc/rev/7a0bc2bf30d2
branches: trunk
changeset: 357912:7a0bc2bf30d2
user: he <he%pkgsrc.org@localhost>
date: Wed Feb 01 09:29:18 2017 +0000
description:
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:
net/tcl-scotty/Makefile | 4 +-
net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c | 101 ++++++++++++++++++++-
2 files changed, 99 insertions(+), 6 deletions(-)
diffs (147 lines):
diff -r 23aeb21de07e -r 7a0bc2bf30d2 net/tcl-scotty/Makefile
--- a/net/tcl-scotty/Makefile Wed Feb 01 07:25:28 2017 +0000
+++ b/net/tcl-scotty/Makefile Wed Feb 01 09:29:18 2017 +0000
@@ -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 -r 23aeb21de07e -r 7a0bc2bf30d2 net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c
--- a/net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c Wed Feb 01 07:25:28 2017 +0000
+++ b/net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c Wed Feb 01 09:29:18 2017 +0000
@@ -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 @@
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 @@
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 @@
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) {
Home |
Main Index |
Thread Index |
Old Index