Skip to contentSkip to conversation

Produce better termination message

PATCH Applied Michal Privoznik 3 participants 5 messages Sep 27, 2016 – Sep 30, 2016

lore
Share & tools
lore
#0 lore raw

v4 cover Produce better termination message

v3 of:
http://lists.nongnu.org/archive/html/qemu-devel/2016-09/msg05058.html

diff to v3:
- Rework 2/2 so that no malloc() is done in signal handler since it's not re-entrant.

Michal Privoznik (2):
util: Introduce qemu_get_pid_name
qemu_kill_report: Report PID name too

 include/qemu/osdep.h | 10 ++++++++++
 util/oslib-posix.c   | 27 +++++++++++++++++++++++++++
 util/oslib-win32.c   |  7 +++++++
 vl.c                 |  8 ++++++--
 4 files changed, 50 insertions(+), 2 deletions(-)
Signature · 1 line
2.8.4
#2 lore raw

PATCH v4 2/2 qemu_kill_report: Report PID name too

When qemu is being killed, its last words are:

2016-08-31T11:48:15.293587Z qemu-system-x86_64: terminating on signal 15 from pid 11180

That's nice, but what process is 11180? What if I told you we can do better:

2016-08-31T11:48:15.293587Z qemu-system-x86_64: terminating on signal 15 from pid 11180 (/usr/sbin/libvirtd)

And that's exactly what this patch does.

---
 vl.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
vl.c +6 -2
index 215a6f9..62a100e 100644
@@ -1674,8 +1674,12 @@ static void qemu_kill_report(void)
              */
             error_report("terminating on signal %d", shutdown_signal);
         } else {
-            error_report("terminating on signal %d from pid " FMT_pid,
-                         shutdown_signal, shutdown_pid);
+            char *shutdown_cmd = qemu_get_pid_name(shutdown_pid);
+
+            error_report("terminating on signal %d from pid " FMT_pid " (%s)",
+                         shutdown_signal, shutdown_pid,
+                         shutdown_cmd ? shutdown_cmd : "<unknown process>");
+            g_free(shutdown_cmd);
         }
         shutdown_signal = -1;
     }
Signature · 1 line
2.8.4
#1 lore raw

PATCH v4 1/2 util: Introduce qemu_get_pid_name

In reply to Michal Privoznik

This is a small helper that tries to fetch binary name for given PID.

---
 include/qemu/osdep.h | 10 ++++++++++
 util/oslib-posix.c   | 27 +++++++++++++++++++++++++++
 util/oslib-win32.c   |  7 +++++++
 3 files changed, 44 insertions(+)
include/qemu/osdep.h +10 -0
index 9e9fa61..384bfe2 100644
@@ -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
util/oslib-posix.c +27 -0
index f2d4e9e..8c1e8d6 100644
@@ -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;
util/oslib-win32.c +7 -0
index 4c1dcf1..d09863c 100644
@@ -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;
Signature · 1 line
2.8.4
#3 lore raw
In reply to Michal Privoznik
Your series seems to have some coding style problems. See output below for more information:

Hi,

Your series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v4 0/2] Produce better termination message

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git show --no-patch --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
945e773 qemu_kill_report: Report PID name too
9e243c4 util: Introduce qemu_get_pid_name

=== OUTPUT BEGIN ===
Checking PATCH 1/2: util: Introduce qemu_get_pid_name...
ERROR: architecture specific defines should be avoided #53: FILE: util/oslib-posix.c:438:
+#if defined(__FreeBSD__)

total: 1 errors, 0 warnings, 68 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 2/2: qemu_kill_report: Report PID name too... === OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#4 lore raw
In reply to Michal Privoznik
Quoted 10 lines · Michal Privoznik

v3 of:
http://lists.nongnu.org/archive/html/qemu-devel/2016-09/msg05058.html

diff to v3:
- Rework 2/2 so that no malloc() is done in signal handler since it's not re-entrant.

Michal Privoznik (2):
util: Introduce qemu_get_pid_name
qemu_kill_report: Report PID name too

Quoted 6 lines
 include/qemu/osdep.h | 10 ++++++++++
 util/oslib-posix.c   | 27 +++++++++++++++++++++++++++
 util/oslib-win32.c   |  7 +++++++
 vl.c                 |  8 ++++++--
 4 files changed, 50 insertions(+), 2 deletions(-)

Queued, thanks.