diff -u -r monit-2.5.orig/l.l monit-2.5.devsocket/l.l --- monit-2.5.orig/l.l Wed Jul 10 21:43:30 2002 +++ monit-2.5.devsocket/l.l Wed Jul 24 17:16:04 2002 @@ -71,6 +71,7 @@ start { return START; } stop { return STOP; } port(number)? { return PORT; } +unix(socket)? { return UNIXSOCKET; } type { return TYPE; } proto(col)? { return PROTOCOL; } tcp { return TCP; } diff -u -r monit-2.5.orig/monitor.h.in monit-2.5.devsocket/monitor.h.in --- monit-2.5.orig/monitor.h.in Fri Jul 12 14:08:42 2002 +++ monit-2.5.devsocket/monitor.h.in Wed Jul 24 15:41:50 2002 @@ -115,9 +115,11 @@ typedef struct myport { volatile int socket; /**< Socket used for connection */ int type; /**< Socket type used for connection (UDP/TCP) */ + int family; /**< Socket family used for connection (INET/UNIX) */ char *hostname; /**< Hostname to check */ int port; /**< Portnumber */ char *request; /**< Specific protocol request */ + char *pathname; /**< Pathname, in case of an UNIX socket */ /**< Object used for testing a port's service */ struct myprotocol { diff -u -r monit-2.5.orig/net.c monit-2.5.devsocket/net.c --- monit-2.5.orig/net.c Fri Jul 5 20:53:51 2002 +++ monit-2.5.devsocket/net.c Wed Jul 24 17:19:06 2002 @@ -38,6 +38,7 @@ #include #include #include +#include #include "monitor.h" #include "net.h" @@ -158,6 +159,39 @@ memcpy(&sin.sin_addr, hp->h_addr, hp->h_length); if ( connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0 ) { + + close_socket(s); + return -1; + + } + + return s; + +} + +/** + * Open a socket against pathname with the given protocol. + * The protocol is normaly either SOCK_STREAM or SOCK_DGRAM. + * @param pathname The unix socket to connect to + * @param protocol Socket protocol to use (SOCK_STREAM|SOCK_DGRAM) + * @return The socket or -1 if an error occured. + */ +int create_unix_socket(char *pathname, int protocol) { + + int s; + struct hostent *hp; + struct sockaddr_un unixsocket; + + if ( (s= socket(PF_UNIX, protocol, 0)) < 0 ) { + + return -1; + + } + + unixsocket.sun_family= AF_UNIX; + snprintf(unixsocket.sun_path, sizeof(unixsocket.sun_path), "%s", pathname); + + if ( connect(s, (struct sockaddr *)&unixsocket, sizeof(unixsocket)) < 0 ) { close_socket(s); return -1; diff -u -r monit-2.5.orig/net.h monit-2.5.devsocket/net.h --- monit-2.5.orig/net.h Tue Jul 2 20:44:07 2002 +++ monit-2.5.devsocket/net.h Wed Jul 24 17:18:17 2002 @@ -30,6 +30,7 @@ int check_host(char *); int check_socket(int); int create_socket(char*, int, int); +int create_unix_socket(char*, int); int create_server_socket(int, int, char *bindAddr); int close_socket(int); int set_sotimeout(int, int); diff -u -r monit-2.5.orig/p.y monit-2.5.devsocket/p.y --- monit-2.5.orig/p.y Fri Jul 12 10:14:35 2002 +++ monit-2.5.devsocket/p.y Thu Jul 25 11:53:52 2002 @@ -77,7 +77,9 @@ char *hostname; int port; int type; + int family; char *request; + char *pathname; Protocol_T protocol; }; @@ -96,7 +98,7 @@ static Process_T current= NULL; static struct IHavePrecedence ihp= { FALSE, FALSE }; static struct MailFilter mtf= { NULL, NULL, NULL, FALSE, FALSE, FALSE }; - static struct PortSet portset= { -1, NULL, 0, SOCK_STREAM, NULL, NULL }; + static struct PortSet portset= { -1, NULL, 0, SOCK_STREAM, AF_INET, NULL, NULL, NULL }; /* Private prototypes */ static void initialize(); @@ -128,7 +130,7 @@ %token SET LOGFILE DAEMON SYSLOG MAILSERVER HTTPD ALLOW ADDRESS INIT %token CHECK PIDFILE START STOP %token HOST PORT TYPE UDP TCP PROTOCOL -%token ALERT MAILFORMAT +%token ALERT MAILFORMAT UNIXSOCKET %token TIMEOUT RESTART CHECKSUM EXPECT EVERY %token DEFAULT HTTP FTP SMTP POP IMAP NNTP %token STRING PATH MAILADDR MAILFROM MAILSUBJECT MAILBODY @@ -167,6 +169,9 @@ | host port type protocol { addport(&portset); } + | unixsocket type protocol { + addport(&portset); + } | timeout | every | alert @@ -276,7 +281,10 @@ | HOST STRING { check_hostname($2); portset.hostname= $2; } ; -port : PORT NUMBER { portset.port= $2; } +port : PORT NUMBER { portset.port= $2; portset.family= AF_INET; } + ; + +unixsocket : UNIXSOCKET PATH { portset.pathname= $2; portset.family= AF_UNIX; } ; type : /* EMPTY */ { portset.type= SOCK_STREAM; } @@ -589,8 +597,10 @@ p->hostname= pp->hostname; p->port= pp->port; p->type= pp->type; + p->family= pp->family; p->request= pp->request; p->protocol= pp->protocol; + p->pathname= pp->pathname; p->next= current->portlist; current->portlist= p; @@ -737,8 +747,10 @@ portset.hostname= NULL; portset.port= 0; portset.type= SOCK_STREAM; + portset.family= AF_INET; portset.request= NULL; portset.protocol= NULL; + portset.pathname= NULL; } diff -u -r monit-2.5.orig/util.c monit-2.5.devsocket/util.c --- monit-2.5.orig/util.c Fri Jul 12 14:41:47 2002 +++ monit-2.5.devsocket/util.c Thu Jul 25 10:13:30 2002 @@ -30,6 +30,7 @@ #include #include #include +#include #include "monitor.h" #include "engine.h" @@ -328,8 +329,16 @@ for (n= p->portlist; n; n= n->next) { - printf(" %-20s = %s:%d%s [protocol %s]\n", "Host:Port", - n->hostname, n->port, n->request?n->request:"", n->protocol->name); + if ( n->family == AF_INET ) { + + printf(" %-20s = %s:%d%s [protocol %s]\n", "Host:Port", + n->hostname, n->port, n->request?n->request:"", n->protocol->name); + } else if ( n->family == AF_UNIX ) { + + printf(" %-20s = %s\n", "Unix Socket", + n->pathname); + + } } diff -u -r monit-2.5.orig/validate.c monit-2.5.devsocket/validate.c --- monit-2.5.orig/validate.c Fri Jul 12 10:14:35 2002 +++ monit-2.5.devsocket/validate.c Thu Jul 25 11:54:16 2002 @@ -25,6 +25,7 @@ #include #include #include +#include #include "monitor.h" #include "net.h" @@ -217,8 +218,18 @@ /* Control comes here if a timeout occures */ if ( sigsetjmp(timeout, TRUE) ) { - log("'%s' timed out when testing %s:%d [%s]\n", - p->name, pp->hostname, pp->port, pp->protocol->name); + if ( pp->family == AF_INET ) { + + log("'%s' timed out when testing %s:%d [%s]\n", + p->name, pp->hostname, pp->port, pp->protocol->name); + + } else if ( pp->family == AF_UNIX ) { + + log("'%s' timed out when testing %s [%s]\n", + p->name, pp->pathname, pp->protocol->name); + + } + rv= FALSE; goto timeout; @@ -228,30 +239,65 @@ set_alarm_handler(connection_timeout); alarm(CHECK_TIMEOUT); - /* Open a socket to hostname:port */ - if( (pp->socket= create_socket(pp->hostname, pp->port, pp->type)) < 0 ) { + if( pp->family == AF_INET ) { + + /* Open a socket to hostname:port */ + if( (pp->socket= create_socket(pp->hostname, pp->port, pp->type)) < 0 ) { + + log("'%s' does not accept connection at %s:%d.\n", + p->name, pp->hostname, pp->port); + rv= FALSE; + goto timeout; + + } else { - log("'%s' does not accept connection at %s:%d.\n", - p->name, pp->hostname, pp->port); - rv= FALSE; - goto timeout; + if ( Run.debug ) { + + log("'%s' succeeded connecting to %s:%d\n", + p->name, pp->hostname, pp->port); + + } - } else { + } + + } else if( pp->family == AF_UNIX ) { + + /* Open a socket to pathname */ + if( (pp->socket= create_unix_socket(pp->pathname, pp->type)) < 0 ) { + + log("'%s' does not accept connection at %s.\n", + p->name, pp->pathname); + rv= FALSE; + goto timeout; + + } else { - if ( Run.debug ) { + if ( Run.debug ) { - log("'%s' succeeded connecting to %s:%d\n", - p->name, pp->hostname, pp->port); + log("'%s' succeeded connecting to %s\n", + p->name, pp->pathname); - } + } + } + } /* Verify that the socket is ready for i|o */ if ( ! check_socket(pp->socket) ) { - log("'%s', socket at port %d is not ready for i|o -- %s\n", - p->name, pp->port, STRERROR); + if ( pp->family == AF_INET ) { + + log("'%s', socket at port %d is not ready for i|o -- %s\n", + p->name, pp->port, STRERROR); + + } else if ( pp->family == AF_UNIX ) { + + log("'%s', socket at file %s is not ready for i|o -- %s\n", + p->name, pp->pathname, STRERROR); + + } + rv= FALSE; goto timeout; @@ -260,8 +306,18 @@ /* Run the protocol verification routine through the socket */ if ( ! pp->protocol->check(pp) ) { - log("'%s', test with protocol [%s] failed at %s:%d.\n", - p->name, pp->protocol->name, pp->hostname, pp->port); + if ( pp->family == AF_INET ) { + + log("'%s', test with protocol [%s] failed at %s:%d.\n", + p->name, pp->protocol->name, pp->hostname, pp->port); + + } else if ( pp->family == AF_UNIX ) { + + log("'%s', test with protocol [%s] failed at %s.\n", + p->name, pp->protocol->name, pp->pathname); + + } + rv= FALSE; goto timeout; @@ -269,11 +325,18 @@ if ( Run.debug ) { - log("'%s' succeeded testing protocol [%s] at %s:%d\n", - p->name, pp->protocol->name, pp->hostname, pp->port); + if ( pp->family == AF_INET ) { + + log("'%s' succeeded testing protocol [%s] at %s:%d\n", + p->name, pp->protocol->name, pp->hostname, pp->port); + } else if ( pp->family == AF_UNIX ) { + + log("'%s' succeeded testing protocol [%s] at %s\n", + p->name, pp->protocol->name, pp->pathname); + + } } - } timeout: