/* ******************************************************************************* * 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$ * $Author$ * $Date$ * $Revision$ * Purpose : List running programs (in shm) * ******************************************************************************* * * 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_init_internal.h" #include "include/bpo_q_internal.h" #include "include/bpo_proc_internal.h" #include /* ------------------------------------------------------------------ structures / defines ------------------------------------------------------------------ */ static char dead_str[]="dead"; static char live_str[]="live"; static int verbose=0; static int cleanup=0; /* ------------------------------------------------------------------ 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; } static void Set_Time_Str( time_t this_now, char *tstr, size_t tsize, const char *format ) { time_t now; struct tm *tptr; now = (this_now==(time_t) 0) ? time(NULL): this_now; /* tptr = localtime( &now );*/ /* strftime( tstr, tsize, (format)?format:"%T %Y/%m/%d %Z", tptr );*/ /* We will now use the format described in ISO 8601 for our time/date strings. Since the standard does not allow for civil time zones (CET/EST) since these change and are ambiguous. Unfortunately, the tm structure does not provide the offset values for a given zone. Neither is there a function which can convert from one format to the other. To avoid this we also print in UTC. */ tptr = gmtime( &now ); strftime( tstr, tsize, (format)?format:"%Y-%m-%d %H:%M:%SZ", tptr ); return; } static const char * meos( const char *cp ) { return( (cp)?cp:"-" ); } static int disp_proc( struct shm_process_private *shmpp, void *p1 ) { char tstr[40], *state_str; int q_dead,rv=SHM_LEAVE_PROC; Set_Time_Str( shmpp->pid_start_tm, tstr, 40, NULL ); q_dead = is_pid_dead( shmpp->pid ); if (q_dead) state_str=dead_str; else state_str=live_str; if (q_dead==0 || verbose) fprintf( stdout, " %-12.12s\t%-15.15s\t%-15.15s\t%s\t%s\n", meos(shmpp->pid_str), meos(shmpp->pid_nm), meos(shmpp->pid_grp), state_str, tstr ); if (q_dead && cleanup) rv = SHM_DELETE_PROC; return(rv); } int main ( int argc, char *argv[] ) { int optc; int cfg_read=0; char *cp; char config_name[200]; void *vp=NULL; while ((optc = getopt(argc, argv, "Cf:v")) != EOF) switch (optc) { case 'C' : cleanup=1; break; case 'f': read_config_file( optarg ); strcpy( config_name, optarg ); cfg_read=1; break; case 'v': verbose = 1; 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 );*/ read_config_file( config_name ); } /* Now we call the various initialisation routines */ /* Attach to shared memory */ if (get_config_flag("NO_SHARED_MEMORY")==0) { 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" ); Validate_Processes( vp, SHM_CHECK_ALL_PROCESSES, disp_proc, NULL ); } return(0); } /* -- End of File -- */