gcore command to coredump a process

This commit is contained in:
Adriana Szekeres
2011-11-22 16:41:47 +01:00
committed by Ben Gras
parent eaa29370f4
commit c30f014a89
11 changed files with 113 additions and 5 deletions

View File

@@ -317,6 +317,7 @@ int dump_core; /* flag indicating whether to dump core */
/* Tell VFS about the exiting process. */
m.m_type = dump_core ? PM_DUMPCORE : PM_EXIT;
m.PM_PROC = rmp->mp_endpoint;
m.PM_TRACED_PROC = rmp->mp_endpoint;
if (dump_core) {
m.PM_TERM_SIG = rmp->mp_sigstatus;

View File

@@ -477,7 +477,15 @@ PRIVATE void handle_vfs_reply()
if (m_in.PM_STATUS == OK)
rmp->mp_sigstatus |= DUMPED;
exit_restart(rmp, TRUE /*dump_core*/);
if (m_in.PM_PROC == m_in.PM_TRACED_PROC)
/* The reply is to a core dump request
* for a killed process */
exit_restart(rmp, TRUE /*dump_core*/);
else
/* The reply is to a core dump request
* for a traced process (T_DUMPCORE) */
/* Wake up the original caller */
setreply(rmp-mproc, rmp->mp_procgrp);
break;

View File

@@ -42,6 +42,7 @@ PUBLIC int do_trace()
register struct mproc *child;
struct ptrace_range pr;
int i, r, seg, req;
message m;
req = m_in.request;
@@ -90,6 +91,27 @@ PUBLIC int do_trace()
mp->mp_reply.reply_trace = 0;
return(OK);
case T_DUMPCORE:
if ((child = find_proc(m_in.pid)) == NULL) return(ESRCH);
/* Allow dumpcore only if traced! */
if (child->mp_tracer != who_p) return(EPERM);
/* Tell VFS to dump the core. */
m.m_type = PM_DUMPCORE;
m.PM_PROC = mp->mp_endpoint;
m.PM_TRACED_PROC = child->mp_endpoint;
/* Note that m.PM_PROC != m.PM_TRACED_PROC
* (we use this to differentiate between a VFS core dump reply for a
* an exiting process and the one for a traced process) */
m.PM_TERM_SIG = child->mp_sigstatus;
m.PM_PATH = child->mp_name;
tell_vfs(mp, &m);
return(SUSPEND); /* Suspend the process until we receive reply from VFS */
case T_STOP: /* stop the process */
/* This call is not exposed to user programs, because its effect can be
* achieved better by sending the traced process a signal with kill(2).