Skip to content

Commit 57cc083

Browse files
Jiri Slabytorvalds
authored andcommitted
coredump: add support for exe_file in core name
Now, exe_file is not proc FS dependent, so we can use it to name core file. So we add %E pattern for core file name cration which extract path from mm_struct->exe_file. Then it converts slashes to exclamation marks and pastes the result to the core file name itself. This is useful for environments where binary names are longer than 16 character (the current->comm limitation). Also where there are binaries with same name but in a different path. Further in case the binery itself changes its current->comm after exec. So by doing (s/$/#/ -- # is treated as git comment): $ sysctl kernel.core_pattern='core.%p.%e.%E' $ ln /bin/cat cat45678901234567890 $ ./cat45678901234567890 ^Z $ rm cat45678901234567890 $ fg ^\Quit (core dumped) $ ls core* we now get: core.2434.cat456789012345.!root!cat45678901234567890 (deleted) Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Reviewed-by: Andi Kleen <andi@firstfloor.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3864601 commit 57cc083

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎Documentation/sysctl/kernel.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ core_pattern is used to specify a core dumpfile pattern name.
161161
%s signal number
162162
%t UNIX time of dump
163163
%h hostname
164-
%e executable filename
164+
%e executable filename (may be shortened)
165+
%E executable path
165166
%<OTHER> both are dropped
166167
. If the first character of the pattern is a '|', the kernel will treat
167168
the rest of the pattern as a command to run. The core dump will be

‎fs/exec.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,41 @@ static int cn_printf(struct core_name *cn, const char *fmt, ...)
16231623
return ret;
16241624
}
16251625

1626+
static int cn_print_exe_file(struct core_name *cn)
1627+
{
1628+
struct file *exe_file;
1629+
char *pathbuf, *path, *p;
1630+
int ret;
1631+
1632+
exe_file = get_mm_exe_file(current->mm);
1633+
if (!exe_file)
1634+
return cn_printf(cn, "(unknown)");
1635+
1636+
pathbuf = kmalloc(PATH_MAX, GFP_TEMPORARY);
1637+
if (!pathbuf) {
1638+
ret = -ENOMEM;
1639+
goto put_exe_file;
1640+
}
1641+
1642+
path = d_path(&exe_file->f_path, pathbuf, PATH_MAX);
1643+
if (IS_ERR(path)) {
1644+
ret = PTR_ERR(path);
1645+
goto free_buf;
1646+
}
1647+
1648+
for (p = path; *p; p++)
1649+
if (*p == '/')
1650+
*p = '!';
1651+
1652+
ret = cn_printf(cn, "%s", path);
1653+
1654+
free_buf:
1655+
kfree(pathbuf);
1656+
put_exe_file:
1657+
fput(exe_file);
1658+
return ret;
1659+
}
1660+
16261661
/* format_corename will inspect the pattern parameter, and output a
16271662
* name into corename, which must have space for at least
16281663
* CORENAME_MAX_SIZE bytes plus one byte for the zero terminator.
@@ -1694,6 +1729,9 @@ static int format_corename(struct core_name *cn, long signr)
16941729
case 'e':
16951730
err = cn_printf(cn, "%s", current->comm);
16961731
break;
1732+
case 'E':
1733+
err = cn_print_exe_file(cn);
1734+
break;
16971735
/* core limit size */
16981736
case 'c':
16991737
err = cn_printf(cn, "%lu",

0 commit comments

Comments
 (0)