diff options
author | Jiri Slaby <jslaby@suse.cz> | 2011-05-26 19:25:46 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-05-26 20:12:36 -0400 |
commit | 57cc083ad9e1bfeeb4a0ee831e7bb008c8865bf0 (patch) | |
tree | 03b491fd20b4ca3e58354b15067f6961f32a016b /fs/exec.c | |
parent | 3864601387cf4196371e3c1897fdffa5228296f9 (diff) |
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>
Diffstat (limited to 'fs/exec.c')
-rw-r--r-- | fs/exec.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -1623,6 +1623,41 @@ expand_fail: | |||
1623 | return ret; | 1623 | return ret; |
1624 | } | 1624 | } |
1625 | 1625 | ||
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 | |||
1626 | /* format_corename will inspect the pattern parameter, and output a | 1661 | /* format_corename will inspect the pattern parameter, and output a |
1627 | * name into corename, which must have space for at least | 1662 | * name into corename, which must have space for at least |
1628 | * CORENAME_MAX_SIZE bytes plus one byte for the zero terminator. | 1663 | * 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) | |||
1694 | case 'e': | 1729 | case 'e': |
1695 | err = cn_printf(cn, "%s", current->comm); | 1730 | err = cn_printf(cn, "%s", current->comm); |
1696 | break; | 1731 | break; |
1732 | case 'E': | ||
1733 | err = cn_print_exe_file(cn); | ||
1734 | break; | ||
1697 | /* core limit size */ | 1735 | /* core limit size */ |
1698 | case 'c': | 1736 | case 'c': |
1699 | err = cn_printf(cn, "%lu", | 1737 | err = cn_printf(cn, "%lu", |