Ejemplo n.º 1
0
/*
 * You should free the string once you've used it
 */
char * getPortFromFile( const char * fmt, ... ) {
    char fname[PATH_MAX];
    char dirname[PATH_MAX];
    char *retPort;
    char *cerr;
    va_list ap;
    FILE * fp;
    int done = 0;
    int count = 0;              /* Just used for the NFS sync - not really a count */
    
    retPort = (char * ) calloc( MPI_MAX_PORT_NAME + 1, sizeof( char ) );

    va_start( ap, fmt );
    vsnprintf( fname, PATH_MAX, fmt, ap );
    va_end( ap );
    
    srand( getpid() );

    while( !done ) {
        count += rand();
        fp = fopen( fname, "rt" );
        if( fp != NULL ) {
            cerr = fgets( retPort, MPI_MAX_PORT_NAME, fp );
            fclose( fp );
            /* ignore bogus tag - assume that the real tag must be longer than 8
             * characters */
            if( strlen( retPort ) >= 8 ) {
                done = 1;
            } 
        } 
        if ( !done ) {
            int retcode;
            safeSleep( 0.1 );
            /* force NFS to update by creating and then deleting a subdirectory. Ouch. */
            snprintf( dirname, PATH_MAX, "%s___%d", fname, count );
            retcode = mkdir( dirname, 0777 );
            if( retcode != 0 ) {
                perror( "Calling mkdir" );
                _exit( 9 );
            } else {
                rmdir( dirname );
            }
        }
    }
    return retPort;
}
Ejemplo n.º 2
0
static void *threadLooper(void *x)
{
    int runTime = 0;
    size_t lastStrokeSeen = sWatchdogStrokeCount;
    /* allow to run for up to 2 minutes */
    while (runTime < sWatchdogTimeout) {
        safeSleep(5);
        runTime += 5;
        if (lastStrokeSeen == sWatchdogStrokeCount) {
            msg("Watchdog not stroked for a while, printing stack: \n");
            printStackTrace();
        }
        lastStrokeSeen = sWatchdogStrokeCount;
    }
    msg("Watchdog about to abort with a timeout after %d\n", runTime);
    _exit(20);
    return NULL;
}