linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] coredump: Add %f for executable file name.
@ 2020-06-27  4:01 Lepton Wu
  2020-06-27  4:23 ` [PATCH v2] " Lepton Wu
  0 siblings, 1 reply; 4+ messages in thread
From: Lepton Wu @ 2020-06-27  4:01 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: akpm, Lepton Wu

The document reads "%e" should be executable file name while actually
it could be changed by things like pr_ctl PR_SET_NAME. We can't really
change the behavior of "%e" for now, so introduce a new "%f" for the
real executable file name.

Signed-off-by: Lepton Wu <ytht.net@gmail.com>
---
 Documentation/admin-guide/sysctl/kernel.rst |  2 ++
 fs/coredump.c                               | 17 +++++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
index 83acf5025488..f2994cdbd57f 100644
--- a/Documentation/admin-guide/sysctl/kernel.rst
+++ b/Documentation/admin-guide/sysctl/kernel.rst
@@ -165,6 +165,8 @@ core_pattern
 	%t		UNIX time of dump
 	%h		hostname
 	%e		executable filename (may be shortened)
+	%e		executable filename (may be shortened, could be changed by prctl etc)
+	%f      	executable filename
 	%E		executable path
 	%c		maximum size of core file by resource limit RLIMIT_CORE
 	%<OTHER>	both are dropped
diff --git a/fs/coredump.c b/fs/coredump.c
index 7237f07ff6be..76e7c10edfc0 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -153,10 +153,10 @@ int cn_esc_printf(struct core_name *cn, const char *fmt, ...)
 	return ret;
 }
 
-static int cn_print_exe_file(struct core_name *cn)
+static int cn_print_exe_file(struct core_name *cn, bool name_only)
 {
 	struct file *exe_file;
-	char *pathbuf, *path;
+	char *pathbuf, *path, *ptr;
 	int ret;
 
 	exe_file = get_mm_exe_file(current->mm);
@@ -175,6 +175,11 @@ static int cn_print_exe_file(struct core_name *cn)
 		goto free_buf;
 	}
 
+	if (name_only) {
+		ptr = strrchr(path, '/');
+		if (ptr)
+			path = ptr + 1;
+	}
 	ret = cn_esc_printf(cn, "%s", path);
 
 free_buf:
@@ -301,12 +306,16 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm,
 					      utsname()->nodename);
 				up_read(&uts_sem);
 				break;
-			/* executable */
+			/* executable, could be changed by prctl PR_SET_NAME etc */
 			case 'e':
 				err = cn_esc_printf(cn, "%s", current->comm);
 				break;
+			/* file name of executable */
+			case 'f':
+				err = cn_print_exe_file(cn, true);
+				break;
 			case 'E':
-				err = cn_print_exe_file(cn);
+				err = cn_print_exe_file(cn, false);
 				break;
 			/* core limit size */
 			case 'c':
-- 
2.27.0.212.ge8ba1cc988-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] coredump: Add %f for executable file name.
  2020-06-27  4:01 [PATCH] coredump: Add %f for executable file name Lepton Wu
@ 2020-06-27  4:23 ` Lepton Wu
  2020-07-01  2:26   ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Lepton Wu @ 2020-06-27  4:23 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: akpm, Lepton Wu

The document reads "%e" should be executable file name while actually
it could be changed by things like pr_ctl PR_SET_NAME. We can't really
change the behavior of "%e" for now, so introduce a new "%f" for the
real executable file name.

Signed-off-by: Lepton Wu <ytht.net@gmail.com>
---
 Documentation/admin-guide/sysctl/kernel.rst |  3 ++-
 fs/coredump.c                               | 17 +++++++++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
index 83acf5025488..17cd96a54fc4 100644
--- a/Documentation/admin-guide/sysctl/kernel.rst
+++ b/Documentation/admin-guide/sysctl/kernel.rst
@@ -164,7 +164,8 @@ core_pattern
 	%s		signal number
 	%t		UNIX time of dump
 	%h		hostname
-	%e		executable filename (may be shortened)
+	%e		executable filename (may be shortened, could be changed by prctl etc)
+	%f      	executable filename
 	%E		executable path
 	%c		maximum size of core file by resource limit RLIMIT_CORE
 	%<OTHER>	both are dropped
diff --git a/fs/coredump.c b/fs/coredump.c
index 7237f07ff6be..76e7c10edfc0 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -153,10 +153,10 @@ int cn_esc_printf(struct core_name *cn, const char *fmt, ...)
 	return ret;
 }
 
-static int cn_print_exe_file(struct core_name *cn)
+static int cn_print_exe_file(struct core_name *cn, bool name_only)
 {
 	struct file *exe_file;
-	char *pathbuf, *path;
+	char *pathbuf, *path, *ptr;
 	int ret;
 
 	exe_file = get_mm_exe_file(current->mm);
@@ -175,6 +175,11 @@ static int cn_print_exe_file(struct core_name *cn)
 		goto free_buf;
 	}
 
