Ejemplo n.º 1
0
static void
ngislSSHjobPBSqueryStatusReadCallback(
    void *arg,
    ngisLineBuffer_t *lBuf,
    char *line,
    ngisCallbackResult_t cResult)
{
    ngisSSHjob_t *job = arg;
    int result;
    int i;
    ngisTokenAnalyzer_t tokenAnalyzer;
    int tokenAnalyzerInitialized = 0;
    char *status = NULL;
    ngisLog_t *log;
    static const char fName[] = "ngislSSHjobPBSqueryStatusReadCallback";

    NGIS_ASSERT(job != NULL);
    NGIS_ASSERT(lBuf != NULL);

    log = job->ngsj_log;

    switch (cResult) {
    case NGIS_CALLBACK_RESULT_EOF:
        ngisErrorPrint(log, fName, "Unexcept EOF.\n");
        goto error;
    case NGIS_CALLBACK_RESULT_CANCEL:
        ngisDebugPrint(log, fName,
            "Callback is canceled.\n");
        return;
    case NGIS_CALLBACK_RESULT_FAILED:
        ngisErrorPrint(log, fName,
            "Can't read the reply.\n");
        goto error;
    case NGIS_CALLBACK_RESULT_SUCCESS:
        break;
    default:
        NGIS_ASSERT_NOTREACHED();
    }

    /* Failed? */
    if (strcmp(line, "dummy") == 0) {
        /* Done */
        job->ngsj_executables[0].nge_exitCode = 0;/* Success */
        result = ngisSSHjobExecutableSetStatus(
            job, &job->ngsj_executables[0],
            NGIS_EXECUTABLE_STATUS_EXIT);
        if (result == 0) {
            ngisErrorPrint(log, fName,
                "Can't set status.\n");            
            goto error;
        }

        result = ngisSSHjobProcessAfterExit(job);
        if (result == 0) {
            ngisErrorPrint(log, fName,
                "Can't process after exit.\n");
            goto error;
        }
        return;
    }

    ngisTokenAnalyzerInitialize(&tokenAnalyzer, line);
    tokenAnalyzerInitialized = 0;

    /* job_state = [STATUS] */
    for (i = 0;i < 2;++i) {
        result = ngisTokenAnalyzerNext(&tokenAnalyzer);
        if (result == 0) {
            ngisErrorPrint(log, fName,
                "Can't get status.\n.");
            goto error;
        }
    }
    
    /* Get Status */
    status = ngisTokenAnalyzerGetString(&tokenAnalyzer);
    if (status == NULL) {
        ngisErrorPrint(log, fName,
            "Can't get status.\n");
        goto error;
    }

    ngisDebugPrint(log, fName, "Status string is \"%s\".\n", status);

    /* Check Status */
    switch (*status) {
    case 'Q':
    case 'W':
    case 'T':
        break;
    case 'B':
    case 'E':
    case 'R':
    case 'X':
        /* t(ransfering), r(unning) */
        job->ngsj_executables[0].nge_status
            = NGIS_EXECUTABLE_STATUS_ACTIVE;
        break;
    case 'H':
        /* Do nothing */
        break;
    case 'S':
        break;
    case 'U':
    default:
        /* DONOTHING */;
    }

    free(status);
    status = NULL;

    ngisTokenAnalyzerFinalize(&tokenAnalyzer);
    tokenAnalyzerInitialized = 0;

    result = ngisLineBufferReadLine(job->ngsj_lBufStdout, 
        ngisSSHjobQueryStatusReadDummyCallback, job);
    if (result == 0) {
        ngisErrorPrint(log, fName, 
            "Can't register the function for reading the line.\n");
        goto error;
    }

    return;
error:
    NGIS_NULL_CHECK_AND_FREE(status);

    if (tokenAnalyzerInitialized != 0) {
        ngisTokenAnalyzerFinalize(&tokenAnalyzer);
        tokenAnalyzerInitialized = 0;
    }
    result = ngisSSHjobProcessAfterExit(job);
    if (result == 0) {
        ngisErrorPrint(NULL, fName, "The job isn't able to be done.\n");
    }
    return;
}
Ejemplo n.º 2
0
/**
 * SSH job: Callback function for "Query exit status"
 */
