On Mon, Dec 15, 2008 at 02:22:42PM +0100, Daniel Veillard wrote: > On Mon, Dec 15, 2008 at 11:21:20AM +0000, Daniel P. Berrange wrote: > > On Fri, Dec 12, 2008 at 07:26:32PM +0100, Guido G?nther wrote: > > > + if (kill(vm->pid, SIGTERM) < 0) > > > + qemudLog(QEMUD_ERROR, _("Failed to send SIGTERM to %s (%d): %s\n"), > > > + vm->def->name, vm->pid, strerror(errno)); > > > > We should add a guard around all the kill() statements for > > > > if (vm->pid > 1) > > kill.. > > > > One of the bugs I found when doing the LXC/UML drivers is that when relying > > on an external PID file, some things can go wrong in unexpected ways that > > just don't happen when getting the PID straight back from fork. This often > > ended up with vm->pid being -1, 0 with horrific results - > > > > "If pid equals -1, then sig is sent to every process for which the calling > > process has permission to send signals, except for process 1 (init)" > > > > Yes, I killed every single process on my dev machine several times before > > discovering this isues :-) > > This call for an utility function > int virKillProcess(pid_t pid, int sig) > call checking for this, could also help on debugging/logging O.k. to apply the attached version of virKillProcess? I'm already using this in the libvirtd restart patches. -- Guido
>From 100ac54650daec21d9ff49b8997653495b80dab3 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Guido=20G=C3=BCnther?= <agx@xxxxxxxxxxx> Date: Mon, 22 Dec 2008 23:04:29 +0100 Subject: [PATCH] add virKillProcess --- src/libvirt_sym.version.in | 1 + src/util.c | 11 +++++++++++ src/util.h | 2 ++ 3 files changed, 14 insertions(+), 0 deletions(-) diff --git a/src/libvirt_sym.version.in b/src/libvirt_sym.version.in index 7d39480..97be5e4 100644 --- a/src/libvirt_sym.version.in +++ b/src/libvirt_sym.version.in @@ -599,6 +599,7 @@ LIBVIRT_PRIVATE_@VERSION@ { virAsprintf; virRun; virSkipSpaces; + virKillProcess; # uuid.h diff --git a/src/util.c b/src/util.c index f324bdf..dd18522 100644 --- a/src/util.c +++ b/src/util.c @@ -1337,3 +1337,14 @@ int virDiskNameToIndex(const char *name) { return idx; } + +/* send signal to a single process */ +int virKillProcess(pid_t pid, int sig) +{ + if (pid < 1) { + errno = ESRCH; + return -1; + } + + return kill(pid, sig); +} diff --git a/src/util.h b/src/util.h index 87ac908..f622bad 100644 --- a/src/util.h +++ b/src/util.h @@ -166,4 +166,6 @@ static inline int getuid (void) { return 0; } static inline int getgid (void) { return 0; } #endif +int virKillProcess(pid_t pid, int sig); + #endif /* __VIR_UTIL_H__ */ -- 1.6.0.3
-- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list