summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/oslib-posix.c27
-rw-r--r--util/oslib-win32.c7
2 files changed, 34 insertions, 0 deletions
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index f2d4e9e592..8c1e8d6841 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 4c1dcf1e66..d09863cc9d 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;