aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2018-05-18 11:47:13 -0400
committerTejun Heo <tj@kernel.org>2018-05-18 11:47:13 -0400
commit88b72b31e15f9dfed069ede5416bb71040e0d299 (patch)
tree0965c46c2b8daeed787781fd0ee62b6333ec513f
parent8bf895931ee3b635888b5a302055f97362c92d79 (diff)
proc: Consolidate task->comm formatting into proc_task_name()
proc shows task->comm in three places - comm, stat, status - and each is fetching and formatting task->comm slighly differently. This patch renames task_name() to proc_task_name(), makes it more generic, and updates all three paths to use it. This will enable expanding comm reporting for workqueue workers. Signed-off-by: Tejun Heo <tj@kernel.org>
-rw-r--r--fs/proc/array.c26
-rw-r--r--fs/proc/base.c5
-rw-r--r--fs/proc/internal.h2
3 files changed, 19 insertions, 14 deletions
diff --git a/fs/proc/array.c b/fs/proc/array.c
index ae2c807fd719..f29221e95792 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -95,7 +95,7 @@
95#include <asm/processor.h> 95#include <asm/processor.h>
96#include "internal.h" 96#include "internal.h"
97 97
98static inline void task_name(struct seq_file *m, struct task_struct *p) 98void proc_task_name(struct seq_file *m, struct task_struct *p, bool escape)
99{ 99{
100 char *buf; 100 char *buf;
101 size_t size; 101 size_t size;
@@ -104,13 +104,17 @@ static inline void task_name(struct seq_file *m, struct task_struct *p)
104 104
105 get_task_comm(tcomm, p); 105 get_task_comm(tcomm, p);
106 106
107 seq_puts(m, "Name:\t");
108
109 size = seq_get_buf(m, &buf); 107 size = seq_get_buf(m, &buf);
110 ret = string_escape_str(tcomm, buf, size, ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\"); 108 if (escape) {
111 seq_commit(m, ret < size ? ret : -1); 109 ret = string_escape_str(tcomm, buf, size,
110 ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\");
111 if (ret >= size)
112 ret = -1;
113 } else {
114 ret = strscpy(buf, tcomm, size);
115 }
112 116
113 seq_putc(m, '\n'); 117 seq_commit(m, ret);
114} 118}
115 119
116/* 120/*
@@ -365,7 +369,10 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
365{ 369{
366 struct mm_struct *mm = get_task_mm(task); 370 struct mm_struct *mm = get_task_mm(task);
367 371
368 task_name(m, task); 372 seq_puts(m, "Name:\t");
373 proc_task_name(m, task, true);
374 seq_putc(m, '\n');
375
369 task_state(m, ns, pid, task); 376 task_state(m, ns, pid, task);
370 377
371 if (mm) { 378 if (mm) {
@@ -400,7 +407,6 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
400 u64 cutime, cstime, utime, stime; 407 u64 cutime, cstime, utime, stime;
401 u64 cgtime, gtime; 408 u64 cgtime, gtime;
402 unsigned long rsslim = 0; 409 unsigned long rsslim = 0;
403 char tcomm[sizeof(task->comm)];
404 unsigned long flags; 410 unsigned long flags;
405 411
406 state = *get_task_state(task); 412 state = *get_task_state(task);
@@ -427,8 +433,6 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
427 } 433 }
428 } 434 }
429 435
430 get_task_comm(tcomm, task);
431
432 sigemptyset(&sigign); 436 sigemptyset(&sigign);
433 sigemptyset(&sigcatch); 437 sigemptyset(&sigcatch);
434 cutime = cstime = utime = stime = 0; 438 cutime = cstime = utime = stime = 0;
@@ -495,7 +499,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
495 499
496 seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns)); 500 seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns));
497 seq_puts(m, " ("); 501 seq_puts(m, " (");
498 seq_puts(m, tcomm); 502 proc_task_name(m, task, false);
499 seq_puts(m, ") "); 503 seq_puts(m, ") ");
500 seq_putc(m, state); 504 seq_putc(m, state);
501 seq_put_decimal_ll(m, " ", ppid); 505 seq_put_decimal_ll(m, " ", ppid);
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 1b2ede6abcdf..bb192a699bce 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1565,9 +1565,8 @@ static int comm_show(struct seq_file *m, void *v)
1565 if (!p) 1565 if (!p)
1566 return -ESRCH; 1566 return -ESRCH;
1567 1567
1568 task_lock(p); 1568 proc_task_name(m, p, false);
1569 seq_printf(m, "%s\n", p->comm); 1569 seq_putc(m, '\n');
1570 task_unlock(p);
1571 1570
1572 put_task_struct(p); 1571 put_task_struct(p);
1573 1572
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 0f1692e63cb6..b823fac621d2 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -131,6 +131,8 @@ unsigned name_to_int(const struct qstr *qstr);
131 */ 131 */
132extern const struct file_operations proc_tid_children_operations; 132extern const struct file_operations proc_tid_children_operations;
133 133
134extern void proc_task_name(struct seq_file *m, struct task_struct *p,
135 bool escape);
134extern int proc_tid_stat(struct seq_file *, struct pid_namespace *, 136extern int proc_tid_stat(struct seq_file *, struct pid_namespace *,
135 struct pid *, struct task_struct *); 137 struct pid *, struct task_struct *);
136extern int proc_tgid_stat(struct seq_file *, struct pid_namespace *, 138extern int proc_tgid_stat(struct seq_file *, struct pid_namespace *,