/* ******************************************************************************* * Copyright (c) 1996 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 ** * * $Source: /home/cvs/cvsroot/onelan/onelan/src/mplib1/util/watchdog.c,v $ * $Author: mpoole $ * $Date: 2002/10/07 09:37:30 $ * $Revision: 1.2 $ * Purpose : Generic Program Watchdog * ******************************************************************************* * * Change History * * $Log: watchdog.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/watchdog.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 #include #include "watchdog.h" #if __STDC__ == 1 extern char * strdup( const char *from ); #endif /* ------------------------------------------------------------------ structures / defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ static void usage ( const char *progname, const char *errstr ) { if (errstr) fprintf( stderr, "Error: %s\n", errstr ); fprintf(stderr, "\nUsage: %s [ -f filename ] [ -v ]\n", progname ); exit(1); return; } int main ( int argc, char *argv[] ) { int optc,verbose =0; int cfg_read=0; char *cp; char config_name[200]; mode_t fifo_mode; void *vp=NULL; char *read_file_name=NULL; char *lvl_excl=NULL; int using_shm=0; while ((optc = getopt(argc, argv, "x:f:r:v")) != EOF) switch (optc) { case 'f': read_config_file( optarg ); strcpy( config_name, optarg ); cfg_read=1; break; case 'r': read_file_name = optarg; break; case 'v': verbose = 1; break; case 'x': /* Exclude some level immediately */ lvl_excl = optarg; break; default: usage( argv[0], "Invalid argument supplied" ); break; } if (!cfg_read) { cp = eval_config_default( NULL, "$HOME/config/watchdog.cfg" ); strcpy( config_name, cp ); /* fprintf(stderr, "Try to read: %s\n", config_name );*/ if (!read_config_file( config_name )) { usage( argv[0], "Config file not found\n" ); } } watch_cfg_file( config_name ); /* Now we call the various initialisation routines */ /* Disconnect */ if (!get_config_flag("NO_LEAVEHOME")) leavehome(); if (lock_watch_lock()==0) return(0); init_signalling(); /* Set our details */ fifo_mode = get_config_int( "FIFO_MODE" ); fifo_mode &= 0666; fifo_mode |= 0600; Set_My_Proc_Details( NULL, "watchdog", NULL, NULL, fifo_mode, 0 ); /* Attach to shared memory */ if (get_config_flag("NO_SHARED_MEMORY")==0) { using_shm=1; vp = comms_shm_attach( eval_config_default( "SHM_CONFIG", "$HOME/config/shm.cfg" ), SODB_READ_CONFIG ); if (vp==NULL) usage( argv[0], "Unable to attach to shared memory\n" ); Register_Process_Details( vp ); create_watch_queues( vp ); } open_job_file( ); if (read_file_name) read_file_into_db( read_file_name ); read_job_file( ); set_all_program_levels(); if (lvl_excl) exclude_named_level( lvl_excl ); /* dump_jobs( stderr );*/ watchdog_main_loop( vp ); close_job_file(); if (using_shm) { delete_watch_queues( vp ); Deregister_Process_Details( vp ); } return(0); } /* -- End of File -- */