qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4 0/2] Produce better termination message
@ 2016-09-27 15:24 Michal Privoznik
  2016-09-27 15:24 ` [Qemu-devel] [PATCH v4 1/2] util: Introduce qemu_get_pid_name Michal Privoznik
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Michal Privoznik @ 2016-09-27 15:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, eblake

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(-)

-- 
2.8.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH v4 1/2] util: Introduce qemu_get_pid_name
  2016-09-27 15:24 [Qemu-devel] [PATCH v4 0/2] Produce better termination message Michal Privoznik
@ 2016-09-27 15:24 ` Michal Privoznik
  2016-09-27 15:24 ` [Qemu-devel] [PATCH v4 2/2] qemu_kill_report: Report PID name too Michal Privoznik
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Michal Privoznik @ 2016-09-27 15:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, eblake

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 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.8.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH v4 2/2] qemu_kill_report: Report PID name too
  2016-09-27 15:24 [Qemu-devel] [PATCH v4 0/2] Produce better termination message Michal Privoznik
  2016-09-27 15:24 ` [Qemu-devel] [PATCH v4 1/2] util: Introduce qemu_get_pid_name Michal Privoznik
@ 2016-09-27 15:24 ` Michal Privoznik
  2016-09-27 15:59 ` [Qemu-devel] [PATCH v4 0/2] Produce better termination message no-reply
  2016-09-30 11:45 ` Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Michal Privoznik @ 2016-09-27 15:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, eblake

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.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 vl.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/vl.c b/vl.c
index 215a6f9..62a100e 100644
--- a/vl.c
+++ b/vl.c
@@ -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;
     }
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v4 0/2] Produce better termination message
  2016-09-27 15:24 [Qemu-devel] [PATCH v4 0/2] Produce better termination message Michal Privoznik
  2016-09-27 15:24 ` [Qemu-devel] [PATCH v4 1/2] util: Introduce qemu_get_pid_name Michal Privoznik
  2016-09-27 15:24 ` [Qemu-devel] [PATCH v4 2/2] qemu_kill_report: Report PID name too Michal Privoznik
@ 2016-09-27 15:59 ` no-reply
  2016-09-30 11:45 ` Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: no-reply @ 2016-09-27 15:59 UTC (permalink / raw)
  To: mprivozn; +Cc: famz, qemu-devel, pbonzini

Hi,

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

Type: series
Message-id: cover.1474987617.git.mprivozn@redhat.com
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/1474970326-10271-1-git-send-email-pl@kamp.de -> patchew/1474970326-10271-1-git-send-email-pl@kamp.de
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 patchew-devel@freelists.org

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v4 0/2] Produce better termination message
  2016-09-27 15:24 [Qemu-devel] [PATCH v4 0/2] Produce better termination message Michal Privoznik
                   ` (2 preceding siblings ...)
  2016-09-27 15:59 ` [Qemu-devel] [PATCH v4 0/2] Produce better termination message no-reply
@ 2016-09-30 11:45 ` Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2016-09-30 11:45 UTC (permalink / raw)
  To: Michal Privoznik, qemu-devel



On 27/09/2016 17:24, Michal Privoznik wrote:
> 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(-)
> 

Queued, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-09-30 11:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-27 15:24 [Qemu-devel] [PATCH v4 0/2] Produce better termination message Michal Privoznik
2016-09-27 15:24 ` [Qemu-devel] [PATCH v4 1/2] util: Introduce qemu_get_pid_name Michal Privoznik
2016-09-27 15:24 ` [Qemu-devel] [PATCH v4 2/2] qemu_kill_report: Report PID name too Michal Privoznik
2016-09-27 15:59 ` [Qemu-devel] [PATCH v4 0/2] Produce better termination message no-reply
2016-09-30 11:45 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).