Beispiel #1
0
int
syscall_entering_trace(struct tcb *tcp, unsigned int *sig)
{
	/* Restrain from fault injection while the trace executes strace code. */
	if (hide_log(tcp)) {
		tcp->qual_flg &= ~QUAL_INJECT;
	}

	switch (tcp->s_ent->sen) {
		case SEN_execve:
		case SEN_execveat:
#if defined SPARC || defined SPARC64
		case SEN_execv:
#endif
			tcp->flags &= ~TCB_HIDE_LOG;
			break;
	}

	if (!traced(tcp) || (tracing_paths && !pathtrace_match(tcp))) {
		tcp->flags |= TCB_FILTERED;
		return 0;
	}

	tcp->flags &= ~TCB_FILTERED;

	if (hide_log(tcp)) {
		return 0;
	}

	if (inject(tcp))
		tamper_with_syscall_entering(tcp, sig);

	if (cflag == CFLAG_ONLY_STATS) {
		return 0;
	}

#ifdef USE_LIBUNWIND
	if (stack_trace_enabled) {
		if (tcp->s_ent->sys_flags & STACKTRACE_CAPTURE_ON_ENTER)
			unwind_capture_stacktrace(tcp);
	}
#endif

	printleader(tcp);
	tprintf("%s(", tcp->s_ent->sys_name);
	int res = raw(tcp) ? printargs(tcp) : tcp->s_ent->sys_func(tcp);
	fflush(tcp->outf);
	return res;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        usage();
        exit(1);
    }

    long long row_id = atoll(argv[1]);
    if (row_id < 1)
    {
        fprintf(stderr, "No valid row_id: %s\n", argv[1]);
        usage();
        exit(1);
    }

    char *cmd = get_command(row_id);
    if (cmd == NULL)
    {
        fprintf(stderr, "Error: Could not read job command\n");
        exit(1);
    }

    pid_t childpid;

    if ((childpid = fork()) == -1)
    {
        perror("fork failed\n");
        exit(1);
    }

    if (childpid == 0)
    {
        //child
        char *args[] = {cmd, NULL};
        execv(args[0], args);
        return 0;			// dead code, just to avoid GCC warning
    }
    else
    {
        // parent
        drmaa2_save_pid(row_id, childpid);

        pid_t child;
        int status;
        child = waitpid(childpid, &status, 0);

        drmaa2_save_exit_status(row_id, status);

        if (WIFEXITED(status))
        {
            DRMAA2_DEBUG_PRINT("Process terminated normally by a call to _exit(2) or exit(3).\n");
            DRMAA2_DEBUG_PRINT("%d  - evaluates to the low-order 8 bits of the argument passed to _exit(2) or exit(3) by the child.\n", WEXITSTATUS(status));
        }
        if (WIFSIGNALED(status))
        {
            DRMAA2_DEBUG_PRINT("Process terminated due to receipt of a signal.\n");
            DRMAA2_DEBUG_PRINT("%d  - evaluates to the number of the signal that caused the termination of the process.\n", WTERMSIG(status));
            DRMAA2_DEBUG_PRINT("%d  - evaluates as true if the termination of the process was accompanied by the creation of a core \
	             file containing an image of the process when the signal was received.\n", WCOREDUMP(status));
        }
        if (WIFSTOPPED(status))
        {
            DRMAA2_DEBUG_PRINT("Process has not terminated, but has stopped and can be restarted.  This macro can be true only if the wait call \
	             specified the WUNTRACED option or if the child process is being traced (see ptrace(2)).\n");
            DRMAA2_DEBUG_PRINT("%d  - evaluates to the number of the signal that caused the process to stop.\n", WSTOPSIG(status));
        }
        return 0;
    }

}