[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 24/39] util: Introduce qemu_get_pid_name
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 24/39] util: Introduce qemu_get_pid_name |
Date: |
Fri, 7 Oct 2016 18:57:48 +0200 |
From: Michal Privoznik <address@hidden>
This is a small helper that tries to fetch binary name for given
PID.
Signed-off-by: Michal Privoznik <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
include/qemu/osdep.h | 10 ++++++++++
util/oslib-posix.c | 27 +++++++++++++++++++++++++++
util/oslib-win32.c | 7 +++++++
3 files changed, 44 insertions(+)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 9e9fa61..384bfe2 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -388,6 +388,16 @@ void os_mem_prealloc(int fd, char *area, size_t sz, Error
**errp);
int qemu_read_password(char *buf, int buf_size);
/**
+ * qemu_get_pid_name:
+ * @pid: pid of a process
+ *
+ * For given @pid fetch its name. Caller is responsible for
+ * freeing the string when no longer needed.
+ * Returns allocated string on success, NULL on failure.
+ */
+char *qemu_get_pid_name(pid_t pid);
+
+/**
* qemu_fork:
*
* A version of fork that avoids signal handler race
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index f2d4e9e..8c1e8d6 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -46,6 +46,7 @@
#ifdef __FreeBSD__
#include <sys/sysctl.h>
+#include <libutil.h>
#endif
#include "qemu/mmap-alloc.h"
@@ -430,6 +431,32 @@ int qemu_read_password(char *buf, int buf_size)
}
+char *qemu_get_pid_name(pid_t pid)
+{
+ char *name = NULL;
+
+#if defined(__FreeBSD__)
+ /* BSDs don't have /proc, but they provide a nice substitute */
+ struct kinfo_proc *proc = kinfo_getproc(pid);
+
+ if (proc) {
+ name = g_strdup(proc->ki_comm);
+ free(proc);
+ }
+#else
+ /* Assume a system with reasonable procfs */
+ char *pid_path;
+ size_t len;
+
+ pid_path = g_strdup_printf("/proc/%d/cmdline", pid);
+ g_file_get_contents(pid_path, &name, &len, NULL);
+ g_free(pid_path);
+#endif
+
+ return name;
+}
+
+
pid_t qemu_fork(Error **errp)
{
sigset_t oldmask, newmask;
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 4c1dcf1..d09863c 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -575,6 +575,13 @@ int qemu_read_password(char *buf, int buf_size)
}
+char *qemu_get_pid_name(pid_t pid)
+{
+ /* XXX Implement me */
+ abort();
+}
+
+
pid_t qemu_fork(Error **errp)
{
errno = ENOSYS;
--
2.7.4
- [Qemu-devel] [PULL 15/39] qom/cpu: atomically clear the tb_jmp_cache, (continued)
- [Qemu-devel] [PULL 15/39] qom/cpu: atomically clear the tb_jmp_cache, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 16/39] cpu: atomically modify cpu->exit_request, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 17/39] util/qht: atomically set b->hashes, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 18/39] linux-user/syscall: extend lock around cpu-list, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 19/39] qga/command: use QEMU atomic primitives, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 20/39] .travis.yml: add gcc sanitizer build, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 22/39] char: use a fixed idx for child muxed chr, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 21/39] i8259: give ISA device when registering ISA ioports, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 23/39] char: update read handler in all cases, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 25/39] qemu_kill_report: Report PID name too, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 24/39] util: Introduce qemu_get_pid_name,
Paolo Bonzini <=
- [Qemu-devel] [PULL 26/39] qemu-nbd: Shrink image size by specified offset, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 27/39] qht: simplify qht_reset_size, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 28/39] qht: fix unlock-after-free segfault upon resizing, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 30/39] qemu-tech: drop index, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 29/39] test-qht: perform lookups under rcu_read_lock, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 31/39] qemu-doc: replace introduction with the one from the internals manual, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 33/39] qemu-tech: move text from qemu-tech to tcg/README, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 32/39] qemu-doc: drop installation and compilation notes, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 36/39] qemu-tech: move TCG test documentation to tests/tcg/README, Paolo Bonzini, 2016/10/07
- [Qemu-devel] [PULL 34/39] qemu-tech: document lazy condition code evaluation in cpu.h, Paolo Bonzini, 2016/10/07