Re: [PATCH] task name handling in proc fs

From: Andrew Morton
Date: Wed Jul 07 2004 - 17:09:42 EST


Mike Kravetz <kravetz@xxxxxxxxxx> wrote:
>
> +void set_task_comm(struct task_struct *tsk, char *name)
> +{
> + int i, ch;
> +
> + task_lock(tsk);
> + for (i=0; (ch = *(name++)) != '\0';) {
> + if (ch == '/')
> + i = 0;
> + else
> + if (i < (sizeof(tsk->comm) - 1))
> + tsk->comm[i++] = ch;
> + }
> + tsk->comm[i] = '\0';
> + task_unlock(tsk);
> +}

I don't think the basename logic should be in this function. Only one
caller needs it, and if we later try to use this function to set
current->comm for per-cpu kernel threads, it will mangle the text.

root 2 0.0 0.0 0 0 ? SW Jul06 0:00 [migration/0]
root 3 0.0 0.0 0 0 ? SWN Jul06 0:00 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? SW Jul06 0:00 [migration/1]
root 5 0.0 0.0 0 0 ? SWN Jul06 0:00 [ksoftirqd/1]
root 6 0.0 0.0 0 0 ? SW Jul06 0:00 [migration/2]
root 7 0.0 0.0 0 0 ? SWN Jul06 0:00 [ksoftirqd/2]
root 8 0.0 0.0 0 0 ? SW Jul06 0:00 [migration/3]
root 9 0.0 0.0 0 0 ? SWN Jul06 0:00 [ksoftirqd/3]

We probably won't actually _do_ that, since kthread_create() uses vsnprintf(),
but pushing code which is specific to one caller into a library function
seems wrong...
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/