From: Cameron Esfahani <dirty@apple.com>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu
Subject: [PATCH] linux-user: Implement starttime field in self stat emulation
Date: Mon, 24 Jan 2022 18:47:12 -0800 [thread overview]
Message-ID: <20220125024712.6626-1-dirty@apple.com> (raw)
Instead of always returning 0, return actual starttime.
Signed-off-by: Cameron Esfahani <dirty@apple.com>
---
linux-user/syscall.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 5950222a77..59265ab986 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8107,6 +8107,34 @@ static int open_self_stat(void *cpu_env, int fd)
} else if (i == 3) {
/* ppid */
g_string_printf(buf, FMT_pid " ", getppid());
+ } else if (i == 21) {
+ /* starttime */
+ FILE *fp = NULL;
+ char *line = NULL;
+ char *skipped_comm = NULL;
+ size_t n = 0;
+ unsigned long long starttime = 0;
+
+ fp = fopen("/proc/self/stat", "r");
+ if (fp) {
+ if (getdelim(&line, &n, '\0', fp) != -1) {
+ /* Find end of comm field */
+ skipped_comm = strrchr(line, ')');
+ if (skipped_comm != NULL) {
+ /* Skip over parenthesis and space */
+ skipped_comm += 2;
+ /* Scan starttime (field 20 after pid and comm) */
+ (void) sscanf(skipped_comm, "%*c %*d %*d %*d %*d %*d "
+ "%*u %*u %*u %*u %*u %*u %*u %*d "
+ "%*d %*d %*d %*d %*d %llu",
+ &starttime);
+ }
+ free(line);
+ }
+ fclose(fp);
+ }
+
+ g_string_printf(buf, "%llu ", starttime);
} else if (i == 27) {
/* stack bottom */
g_string_printf(buf, TARGET_ABI_FMT_ld " ", ts->info->start_stack);
--
2.32.0 (Apple Git-131)
next reply other threads:[~2022-01-25 2:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-25 2:47 Cameron Esfahani [this message]
2022-01-25 9:41 ` [PATCH] linux-user: Implement starttime field in self stat emulation Laurent Vivier
2022-01-25 10:12 ` Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220125024712.6626-1-dirty@apple.com \
--to=dirty@apple.com \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.