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
164 %s signal number164 %s signal number
165 %t UNIX time of dump165 %t UNIX time of dump
166 %h hostname166 %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
168 %E executable path169 %E executable path
169 %c maximum size of core file by resource limit RLIMIT_CORE170 %c maximum size of core file by resource limit RLIMIT_CORE
170 %<OTHER> both are dropped171 %<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
153 return ret;153 return ret;
154}154}
155 155
156static int cn_print_exe_file(struct core_name *cn)156static int cn_print_exe_file(struct core_name *cn, bool name_only)
157{157{
158 struct file *exe_file;158 struct file *exe_file;
159 char *pathbuf, *path;159 char *pathbuf, *path, *ptr;
160 int ret;160 int ret;
161 161
162 exe_file = get_mm_exe_file(current->mm);162 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
175 goto free_buf;175 goto free_buf;
176 }176 }
177 177
178 if (name_only) {
179 ptr = strrchr(path, '/');
180 if (ptr)
181 path = ptr + 1;
182 }
178 ret = cn_esc_printf(cn, "%s", path);183 ret = cn_esc_printf(cn, "%s", path);
179 184
180free_buf:185free_buf:
@@ -301,12 +306,16 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm, · 120 unmodified lines
301 utsname()->nodename);306 utsname()->nodename);
302 up_read(&uts_sem);307 up_read(&uts_sem);
303 break;308 break;
304 /* executable */309 /* executable, could be changed by prctl PR_SET_NAME etc */
305 case 'e':310 case 'e':
306 err = cn_esc_printf(cn, "%s", current->comm);311 err = cn_esc_printf(cn, "%s", current->comm);
307 break;312 break;
313 /* file name of executable */
314 case 'f':
315 err = cn_print_exe_file(cn, true);
316 break;
308 case 'E':317 case 'E':
309 err = cn_print_exe_file(cn);318 err = cn_print_exe_file(cn, false);
310 break;319 break;
311 /* core limit size */320 /* core limit size */
312 case 'c':321 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