More clients.beta.6 patches

Peter Van Epp vanepp at sfu.ca
Wed May 13 00:52:04 EDT 2009


	Another patch set that you may or may not want to include. The
main one is common/argus_client.c and identifies which routine is logging 
and adds a number to some identical messages in a different path so you can
tell which path you got there from. As well it adds a syslog message 
(changed from 1 LOG_ALERT to 5 LOG_NOTICE) so that the socket connect and 
termination of an ra reading from a socket will syslog (and assure me that 
syslog is actually working with ra as well :-)). The command

ra -S192.168.1.1:561 -w /var/log/argus/argus

doesn't trip any of the "Binding ..." messages in the path it takes so this 
logs the "Trying ..." success.

Peter Van Epp

	This change to ra needs to be done to all the ones in the last patch
as well in the same place, but I just did ra this time ...

*** clients/ra.c.orig	Wed Apr 15 12:06:17 2009
--- clients/ra.c	Tue May 12 21:27:03 2009
***************
*** 112,118 ****
        fflush(stdout);
  
  #ifdef ARGUSDEBUG
!       ArgusDebug (2, "RaParseComplete(caught signal $d)\n", sig);
  #endif
        switch (sig) {
           case SIGHUP:
--- 112,119 ----
        fflush(stdout);
  
  #ifdef ARGUSDEBUG
!       ArgusDebug (2, "RaParseComplete(caught signal %d)\n", sig);
!       ArgusLog (LOG_NOTICE, "RaParseComplete(caught signal %d)\n", sig);
  #endif
        switch (sig) {
           case SIGHUP:


*** common/argus_client.c.orig	Tue May 12 20:11:42 2009
--- common/argus_client.c	Tue May 12 21:11:15 2009
***************
*** 2372,2378 ****
  #if defined(HAVE_GETADDRINFO)
              do {
                 if (getnameinfo(hp->ai_addr, hp->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV))
!                   ArgusLog(LOG_ERR, "could not get numeric hostname");
                 
                 if (hp->ai_canonname) {
                    if (input->hostname)
--- 2372,2378 ----
  #if defined(HAVE_GETADDRINFO)
              do {
                 if (getnameinfo(hp->ai_addr, hp->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV))
!                   ArgusLog(LOG_ERR, "ArgusGetServerSocket: could not get numeric hostname");
                 
                 if (hp->ai_canonname) {
                    if (input->hostname)
***************
*** 2387,2396 ****
                 if ((s = socket (hp->ai_family, hp->ai_socktype, hp->ai_protocol)) >= 0) {
                    if (hp->ai_socktype == SOCK_DGRAM) {
  #ifdef ARGUSDEBUG
!                      ArgusLog (1, "Binding %s:%s Expecting %s records", input->hostname, sbuf, ArgusRecordType); 
  #endif
                       if ((retn = bind (s, hp->ai_addr, hp->ai_addrlen)) < 0) {
!                         ArgusLog(LOG_WARNING, "connect to %s:%s failed '%s'", input->hostname, sbuf, strerror(errno));
                          hp = hp->ai_next;
                       } else {
                          retn = s;
--- 2387,2396 ----
                 if ((s = socket (hp->ai_family, hp->ai_socktype, hp->ai_protocol)) >= 0) {
                    if (hp->ai_socktype == SOCK_DGRAM) {
  #ifdef ARGUSDEBUG
!                      ArgusLog (1, "ArgusGetServerSocket: ArgusBinding %s:%s Expecting %s records", input->hostname, sbuf, ArgusRecordType); 
  #endif
                       if ((retn = bind (s, hp->ai_addr, hp->ai_addrlen)) < 0) {
!                         ArgusLog(LOG_WARNING, "ArgusGetServerSocket: connect to %s:%s failed '%s'", input->hostname, sbuf, strerror(errno));
                          hp = hp->ai_next;
                       } else {
                          retn = s;
***************
*** 2400,2415 ****
                    } else {
                       if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(int)) < 0) {
  #ifdef ARGUSDEBUG
!                         ArgusDebug (1, "setsockopt(%d, SOL_SOCKET, SO_KEEPALIVE, 0x%x, %d) failed:", s, optval, sizeof(int));
  #endif
                       }
  #ifdef ARGUSDEBUG
!                      ArgusDebug (1, "Trying %s port %s Expecting %s records\n", input->hostname, sbuf, ArgusRecordType); 
  #endif
                       if ((retn = ArgusConnect (s, hp->ai_addr, hp->ai_addrlen, timeout)) < 0) {
!                         ArgusLog(LOG_WARNING, "connect to %s:%s failed '%s'", input->hostname, sbuf, strerror(errno));
                          hp = hp->ai_next;
                       } else {
                          retn = s;
                          input->fd = s;
                       }
--- 2400,2418 ----
                    } else {
                       if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(int)) < 0) {
  #ifdef ARGUSDEBUG
!                         ArgusDebug (1, "ArgusGetServerSocket 1: setsockopt(%d, SOL_SOCKET, SO_KEEPALIVE, 0x%x, %d) failed:", s, optval, sizeof(int));
  #endif
                       }
  #ifdef ARGUSDEBUG
!                      ArgusDebug (1, "ArgusGetServerSocket 1: Trying %s port %s Expecting %s records\n", input->hostname, sbuf, ArgusRecordType); 
  #endif
                       if ((retn = ArgusConnect (s, hp->ai_addr, hp->ai_addrlen, timeout)) < 0) {
!                         ArgusLog(LOG_WARNING, "ArgusGetServerSocket 1: connect to %s:%s failed '%s'", input->hostname, sbuf, strerror(errno));
                          hp = hp->ai_next;
                       } else {
+ #ifdef ARGUSDEBUG
+                         ArgusLog (LOG_NOTICE, "ArgusGetServerSocket: Binding %s:%s Expecting %s records", input->hostname, sbuf, ArgusRecordType);
+ #endif
                          retn = s;
                          input->fd = s;
                       }
***************
*** 2420,2432 ****
  #ifdef ARGUSDEBUG
                    else {
                       if (hp->ai_socktype == SOCK_DGRAM)
!                         ArgusDebug (1, "receiving\n");
                       else
!                         ArgusDebug (1, "connected\n");
                    }
  #endif
                 } else
!                   ArgusLog (LOG_ERR, "ArgusGetServerSocket: socket() failed. errno %d: %s", errno, strerror(errno));
  
              } while (hp && (retn < 0));
  #endif
--- 2423,2435 ----
  #ifdef ARGUSDEBUG
                    else {
                       if (hp->ai_socktype == SOCK_DGRAM)
!                         ArgusDebug (1, "ArgusGetServerSocket 1: receiving\n");
                       else
!                         ArgusDebug (1, "ArgusGetServerSocket 1: connected\n");
                    }
  #endif
                 } else
!                   ArgusLog (LOG_ERR, "ArgusGetServerSocket 1: socket() failed. errno %d: %s", errno, strerror(errno));
  
              } while (hp && (retn < 0));
  #endif
***************
*** 2447,2457 ****
                    server.sin_port = portnum;
  
  #ifdef ARGUSDEBUG
!                   ArgusLog (1, "Binding %s:%d Expecting %s records", 
                         ArgusGetName(ArgusParser, (unsigned char *)&input->addr.s_addr), ntohs(portnum), ArgusRecordType); 
  #endif
                    if ((bind (s, (struct sockaddr *)&server, sizeof(server))) < 0)
!                      ArgusLog (LOG_ERR, "bind (%d, %s:%hu, %d) failed '%s'", s, inet_ntoa(server.sin_addr),
                                                      server.sin_port, sizeof(server), strerror(errno));
                    retn = s;
                    input->fd = s;
--- 2450,2460 ----
                    server.sin_port = portnum;
  
  #ifdef ARGUSDEBUG
!                   ArgusLog (LOG_NOTICE, "ArgusGetServerSocket 2: Binding %s:%d Expecting %s records", 
                         ArgusGetName(ArgusParser, (unsigned char *)&input->addr.s_addr), ntohs(portnum), ArgusRecordType); 
  #endif
                    if ((bind (s, (struct sockaddr *)&server, sizeof(server))) < 0)
!                      ArgusLog (LOG_ERR, "ArgusGetServerSocket 2: bind (%d, %s:%hu, %d) failed '%s'", s, inet_ntoa(server.sin_addr),
                                                      server.sin_port, sizeof(server), strerror(errno));
                    retn = s;
                    input->fd = s;
***************
*** 2460,2466 ****
                    int optval = 1;
                    if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(int)) < 0) {
  #ifdef ARGUSDEBUG
!                      ArgusDebug (1, "setsockopt(%d, SOL_SOCKET, SO_KEEPALIVE, 0x%x, %d) failed:", s, optval, sizeof(int));
  #endif
                    }
  
--- 2463,2469 ----
                    int optval = 1;
                    if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(int)) < 0) {
  #ifdef ARGUSDEBUG
!                      ArgusDebug (1, "ArgusGetServerSocket 2: setsockopt(%d, SOL_SOCKET, SO_KEEPALIVE, 0x%x, %d) failed:", s, optval, sizeof(int));
  #endif
                    }
  
