pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/net/tcl-scotty



Module Name:    pkgsrc
Committed By:   he
Date:           Wed Feb  1 09:29:19 UTC 2017

Modified Files:
        pkgsrc/net/tcl-scotty: Makefile
        pkgsrc/net/tcl-scotty/patches: patch-tnm_snmp_tnmSnmpNet.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 pkgsrc/net/tcl-scotty/Makefile
cvs rdiff -u -r1.1 -r1.2 \
    pkgsrc/net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/net/tcl-scotty/Makefile
diff -u pkgsrc/net/tcl-scotty/Makefile:1.39 pkgsrc/net/tcl-scotty/Makefile:1.40
--- pkgsrc/net/tcl-scotty/Makefile:1.39 Thu Jun  2 12:25:47 2016
+++ pkgsrc/net/tcl-scotty/Makefile      Wed Feb  1 09:29:18 2017
@@ -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/
 

Index: pkgsrc/net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c
diff -u pkgsrc/net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c:1.1 pkgsrc/net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c:1.2
--- pkgsrc/net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c:1.1       Wed Mar  5 13:52:29 2014
+++ pkgsrc/net/tcl-scotty/patches/patch-tnm_snmp_tnmSnmpNet.c   Wed Feb  1 09:29:18 2017
@@ -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) {



Home | Main Index | Thread Index | Old Index