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
7 @@ -246,6 +246,17 @@ main(argc, argv)
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
22 * Fine everything is ready; lets listen for events:
23 * the for(;;) loop aborts, if the last client went away.
25 @@ -271,7 +282,25 @@ main(argc, argv)
26 perror("straps: select failed");
29 - if (FD_ISSET(trap_s, &fds)) {
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.
36 + if (FD_ISSET(serv_s, &fds)) {
37 + /* accept a new client: */
38 + memset((char *) &daddr, 0, sizeof(daddr));
39 + dlen = sizeof(daddr);
41 + rc = accept(serv_s, (struct sockaddr *) &daddr, &dlen);
43 + perror("straps: accept failed");
48 + } else if (FD_ISSET(trap_s, &fds)) {
49 /* read trap message and forward to clients: */
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;
56 - } else if (FD_ISSET(serv_s, &fds)) {
57 - memset((char *) &daddr, 0, sizeof(daddr));
58 - dlen = sizeof(daddr);
60 - rc = accept(serv_s, (struct sockaddr *) &daddr, &dlen);
62 - perror("straps: accept failed");
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");
75 /* fd's connected from clients. (XXX: should check for EOF): */
76 for (i = 0; i < FD_SETSIZE; i++) {