***************
*** 2471,2477 ****
                       server.sin_family = hp->h_addrtype;
                       server.sin_port = portnum;
  #ifdef ARGUSDEBUG
!                      ArgusDebug (1, "Trying %s port %d Expecting %s records\n", (hp->h_name) ?
                                   (hp->h_name) : intoa (input->addr.s_addr), ntohs(portnum), ArgusRecordType); 
  #endif
                   } else {
--- 2474,2480 ----
                       server.sin_family = hp->h_addrtype;
                       server.sin_port = portnum;
  #ifdef ARGUSDEBUG
!                      ArgusDebug (1, "ArgusGetServerSocket 2: Trying %s port %d Expecting %s records\n", (hp->h_name) ?
                                   (hp->h_name) : intoa (input->addr.s_addr), ntohs(portnum), ArgusRecordType); 
  #endif
                   } else {
***************
*** 2479,2485 ****
                       server.sin_family = AF_INET;
                       server.sin_port = portnum;
  #ifdef ARGUSDEBUG
!                      ArgusDebug (1, "Trying %s port %d Expecting %s records\n", 
                                     intoa (input->addr.s_addr), ntohs(portnum), ArgusRecordType); 
  #endif
                    }
--- 2482,2488 ----
                       server.sin_family = AF_INET;
                       server.sin_port = portnum;
  #ifdef ARGUSDEBUG
