monit-general
[Top][All Lists]
Advanced

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

Re: UDP socket tests useless


From: Jan-Henrik Haukeland
Subject: Re: UDP socket tests useless
Date: 12 Aug 2002 20:39:59 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Civil Service)

Jan-Henrik Haukeland <address@hidden> writes:

> You're absolutely right about the select, but since monit connect the
> udp socket a simple read on the socket should in theory return an
> error (ECONNREFUSED) if the server is not running. It should be
> possible to add such a default test in monit (replacing the select
> test for UDP sockets).

Just to prove my point I have enclosed a prototype of the new
default.c test for an UDP server. This is just a test and by all means
no final code.

Test in monitrc:

 port type udp 111 # Should return ok if rpc is running
 port type udp 999 # Will fail assuming no udp server is running on port 999

 

-- 
Jan-Henrik Haukeland

New prototype protocols/default.c which can test an udp server connection:


/*
 * Copyright (C), 2000-2002 by Contributors to the monit codebase. 
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <setjmp.h>

#include "monitor.h"
#include "protocol.h"


/* Private variables */
static sigjmp_buf udptimeout;

/* Private Prototypes */
static void udp_read_timeout(int);

/**
 *  Default service test. Left empty.
 *
 *  @author Jan-Henrik Haukeland, <address@hidden>
 *
 *  @version \$Id: default.c,v 1.5 2002/08/09 00:03:12 hauk Exp $
 *
 *  @file
 */
int check_default(Port_T p) {

  if(p->family==SOCK_DGRAM) {
    
    char buf[1];
    
    if(sigsetjmp(udptimeout, TRUE))
        goto timeout_ok;
    
    set_alarm_handler(udp_read_timeout);
    alarm(2);
    write(p->socket, "", 1);
    if(0>read(p->socket, buf, 1)) {
      log("socket at %s is not ready for i|o -- %s\n", p->address, STRERROR);
      return FALSE;
    }
  }

  timeout_ok:
  
  return TRUE;
    
}



/**
 * Signal handler for udp read timeout
 */
static void udp_read_timeout(int sig) {
  
  siglongjmp(udptimeout, TRUE);
  
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]