From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yang Hongyang Subject: Re: [PATCH v2 04/27] tools/libxl: Introduce libxl__kill() Date: Fri, 10 Jul 2015 09:34:48 +0800 Message-ID: <559F2138.6040401@cn.fujitsu.com> References: <1436466413-25867-1-git-send-email-andrew.cooper3@citrix.com> <1436466413-25867-5-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1436466413-25867-5-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: Andrew Cooper , Xen-devel Cc: Wei Liu , Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org On 07/10/2015 02:26 AM, Andrew Cooper wrote: > as a wrapper to kill(2), and use it in preference to sendig in s/sendig/sendsig/ > libxl_save_callout.c. > > Signed-off-by: Andrew Cooper > CC: Ian Campbell > CC: Ian Jackson > CC: Wei Liu > > --- > 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..9147de1 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); > > +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, > -- Thanks, Yang.