Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / net / tcl-scotty / patches / patch-ag
blobf298c1d7ba31077ea7949c9c7492048a5f890eda
1 $NetBSD: patch-ag,v 1.2 2011/09/02 08:06:55 he Exp $
3 Provide more robustness for the straps helper program.
5 --- tnm/snmp/straps.c.orig      1999-03-09 17:06:10.000000000 +0000
6 +++ tnm/snmp/straps.c
7 @@ -246,6 +246,17 @@ main(argc, argv)
8  #endif
9      
10      /*
11 +     * If there is a steady stream of traps bound for this
12 +     * host, we need to allow some time for the client (scotty)
13 +     * to connect to us.  Otherwise, straps will just exit when
14 +     * the first trap message arrives.  The client does 5 retries
15 +     * with 1 second in-between, so sleeping for 3 should be enough
16 +     * to let the client connect.  There really ought to be a better
17 +     * way to do this.
18 +     */
19 +    sleep(3);
21 +    /*
22       * Fine everything is ready; lets listen for events: 
23       * the for(;;) loop aborts, if the last client went away.
24       */
25 @@ -271,7 +282,25 @@ main(argc, argv)
26               perror("straps: select failed");
27           }
28           
29 -         if (FD_ISSET(trap_s, &fds)) {
30 +         /* 
31 +          * Check for new clients before handling any traps.
32 +          * If a trap arrived while we were sleeping above,
33 +          * we would set go_on to zero before the first client
34 +          * had a chance to connect.
35 +          */
36 +         if (FD_ISSET(serv_s, &fds)) {
37 +              /* accept a new client: */
38 +              memset((char *) &daddr, 0, sizeof(daddr));
39 +              dlen = sizeof(daddr);
40 +            
41 +              rc = accept(serv_s, (struct sockaddr *) &daddr, &dlen);
42 +              if (rc < 0) {
43 +                   perror("straps: accept failed");
44 +                   continue;
45 +              }
46 +              cl_addr [rc] = 1;
48 +         } else if (FD_ISSET(trap_s, &fds)) {
49               /* read trap message and forward to clients: */
50               llen = sizeof(laddr);
51               if ((rc = recvfrom(trap_s, buf, sizeof(buf), 0, 
52 @@ -329,24 +358,6 @@ main(argc, argv)
53                   go_on += cl_addr [i] > 0;
54               }
56 -         } else if (FD_ISSET(serv_s, &fds)) {
57 -             memset((char *) &daddr, 0, sizeof(daddr));
58 -             dlen = sizeof(daddr);
59 -             
60 -             rc = accept(serv_s, (struct sockaddr *) &daddr, &dlen);
61 -             if (rc < 0) {
62 -                 perror("straps: accept failed");
63 -                 continue;
64 -             }
65 -             /* Check for a potential buffer overflow if the accept()
66 -                call returns a file descriptor larger than FD_SETSIZE */
67 -             if (rc >= FD_SETSIZE) {
68 -                 fprintf(stderr, "straps: too many clients\n");
69 -                 close(rc);
70 -                 continue;
71 -             }
72 -             cl_addr [rc] = 1;
74           } else {
75               /* fd's connected from clients. (XXX: should check for EOF): */
76               for (i = 0; i < FD_SETSIZE; i++) {