/* ******************************************************************************* * Copyright (c) 1997 Martin Poole * ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * System : * Subsystem : * Module : * $Source: /home/cvs/cvsroot/onelan/onelan/src/mplib1/util/watch_loop.c,v $ * $Author: mpoole $ * $Date: 2002/10/07 09:37:30 $ * $Revision: 1.2 $ * Purpose : * ******************************************************************************* * * Change History * * $Log: watch_loop.c,v $ * Revision 1.2 2002/10/07 09:37:30 mpoole * Initial checkin of mplib1-3.1.0 * * Revision 1.1 2002/10/07 09:37:09 mpoole * Initial checkin of mplib1-3.1.0 * * ******************************************************************************* */ #ident "$Header: /home/cvs/cvsroot/onelan/onelan/src/mplib1/util/watch_loop.c,v 1.2 2002/10/07 09:37:30 mpoole Exp $" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "watchdog.h" #include "watch_lock.h" /* ------------------------------------------------------------------ structures / defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ static void touch_watch_lock( void ) { const char *lname; lname = get_lock_name(); utime( lname, NULL ); return; } int lock_watch_lock( void ) { const char *lname; lname = get_lock_name(); return(lock_file(lname)); } static int watch_check( const void *comms_hint ) { int rv=0; check_cfg_file( 0 ); touch_watch_lock(); if (comms_hint) { rv = watch_ctrl( comms_hint ); } prog_track( comms_hint ); return(rv); } static void show_track( struct pid_track *ptp, FILE *fh ) { fprintf( fh, "Track: %p pid %s %d %d\n", ptp, ptp->pid_str, ptp->starting, ptp->dying ); return; } static void p_show( struct program_hdr *pptr, FILE *fh ) { fprintf( fh, "Program Item: %p active %d lvl %d\n", pptr, pptr->active, pptr->lvl_exclude ); print_prg_hdr( pptr, fh ); /* Now list the track details */ dl_Walk_List( &pptr->running_pids, (dl_Walk_List_t)show_track, fh ); return; } static void l_show( struct level_hdr *lptr, FILE *fh ) { fprintf( fh, "Level Hdr: %p\n", lptr ); print_lvl_hdr( lptr, fh ); return; } static int usr2_func( int t ) { walk_all_programs( (void (*)(struct program_hdr *,void *))p_show, stderr ); walk_all_levels( (void (*)(struct level_hdr *,void *))l_show, stderr ); t=0; return(t); } int watchdog_main_loop( const void *comms_hint ) { int rv=0,t,poll_period; /* Do all those thing we're supposed to do */ fprintfile(stderr,"Watchdog Starting\n" ); do { poll_period = get_config_int( "POLL_PERIOD" ); if (poll_period<1) poll_period=5; switch(t=check_signalling()) { case SIGTERM : rv = t; break; case SIGUSR1 : rv = 0; break; case SIGUSR2 : usr2_func( 0 ); rv = 0; break; case SIGHUP : restart_files(); break; default : rv = watch_check( comms_hint ); break; } if (rv==0) { t = check_kills( stderr ); if (t && t