+	if (name_only) {
+		ptr = strrchr(path, '/');
+		if (ptr)
+			path = ptr + 1;
+	}
 	ret = cn_esc_printf(cn, "%s", path);
 
 free_buf:
@@ -301,12 +306,16 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm,
 					      utsname()->nodename);
 				up_read(&uts_sem);
 				break;
-			/* executable */
+			/* executable, could be changed by prctl PR_SET_NAME etc */
 			case 'e':
 				err = cn_esc_printf(cn, "%s", current->comm);
 				break;
+			/* file name of executable */
+			case 'f':
+				err = cn_print_exe_file(cn, true);
+				break;
 			case 'E':
-				err = cn_print_exe_file(cn);
+				err = cn_print_exe_file(cn, false);
 				break;
 			/* core limit size */
 			case 'c':
-- 
2.27.0.212.ge8ba1cc988-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] coredump: Add %f for executable file name.
  2020-06-27  4:23 ` [PATCH v2] " Lepton Wu
@ 2020-07-01  2:26   ` Andrew Morton
  2020-07-01  3:14     ` [PATCH v3] coredump: Add %f for executable filename Lepton Wu
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2020-07-01  2:26 UTC (permalink / raw)
  To: Lepton Wu; +Cc: linux-fsdevel

On Fri, 26 Jun 2020 21:23:03 -0700 Lepton Wu <ytht.net@gmail.com> wrote:

> The document reads "%e" should be executable file name while actually
> it could be changed by things like pr_ctl PR_SET_NAME. We can't really
> change the behavior of "%e" for now, so introduce a new "%f" for the
> real executable file name.

Please explain (in as much detail as possible) why you believe the
kernel should be changed in this way.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3] coredump: Add %f for executable filename.
  2020-07-01  2:26   ` Andrew Morton
@ 2020-07-01  3:14     ` Lepton Wu
  0 siblings, 0 replies; 4+ messages in thread
From: Lepton Wu @ 2020-07-01  3:14 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: akpm, Lepton Wu

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 surprising 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.

Signed-off-by: Lepton Wu <ytht.net@gmail.com>
---
 Documentation/admin-guide/sysctl/kernel.rst |  3 ++-
 fs/coredump.c                               | 17 +++++++++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
index 83acf5025488..17cd96a54fc4 100644
--- a/Documentation/admin-guide/sysctl/kernel.rst
+++ b/Documentation/admin-guide/sysctl/kernel.rst
@@ -164,7 +164,8 @@ core_pattern
 	%s		signal number
 	%t		UNIX time of dump
 	%h		hostname
-	%e		executable filename (may be shortened)
+	%e		executable filename (may be shortened, could be changed by prctl etc)
+	%f      	executable filename
 	%E		executable path
 	%c		maximum size of core file by resource limit RLIMIT_CORE
 	%<OTHER>	both are dropped
diff --git a/fs/coredump.c b/fs/coredump.c
index 7237f07ff6be..76e7c10edfc0 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -153,10 +153,10 @@ int cn_esc_printf(struct core_name *cn, const char *fmt, ...)
 	return ret;
 }
 
-static int cn_print_exe_file(struct core_name *cn)
+static int cn_print_exe_file(struct core_name *cn, bool name_only)
 {
 	struct file *exe_file;
-	char *pathbuf, *path;
+	char *pathbuf, *path, *ptr;
 	int ret;
 
 	exe_file = get_mm_exe_file(current->mm);
@@ -175,6 +175,11 @@ static int cn_print_exe_file(struct core_name *cn)
 		goto free_buf;
 	}
 
+	if (name_only) {
+		ptr = strrchr(path, '/');
+		if (ptr)
+			path = ptr + 1;
+	}
 	ret = cn_esc_printf(cn, "%s", path);
 
 free_buf:
@@ -301,12 +306,16 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm,
 					      utsname()->nodename);
 				up_read(&uts_sem);
 				break;
-			/* executable */
+			/* executable, could be changed by prctl PR_SET_NAME etc */
 			case 'e':
 				err = cn_esc_printf(cn, "%s", current->comm);
 				break;
+			/* file name of executable */
+			case 'f':
+				err = cn_print_exe_file(cn, true);
+				break;
 			case 'E':
-				err = cn_print_exe_file(cn);
+				err = cn_print_exe_file(cn, false);
 				break;
 			/* core limit size */
 			case 'c':
-- 
2.27.0.212.ge8ba1cc988-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-01  3:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-27  4:01 [PATCH] coredump: Add %f for executable file name Lepton Wu
2020-06-27  4:23 ` [PATCH v2] " Lepton Wu
2020-07-01  2:26   ` Andrew Morton
2020-07-01  3:14     ` [PATCH v3] coredump: Add %f for executable filename Lepton Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).