/* ******************************************************************************* * 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$ * $Author$ * $Date$ * $Revision$ * Purpose : * ******************************************************************************* * * Change History * * $Log$ * ******************************************************************************* */ #ident "$Header$" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "include/bpo_q_internal.h" #include "include/bpo_proc_internal.h" #include "watchdog.h" /* ------------------------------------------------------------------ structures / defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Code start here ------------------------------------------------------------------ */ static void pipeclean( void ) { const char *pipe_dir; pipe_dir= eval_config_default( "PIPE_DIR", "$HOME/pipe" ); scan_dead_pipes( pipe_dir ); return; } static int clean_this_proc( struct shm_process_private *sppp ) { return(SHM_DELETE_PROC); } static void clean_procs( const void *hint ) { Validate_Processes( hint, SHM_CHECK_DEAD_PROCESSES, (Validate_Processes_t)clean_this_proc, NULL ); return; } static int clean_this_q( struct shm_process_private *sppp ) { return(Q_DELETE_QUEUE); } static void clean_queues( const void *hint ) { Validate_Queues( hint, Q_CHECK_DEAD_QUEUES, (Validate_Queues_t)clean_this_q, NULL ); return; } static void cleanup_now( const void *hint ) { pipeclean(); if (hint) { clean_procs( hint ); clean_queues( hint ); } return; } void do_cleanup( const void *hint, int force ) { static pid_t running=(pid_t)0; static time_t until=(time_t)0; static time_t when_next=(time_t)0; time_t now; int interval,duration; interval = get_config_int("CLEANUP_INTERVAL"); if (interval<1) interval=1; interval*=60; duration = get_config_int("CLEANUP_DURATION"); if (duration<1) duration=1; duration*=60; (void)time( &now ); if (running) { if(is_pid_dead(running)) { running=(pid_t)0; }else { /* has it run too long */ if( now > until ) { fprintfile( stderr, "Cleanup child has been running too long\n" ); until = now + duration; } } } if ( running==(pid_t)0 && ( (now < when_next) || force ) ) { when_next = now + interval; until = now + duration; running=fork(); if (running==(pid_t)0) { /* I am the child */ cleanup_now( hint ); exit(0); } } return; } /* -- End of File -- */