Messages in this thread | | | From | Yafang Shao <> | Date | Fri, 8 Oct 2021 20:14:21 +0800 | Subject | Re: [PATCH v2 4/4] kernel/kthread: show a warning if kthread's comm is truncated |
| |
On Fri, Oct 8, 2021 at 1:41 AM Steven Rostedt <rostedt@goodmis.org> wrote: > > On Thu, 7 Oct 2021 12:07:52 +0000 > Yafang Shao <laoar.shao@gmail.com> wrote: > > > - vsnprintf(name, sizeof(name), namefmt, args); > > + len = vsnprintf(name, sizeof(name), namefmt, args); > > + if (len >= TASK_COMM_LEN) { > > + pr_warn("truncated kthread comm:%s, pid:%d by %d characters\n", > > + name, task->pid, len - TASK_COMM_LEN + 1); > > Instead of saying how many characters it is truncated to, what about just > showing what it was truncated to? > > pr_warn("truncated kthread comm from:%s to:%.*s for pid:%d\n", > name, TASK_COMM_LEN - 1, name, task->pid); > > ? >
The 'name' is the truncated one. So it will be printed like, [ 0.222126] truncated kthread comm from:rcu_tasks_kthre to:rcu_tasks_kthre for pid:10
If we want to show the full name, we have to use the namefmt, which is not suggested to use by Petr. See also https://lore.kernel.org/lkml/YVXVBXSZ1m4ScvbX@alley/
Or we can do it as follows,
- char name[TASK_COMM_LEN]; + /* To show the full name if it will be truncated. */ + char name[TASK_COMM_LEN + 8];
Then the full name will be printed: [ 0.222587] truncated kthread comm from:rcu_tasks_kthread to:rcu_tasks_kthre for pid:10
But that seems a little overkill ?
-- Thanks Yafang
| |