!                      ArgusDebug (1, "ArgusGetServerSocket 3: Trying %s port %d Expecting %s records\n", 
                                     intoa (input->addr.s_addr), ntohs(portnum), ArgusRecordType); 
  #endif
                    }
***************
*** 2487,2493 ****
                    input->addr.s_addr = htonl(input->addr.s_addr);
  
                    if ((retn = ArgusConnect (s, (struct sockaddr *)&server, sizeof(server), timeout)) < 0) {
!                      ArgusLog(LOG_WARNING, "connect to %s:%hu failed '%s'", inet_ntoa(server.sin_addr), 
                           ntohs(server.sin_port), strerror(errno));
                       close(s);
  
--- 2490,2496 ----
                    input->addr.s_addr = htonl(input->addr.s_addr);
  
                    if ((retn = ArgusConnect (s, (struct sockaddr *)&server, sizeof(server), timeout)) < 0) {
!                      ArgusLog(LOG_WARNING, "ArgusGetServerSocket 3: connect to %s:%hu failed '%s'", inet_ntoa(server.sin_addr), 
                           ntohs(server.sin_port), strerror(errno));
                       close(s);
  
***************
*** 2497,2511 ****
  
  #ifdef ARGUSDEBUG
                       if (type == SOCK_DGRAM)
!                         ArgusDebug (1, "receiving\n");
                       else
!                         ArgusDebug (1, "connected\n");
  #endif
                    }
                 }
  
              } else {
!                ArgusLog (LOG_ERR, "ArgusGetServerSocket: socket() failed. errno %d: %s", errno, strerror(errno));
              }
  #endif
           }
--- 2500,2514 ----
  
  #ifdef ARGUSDEBUG
                       if (type == SOCK_DGRAM)
!                         ArgusDebug (1, "ArgusGetServerSocket 3: receiving\n");
                       else
!                         ArgusDebug (1, "ArgusGetServerSocket 3: connected\n");
  #endif
                    }
                 }
  
              } else {
!                ArgusLog (LOG_ERR, "ArgusGetServerSocket 3: socket() failed. errno %d: %s", errno, strerror(errno));
              }
  #endif
           }
