void terminate_if_requested( void ) { if ( tport_getflag( &Region ) == TERMINATE ) { tport_detach( &Region ); logit( "t", "orb2eworm: Termination requested; exiting\n" ); fflush( stdout ); exit( 0 ); } else { return; } }
main( int argc, char *argv[] ) { char *runPath; char ringname[MAX_RING_STR]; char configFile[FILENAME_MAX] = DEF_CONFIG; FILE *stream; /* Check the number of arguments. ******************************/ if ( argc == 3 ) { strcpy ( configFile, argv[1] ); if (strncasecmp(argv[2], "-r", 2) == 0 || strncasecmp(argv[2], "/r", 2) == 0) { redirect = 1; } } else if ( argc == 2 ) { if (strncasecmp(argv[1], "-r", 2) == 0 || strncasecmp(argv[1], "/r", 2) == 0) redirect = 1; else strcpy ( configFile, argv[1] ); } else { fprintf ( stderr, "using default config file %s\n", configFile ); } /* Change working directory to environment variable EW_PARAMS value ****************************************************************/ runPath = getenv( "EW_PARAMS" ); if ( runPath == NULL ) { fprintf(stderr, "status: Environment variable EW_PARAMS not defined." ); fprintf(stderr, " Exiting.\n" ); return -1; } if ( *runPath == '\0' ) { fprintf(stderr, "status: Environment variable EW_PARAMS " ); fprintf(stderr, "defined, but has no value. Exiting.\n" ); return -1; } if ( chdir_ew( runPath ) == -1 ) { fprintf(stderr, "status: Params directory not found: %s\n", runPath ); fprintf(stderr, "status: Reset environment variable EW_PARAMS." ); fprintf(stderr, " Exiting.\n" ); return -1; } /* Look up ids in earthworm.d tables ***********************************/ if ( GetLocalInst( &InstId ) != 0 ) { fprintf( stderr, "status: error getting local installation id; exiting!\n" ); return -1; } if ( GetModId( "MOD_STATUS", &MyModId ) != 0 ) { fprintf( stderr, "status: Invalid module id <MOD_STATUS> exiting!\n" ); return -1; } if ( GetType( "TYPE_REQSTATUS", &TypeReqStatus ) != 0 ) { fprintf( stderr, "status: Invalid message type <TYPE_REQSTATUS> exiting!\n" ); return -1; } if ( GetType( "TYPE_STATUS", &TypeStatus ) != 0 ) { fprintf( stderr, "status: Invalid message type <TYPE_STATUS> exiting!\n" ); return -1; } if ( GetType( "TYPE_RESTART", &TypeRestart ) != 0 ) { fprintf( stderr, "restart: Invalid message type <TYPE_RESTART> exiting!\n" ); return -1; } /* if ( GetType( "Port", &Port ) != 0 ) { fprintf( stderr, "status: Invalid module id <MOD_STATUS> exiting!\n" ); return -1; } */ /* Read startstop's config file to find a valid transport ring name ******************************************************************/ ReadRingName( ringname, configFile ); if( (ringKey = GetKey(ringname)) == -1 ) { printf( "status: Invalid ring name <%s>. Exiting.\n", ringname ); return -1; } if (redirect != 0) { stream = freopen("status_output.log", "w", stdout); if (stream == NULL) { fprintf( stderr, "Unable to redirect output to 'status_output.log'\n"); } } /* Attach to shared memory ring *****************************/ fprintf( stdout, "NOTE: If next line reads \"ERROR: tport_attach...\"," " Earthworm is not running.\n" ); tport_attach( ®ion, ringKey ); SocketLoop(); if (redirect != 0) fclose(stream); tport_detach( ®ion ); return 0; }