static gboolean PowerOpsScriptCallback(gpointer _state) { PowerOpState *state = _state; ASSERT(state->pid != INVALID_PID); if (!ProcMgr_IsAsyncProcRunning(state->pid)) { int exitcode; gboolean success; success = (ProcMgr_GetExitCode(state->pid, &exitcode) == 0 && exitcode == 0); g_message("Script exit code: %d, success = %d\n", exitcode, success); PowerOpsStateChangeDone(state, success); ProcMgr_Free(state->pid); state->pid = INVALID_PID; return FALSE; } return TRUE; }
static void VmBackupScriptOpCancel(VmBackupOp *_op) // IN { VmBackupScriptOp *op = (VmBackupScriptOp *) _op; VmBackupScript *scripts = op->state->scripts; VmBackupScript *currScript = NULL; ProcMgr_Pid pid; if (scripts != NULL) { currScript = &scripts[op->state->currentScript]; ASSERT(currScript->proc != NULL); pid = ProcMgr_GetPid(currScript->proc); if (!ProcMgr_KillByPid(pid)) { // XXX: what to do in this situation? other than log and cry? } else { int exitCode; ProcMgr_GetExitCode(currScript->proc, &exitCode); } } op->canceled = TRUE; }
static VmBackupOpStatus VmBackupScriptOpQuery(VmBackupOp *_op) // IN { VmBackupOpStatus ret = VMBACKUP_STATUS_PENDING; VmBackupScriptOp *op = (VmBackupScriptOp *) _op; VmBackupScript *scripts = op->state->scripts; VmBackupScript *currScript = NULL; if (scripts != NULL && op->state->currentScript >= 0) { currScript = &scripts[op->state->currentScript]; } if (op->canceled) { ret = VMBACKUP_STATUS_CANCELED; goto exit; } else if (scripts == NULL || currScript == NULL || currScript->proc == NULL) { ret = VMBACKUP_STATUS_FINISHED; goto exit; } if (!ProcMgr_IsAsyncProcRunning(currScript->proc)) { int exitCode; Bool succeeded; succeeded = (ProcMgr_GetExitCode(currScript->proc, &exitCode) == 0 && exitCode == 0); ProcMgr_Free(currScript->proc); currScript->proc = NULL; /* * If thaw scripts fail, keep running and only notify the failure after * all others have run. */ if (!succeeded) { if (op->type == VMBACKUP_SCRIPT_FREEZE) { ret = VMBACKUP_STATUS_ERROR; goto exit; } else if (op->type == VMBACKUP_SCRIPT_THAW) { op->thawFailed = TRUE; } } switch (VmBackupRunNextScript(op)) { case -1: ret = VMBACKUP_STATUS_ERROR; break; case 0: ret = op->thawFailed ? VMBACKUP_STATUS_ERROR : VMBACKUP_STATUS_FINISHED; break; default: break; } } exit: if (ret == VMBACKUP_STATUS_ERROR) { /* Report the script error to the host */ VmBackup_SendEvent(VMBACKUP_EVENT_REQUESTOR_ERROR, VMBACKUP_SCRIPT_ERROR, "Custom quiesce script failed."); } return ret; }