***************
*** 2524,2530 ****
              if (hp != NULL) {
  #if defined(HAVE_GETADDRINFO)
                 if (getnameinfo(hp->ai_addr, hp->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV))
!                   ArgusLog(LOG_ERR, "could not get numeric hostname");
  
                 if (hp->ai_canonname) {
                    if (input->hostname)
--- 2527,2533 ----
              if (hp != NULL) {
  #if defined(HAVE_GETADDRINFO)
                 if (getnameinfo(hp->ai_addr, hp->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV))
!                   ArgusLog(LOG_ERR, "ArgusGetServerSocket: could not get numeric hostname");
  
                 if (hp->ai_canonname) {
                    if (input->hostname)
***************
*** 2538,2547 ****
  
                 if (hp->ai_socktype == SOCK_DGRAM) {
  #ifdef ARGUSDEBUG
!                   ArgusLog (1, "Binding %s:%s Expecting %s records", input->hostname, sbuf, ArgusRecordType);
  #endif
                    if ((retn = bind (s, hp->ai_addr, hp->ai_addrlen)) < 0) {
!                      ArgusLog(LOG_WARNING, "connect to %s:%s failed '%s'", input->hostname, sbuf, strerror(errno));
                       hp = hp->ai_next;
                    } else {
                       retn = s;
--- 2541,2550 ----
  
                 if (hp->ai_socktype == SOCK_DGRAM) {
  #ifdef ARGUSDEBUG
!                   ArgusLog (LOG_NOTICE, "ArgusGetServerSocket: Binding %s:%s Expecting %s records", input->hostname, sbuf, ArgusRecordType);
  #endif
                    if ((retn = bind (s, hp->ai_addr, hp->ai_addrlen)) < 0) {
!                      ArgusLog(LOG_WARNING, "ArgusGetServerSocket: connect to %s:%s failed '%s'", input->hostname, sbuf, strerror(errno));
                       hp = hp->ai_next;
                    } else {
                       retn = s;
***************
*** 2551,2564 ****
                 } else {
                    if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(int)) < 0) {
  #ifdef ARGUSDEBUG
!                      ArgusDebug (1, "setsockopt(%d, SOL_SOCKET, SO_KEEPALIVE, 0x%x, %d) failed:", s, optval, sizeof(int));
  #endif
                    }
  #ifdef ARGUSDEBUG
!                   ArgusDebug (1, "Trying %s port %s Expecting %s records\n", input->hostname, sbuf, ArgusRecordType);
  #endif
                    if ((retn = ArgusConnect (s, hp->ai_addr, hp->ai_addrlen, timeout)) < 0) {
!                      ArgusLog(LOG_WARNING, "connect to %s:%s failed '%s'", input->hostname, sbuf, strerror(errno));
                       hp = hp->ai_next;
                    } else {
                       retn = s;
--- 2554,2567 ----
                 } else {
                    if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(int)) < 0) {
  #ifdef ARGUSDEBUG
!                      ArgusDebug (1, "ArgusGetServerSocket: setsockopt(%d, SOL_SOCKET, SO_KEEPALIVE, 0x%x, %d) failed:", s, optval, sizeof(int));
  #endif
                    }
  #ifdef ARGUSDEBUG
!                   ArgusDebug (1, "ArgusGetServerSocket: Trying %s port %s Expecting %s records\n", input->hostname, sbuf, ArgusRecordType);
  #endif
                    if ((retn = ArgusConnect (s, hp->ai_addr, hp->ai_addrlen, timeout)) < 0) {
!                      ArgusLog(LOG_WARNING, "ArgusGetServerSocket: connect to %s:%s failed '%s'", input->hostname, sbuf, strerror(errno));
                       hp = hp->ai_next;
                    } else {
                       retn = s;
***************
*** 2571,2579 ****
  #ifdef ARGUSDEBUG
                 else {
                    if (hp->ai_socktype == SOCK_DGRAM)
!                      ArgusDebug (1, "receiving\n");
                    else
!                      ArgusDebug (1, "connected\n");
                 }
  #endif
  #endif
--- 2574,2582 ----
  #ifdef ARGUSDEBUG
                 else {
                    if (hp->ai_socktype == SOCK_DGRAM)
!                      ArgusDebug (1, "ArgusGetServerSocket: receiving\n");
                    else
!                      ArgusDebug (1, "ArgusGetServerSocket: connected\n");
                 }
  #endif
  #endif
***************
*** 2590,2601 ****
                 server.sin_port   = htons(input->portnum);
  #ifdef ARGUSDEBUG
                 if (server.sin_addr.s_addr == INADDR_ANY)
!                   ArgusLog (1, "Binding %s:%d Expecting %s records", "AF_ANY", input->portnum, ArgusRecordType);
                 else
!                   ArgusLog (1, "Binding %s:%d Expecting %s records", (unsigned char *)&input->addr.s_addr, input->portnum, ArgusRecordType);
  #endif
                 if ((retn = bind (s, (struct sockaddr *)&server, sizeof(server))) < 0) {
!                   ArgusLog(LOG_WARNING, "connect to %s:%d failed '%s'", inet_ntoa(server.sin_addr),
                                                ntohs(server.sin_port), sizeof(server), strerror(errno)); 
                    close(s);
  
--- 2593,2604 ----
                 server.sin_port   = htons(input->portnum);
  #ifdef ARGUSDEBUG
                 if (server.sin_addr.s_addr == INADDR_ANY)
!                   ArgusLog (LOG_NOTICE, "ArgusGetServerSocket: Binding %s:%d Expecting %s records", "AF_ANY", input->portnum, ArgusRecordType);
                 else
!                   ArgusLog (LOG_NOTICE, "ArgusGetServerSocket: Binding %s:%d Expecting %s records", (unsigned char *)&input->addr.s_addr, input->portnum, ArgusRecordType);
  #endif
                 if ((retn = bind (s, (struct sockaddr *)&server, sizeof(server))) < 0) {
!                   ArgusLog(LOG_WARNING, "ArgusGetServerSocket: connect to %s:%d failed '%s'", inet_ntoa(server.sin_addr),
                                                ntohs(server.sin_port), sizeof(server), strerror(errno)); 
                    close(s);
  



More information about the argus mailing list