[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 09/17] linux-user: fix /proc/self/stat handling
From: |
Alex Bennée |
Subject: |
[PATCH v2 09/17] linux-user: fix /proc/self/stat handling |
Date: |
Tue, 14 Apr 2020 21:06:23 +0100 |
In the original bug report long files names in Guix caused
/proc/self/stat be truncated without the trailing ") " as specified in
proc manpage which says:
(2) comm %s
The filename of the executable, in parentheses. This
is visible whether or not the executable is swapped
out.
In the kernel this is currently done by do_task_stat calling
proc_task_name() which uses a structure limited by TASK_COMM_LEN (16).
Additionally it should only be reporting the executable name rather
than the full path. Fix both these failings while cleaning up the code
to use GString to build up the reported values. As the whole function
is cleaned up also adjust the white space to the current coding style.
Message-ID: <address@hidden>
Reported-by: Brice Goglin <address@hidden>
Signed-off-by: Alex Bennée <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
---
linux-user/syscall.c | 43 +++++++++++++++++++------------------------
1 file changed, 19 insertions(+), 24 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 6495ddc4cda..674f70e70a5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7295,34 +7295,29 @@ static int open_self_stat(void *cpu_env, int fd)
{
CPUState *cpu = env_cpu((CPUArchState *)cpu_env);
TaskState *ts = cpu->opaque;
- abi_ulong start_stack = ts->info->start_stack;
+ g_autoptr(GString) buf = g_string_new(NULL);
int i;
for (i = 0; i < 44; i++) {
- char buf[128];
- int len;
- uint64_t val = 0;
-
- if (i == 0) {
- /* pid */
- val = getpid();
- snprintf(buf, sizeof(buf), "%"PRId64 " ", val);
- } else if (i == 1) {
- /* app name */
- snprintf(buf, sizeof(buf), "(%s) ", ts->bprm->argv[0]);
- } else if (i == 27) {
- /* stack bottom */
- val = start_stack;
- snprintf(buf, sizeof(buf), "%"PRId64 " ", val);
- } else {
- /* for the rest, there is MasterCard */
- snprintf(buf, sizeof(buf), "0%c", i == 43 ? '\n' : ' ');
- }
+ if (i == 0) {
+ /* pid */
+ g_string_printf(buf, FMT_pid " ", getpid());
+ } else if (i == 1) {
+ /* app name */
+ gchar *bin = g_strrstr(ts->bprm->argv[0], "/");
+ bin = bin ? bin + 1 : ts->bprm->argv[0];
+ g_string_printf(buf, "(%.15s) ", bin);
+ } else if (i == 27) {
+ /* stack bottom */
+ g_string_printf(buf, TARGET_ABI_FMT_ld " ", ts->info->start_stack);
+ } else {
+ /* for the rest, there is MasterCard */
+ g_string_printf(buf, "0%c", i == 43 ? '\n' : ' ');
+ }
- len = strlen(buf);
- if (write(fd, buf, len) != len) {
- return -1;
- }
+ if (write(fd, buf->str, buf->len) != buf->len) {
+ return -1;
+ }
}
return 0;
--
2.20.1
- [PATCH v2 04/17] .gitignore: include common build sub-directories, (continued)
- [PATCH v2 04/17] .gitignore: include common build sub-directories, Alex Bennée, 2020/04/14
- [PATCH v2 01/17] linux-user: completely re-write init_guest_space, Alex Bennée, 2020/04/14
- [PATCH v2 06/17] tests/docker: add docs FEATURE flag and use for test-misc, Alex Bennée, 2020/04/14
- [PATCH v2 07/17] configure: redirect sphinx-build check to config.log, Alex Bennée, 2020/04/14
- [PATCH v2 05/17] linux-user/ppc: Fix padding in mcontext_t for ppc64, Alex Bennée, 2020/04/14
- [PATCH v2 08/17] configure: disable PIE for Windows builds, Alex Bennée, 2020/04/14
- [PATCH v2 12/17] gdbstub: Do not use memset() on GByteArray, Alex Bennée, 2020/04/14
- [PATCH v2 11/17] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb, Alex Bennée, 2020/04/14
- [PATCH v2 13/17] gdbstub: Introduce gdb_get_float32() to get 32-bit float registers, Alex Bennée, 2020/04/14
- [PATCH v2 09/17] linux-user: fix /proc/self/stat handling,
Alex Bennée <=
- [PATCH v2 10/17] target/m68k/helper: Fix m68k_fpu_gdb_get_reg() use of GByteArray, Alex Bennée, 2020/04/14
- [PATCH v2 16/17] tests/tcg: drop inferior.was_attached() test, Alex Bennée, 2020/04/14
- [PATCH v2 17/17] tests/tcg: add a multiarch linux-user gdb test, Alex Bennée, 2020/04/14
- [PATCH v2 15/17] target/m68k: hack around the FPU register support (HACK!), Alex Bennée, 2020/04/14
- [PATCH v2 14/17] gdbstub: Introduce gdb_get_float64() to get 64-bit float registers, Alex Bennée, 2020/04/14
- Re: [PATCH v2 for 5.0-rc3 00/17] more randome fixes (user, pie, docker and gdbstub), no-reply, 2020/04/14