static void
ngislSSHjobExecutableDoneReadCallback(
    void *arg,
    ngisLineBuffer_t *lBuf,
    char *line,
    ngisCallbackResult_t cResult)
{
    ngisSSHjob_t *job = arg;
    int exitStatus;
    int result;
    int nExit;
    ngisLog_t *log;
    ngisTokenAnalyzer_t tokenAnalyzer;
    int tokenAnalyzerInitialized = 0;
    ngisExecutable_t *exe = NULL;
    static const char fName[] = "ngislSSHjobExecutableDoneReadCallback";

    NGIS_ASSERT(job != NULL);
    NGIS_ASSERT(lBuf != NULL);
    
    log = job->ngsj_log;

    ngisDebugPrint(log, fName, "Called.\n");

    switch (cResult) {
    case NGIS_CALLBACK_RESULT_EOF:
        ngisErrorPrint(log, fName, "Unexcept EOF.\n");
        goto error;
    case NGIS_CALLBACK_RESULT_CANCEL:
        ngisDebugPrint(log, fName, "Callback is canceled.\n");
        return;
    case NGIS_CALLBACK_RESULT_FAILED:
        ngisDebugPrint(log, fName, "Can't read the reply.\n");
        goto error;
    case NGIS_CALLBACK_RESULT_SUCCESS:
        break;
    default:
        NGIS_ASSERT_NOTREACHED();
    }

    NGIS_ASSERT(line != NULL);

    ngisTokenAnalyzerInitialize(&tokenAnalyzer, line);
    tokenAnalyzerInitialized = 1;

    /* Get Exit Status */
    result = ngisTokenAnalyzerGetInt(&tokenAnalyzer, &exitStatus);
    if (result == 0) {
        ngisErrorPrint(log, fName, "Can't get exit status.\n");
        goto error;
    }

    /* Check End */
    result = ngisTokenAnalyzerNext(&tokenAnalyzer);
    if (result != 0) {
        ngisErrorPrint(log, fName, "Unnecessary token.\n.");
        goto error;
    }
    tokenAnalyzerInitialized = 0;
    ngisTokenAnalyzerFinalize(&tokenAnalyzer);

    ngisDebugPrint(log, fName, "Exit status is \"%d\".\n", exitStatus);

    /* Set status */
    exe = &job->ngsj_executables[job->ngsj_iExecutables];
    exe->nge_exitCode = exitStatus;
    result = ngisSSHjobExecutableSetStatus(
        job, exe, NGIS_EXECUTABLE_STATUS_EXIT);
    if (result == 0) {
        ngisErrorPrint(log, fName, "Can't set status.\n");
        goto error;
    }

    nExit = ngisSSHjobGetNexecutable(job, NGIS_EXECUTABLE_STATUS_EXIT);
    if (nExit >= job->ngsj_nExecutables) {
        ngisDebugPrint(log, fName, "All Executable exit.\n");
        result = ngisSSHjobProcessAfterExit(job);
        if (result == 0) {
            ngisErrorPrint(log, fName, "Can't process after exit.\n");
            goto error;
        }
    } else {
        ngisDebugPrint(log, fName, "Check status of the next executable.\n");
        job->ngsj_iExecutables++;
        result = ngislSSHjobQueryStatus(job);
        if (result == 0) {
            ngisErrorPrint(log, fName, "Can't query status.\n");
            goto error;
        }
    }
    return;

error:
    if (tokenAnalyzerInitialized != 0) {
        tokenAnalyzerInitialized = 0;
        ngisTokenAnalyzerFinalize(&tokenAnalyzer);
    }

    result = ngisSSHjobProcessAfterExit(job);
    if (result == 0) {
        ngisErrorPrint(NULL, fName,
            "The job isn't able to be done.\n");
    }
    return;
}