tracing: protect reader of cmdline output

Impact: fix to one cause of incorrect comm outputs in trace

The spinlock only protected the creation of a comm <=> pid pair.
But it was possible that a reader could look up a pid, and get the
wrong comm because it had no locking.

This also required changing trace_find_cmdline to copy the comm cache
and not just send back a pointer to it.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
This commit is contained in:
Steven Rostedt
2009-03-16 19:20:15 -04:00
parent 03303549b1
commit 4ca5308523
5 changed files with 49 additions and 26 deletions

View File

@@ -770,25 +770,29 @@ static void trace_save_cmdline(struct task_struct *tsk)
__raw_spin_unlock(&trace_cmdline_lock);
}
char *trace_find_cmdline(int pid)
void trace_find_cmdline(int pid, char comm[])
{
char *cmdline = "<...>";
unsigned map;
if (!pid)
return "<idle>";
if (!pid) {
strcpy(comm, "<idle>");
return;
}
if (pid > PID_MAX_DEFAULT)
goto out;
if (pid > PID_MAX_DEFAULT) {
strcpy(comm, "<...>");
return;
}
__raw_spin_lock(&trace_cmdline_lock);
map = map_pid_to_cmdline[pid];
if (map >= SAVED_CMDLINES)
goto out;
cmdline = saved_cmdlines[map];
strcpy(comm, saved_cmdlines[map]);
out:
return cmdline;
__raw_spin_unlock(&trace_cmdline_lock);
}
void tracing_record_cmdline(struct task_struct *tsk)