History

coredump: add %f for executable filename

The document reads "%e" should be "executable filename" while actually it could be changed by things like pr_ctl PR_SET_NAME. People who uses "%e" in core_pattern get surprised when they find out they get thread name instead of executable filename. This is either a bug of document or a bug of code. Since the behavior of "%e" is there for long time, it could bring another surprise for users if we "fix" the code. So we just "fix" the document. And more, for users who really need the "executable filename" in core_pattern, we introduce a new "%f" for the real executable filename. We already have "%E" for executable path in kernel, so just reuse most of its code for the new added "%f" format.

Lepton Wu committed 6 years ago

Commit f38c85f1 parent 0776d122 files · +15 −5Browse files

Unified · Split

2 files
  1. Documentation/admin-guide/sysctl/kernel.rst +2 −1
  2. fs/coredump.c +13 −4
Documentation/admin-guide/sysctl/kernel.rst+2−1
@@ -164,7 +164,8 @@ core_pattern · 163 unmodified lines
164164 %s signal number
165165 %t UNIX time of dump
166166 %h hostname
167− %e executable filename (may be shortened)
167+ %e executable filename (may be shortened, could be changed by prctl etc)
168+ %f executable filename
168169 %E executable path
169170 %c maximum size of core file by resource limit RLIMIT_CORE
170171 %<OTHER> both are dropped
fs/coredump.c+13−4
@@ -153,10 +153,10 @@ int cn_esc_printf(struct core_name *cn, const char *fmt, ...) · 152 unmodified lines
153153 return ret;
154154 }
155155
156−static int cn_print_exe_file(struct core_name *cn)
156+static int cn_print_exe_file(struct core_name *cn, bool name_only)
157157 {
158158 struct file *exe_file;
159− char *pathbuf, *path;
159+ char *pathbuf, *path, *ptr;
160160 int ret;
161161
162162 exe_file = get_mm_exe_file(current->mm);
@@ -175,6 +175,11 @@ static int cn_print_exe_file(struct core_name *cn) · 12 unmodified lines
175175 goto free_buf;
176176 }
177177
178+ if (name_only) {
179+ ptr = strrchr(path, '/');
180+ if (ptr)
181+ path = ptr + 1;
182+ }
178183 ret = cn_esc_printf(cn, "%s", path);
179184
180185 free_buf:
@@ -301,12 +306,16 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm, · 120 unmodified lines
301306 utsname()->nodename);
302307 up_read(&uts_sem);
303308 break;
304− /* executable */
309+ /* executable, could be changed by prctl PR_SET_NAME etc */
305310 case 'e':
306311 err = cn_esc_printf(cn, "%s", current->comm);
307312 break;
313+ /* file name of executable */
314+ case 'f':
315+ err = cn_print_exe_file(cn, true);
316+ break;
308317 case 'E':
309− err = cn_print_exe_file(cn);
318+ err = cn_print_exe_file(cn, false);
310319 break;
311320 /* core limit size */
312321 case 'c':

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t