From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: [PATCH v4 04/29] tools/libxl: Introduce libxl__kill() Date: Tue, 14 Jul 2015 11:59:19 +0100 Message-ID: <1436871584-6522-5-git-send-email-andrew.cooper3@citrix.com> References: <1436871584-6522-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1436871584-6522-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Andrew Cooper , Ian Jackson List-Id: xen-devel@lists.xenproject.org as a wrapper to kill(2), and use it in preference to sendsig in libxl_save_callout.c. Signed-off-by: Andrew Cooper Acked-by: Wei Liu Acked-by: Ian Campbell CC: Ian Jackson --- v3: Fix typo, add _hidden Logically new in v2 - split out from a v1 change which was itself a cherrypick-and-modify from the AO Abort series --- tools/libxl/libxl_aoutils.c | 15 +++++++++++++++ tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_save_callout.c | 10 ++-------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c index 0931eee..274ef39 100644 --- a/tools/libxl/libxl_aoutils.c +++ b/tools/libxl/libxl_aoutils.c @@ -621,3 +621,18 @@ bool libxl__async_exec_inuse(const libxl__async_exec_state *aes) assert(time_inuse == child_inuse); return child_inuse; } + +void libxl__kill(libxl__gc *gc, pid_t pid, int sig, const char *what) +{ + int r = kill(pid, sig); + if (r) LOGE(WARN, "failed to kill() %s [%lu] (signal %d)", + what, (unsigned long)pid, sig); +} + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 19fc425..7ccbf55 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2244,6 +2244,8 @@ struct libxl__async_exec_state { int libxl__async_exec_start(libxl__async_exec_state *aes); bool libxl__async_exec_inuse(const libxl__async_exec_state *aes); +_hidden void libxl__kill(libxl__gc *gc, pid_t pid, int sig, const char *what); + /*----- device addition/removal -----*/ typedef struct libxl__ao_device libxl__ao_device; diff --git a/tools/libxl/libxl_save_callout.c b/tools/libxl/libxl_save_callout.c index 087c2d5..b82a5c1 100644 --- a/tools/libxl/libxl_save_callout.c +++ b/tools/libxl/libxl_save_callout.c @@ -244,12 +244,6 @@ static void run_helper(libxl__egc *egc, libxl__save_helper_state *shs, libxl__carefd_close(childs_pipes[1]); helper_failed(egc, shs, rc);; } -static void sendsig(libxl__gc *gc, libxl__save_helper_state *shs, int sig) -{ - int r = kill(shs->child.pid, sig); - if (r) LOGE(WARN, "failed to kill save/restore helper [%lu] (signal %d)", - (unsigned long)shs->child.pid, sig); -} static void helper_failed(libxl__egc *egc, libxl__save_helper_state *shs, int rc) @@ -266,7 +260,7 @@ static void helper_failed(libxl__egc *egc, libxl__save_helper_state *shs, return; } - sendsig(gc, shs, SIGKILL); + libxl__kill(gc, shs->child.pid, SIGKILL, "save/restore helper"); } static void helper_stop(libxl__egc *egc, libxl__ao_abortable *abrt, int rc) @@ -282,7 +276,7 @@ static void helper_stop(libxl__egc *egc, libxl__ao_abortable *abrt, int rc) if (!shs->rc) shs->rc = rc; - sendsig(gc, shs, SIGTERM); + libxl__kill(gc, shs->child.pid, SIGTERM, "save/restore helper"); } static void helper_stdout_readable(libxl__egc *egc, libxl__ev_fd *ev, -- 1.7.10.4