* [PATCH] tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1
@ 2014-08-18 13:02 Andrew Cooper
2014-08-18 13:10 ` Alex Bligh
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Andrew Cooper @ 2014-08-18 13:02 UTC (permalink / raw)
To: Xen-devel; +Cc: Andrew Cooper, Ian Jackson, Ian Campbell, Alex Bligh
Otherwise, if it is not used, libxl_ctx_free() will close fd 0.
Reported-by: Alex Bligh <alex@alex.org.uk>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
tools/libxl/libxl.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 3526539..a1e0b5e 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -71,6 +71,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
ctx->childproc_user = 0;
ctx->sigchld_selfpipe[0] = -1;
+ ctx->sigchld_selfpipe[1] = -1;
libxl__ev_fd_init(&ctx->sigchld_selfpipe_efd);
/* The mutex is special because we can't idempotently destroy it */
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1
2014-08-18 13:02 [PATCH] tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1 Andrew Cooper
@ 2014-08-18 13:10 ` Alex Bligh
2014-08-18 13:19 ` Andrew Cooper
2014-08-26 23:34 ` Andrew Cooper
2014-08-27 1:55 ` Ian Campbell
2 siblings, 1 reply; 6+ messages in thread
From: Alex Bligh @ 2014-08-18 13:10 UTC (permalink / raw)
To: Andrew Cooper; +Cc: Xen Devel
On 18/08/2014 14:02, Andrew Cooper wrote:
> Otherwise, if it is not used, libxl_ctx_free() will close fd 0.
Is there some way to work around this on the caller side
without a library change? Perhaps something that forces
sigchld_selfpipe to be opened?
Alex
> Reported-by: Alex Bligh <alex@alex.org.uk>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
> ---
> tools/libxl/libxl.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
> index 3526539..a1e0b5e 100644
> --- a/tools/libxl/libxl.c
> +++ b/tools/libxl/libxl.c
> @@ -71,6 +71,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
> ctx->childproc_user = 0;
>
> ctx->sigchld_selfpipe[0] = -1;
> + ctx->sigchld_selfpipe[1] = -1;
> libxl__ev_fd_init(&ctx->sigchld_selfpipe_efd);
>
> /* The mutex is special because we can't idempotently destroy it */
>
--
Alex Bligh
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1
2014-08-18 13:10 ` Alex Bligh
@ 2014-08-18 13:19 ` Andrew Cooper
2014-08-18 14:18 ` Alex Bligh
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Cooper @ 2014-08-18 13:19 UTC (permalink / raw)
To: Alex Bligh; +Cc: Xen Devel
On 18/08/14 14:10, Alex Bligh wrote:
> On 18/08/2014 14:02, Andrew Cooper wrote:
>> Otherwise, if it is not used, libxl_ctx_free() will close fd 0.
> Is there some way to work around this on the caller side
> without a library change? Perhaps something that forces
> sigchld_selfpipe to be opened?
>
> Alex
It looks like a call to libxl_childproc_setmode() will properly set up
both halves of ctx->sigchld_selfpipe[]
The call is to do with setting up the ownership of SIGCHILD in the
process, and a call to libxl_childproc_setmode(ctx, NULL, 0) should be
fine if you dont plan to fork in your own code.
~Andrew
>
>
>> Reported-by: Alex Bligh <alex@alex.org.uk>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>> CC: Ian Campbell <Ian.Campbell@citrix.com>
>> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
>> ---
>> tools/libxl/libxl.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
>> index 3526539..a1e0b5e 100644
>> --- a/tools/libxl/libxl.c
>> +++ b/tools/libxl/libxl.c
>> @@ -71,6 +71,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
>> ctx->childproc_user = 0;
>>
>> ctx->sigchld_selfpipe[0] = -1;
>> + ctx->sigchld_selfpipe[1] = -1;
>> libxl__ev_fd_init(&ctx->sigchld_selfpipe_efd);
>>
>> /* The mutex is special because we can't idempotently destroy it */
>>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1
2014-08-18 13:19 ` Andrew Cooper
@ 2014-08-18 14:18 ` Alex Bligh
0 siblings, 0 replies; 6+ messages in thread
From: Alex Bligh @ 2014-08-18 14:18 UTC (permalink / raw)
To: Andrew Cooper; +Cc: Xen Devel
On 18/08/2014 14:19, Andrew Cooper wrote:
> It looks like a call to libxl_childproc_setmode() will properly set up
> both halves of ctx->sigchld_selfpipe[]
>
> The call is to do with setting up the ownership of SIGCHILD in the
> process, and a call to libxl_childproc_setmode(ctx, NULL, 0) should be
> fine if you dont plan to fork in your own code.
That does not appear to make any difference.
As far as I can see I need to ensure libxl__sigchld_needed gets called,
which means I need to ensure perhaps_sigchld_needed gets called
and chldmode_ours returns true. As 'creating' is false, in
libxl_sigchld_owner_libxl mode, I appear to need a child for
this to work. I can set it to libxl_sigchld_owner_libxl_always
or libxl_sigchld_owner_libxl_always_selective_reap and then
set it back. The code below is the minimum I can find that gets it
to work:
#include <stdio.h>
#include <stdlib.h>
#include <libxl.h>
#define LIBXL_API_VERSION 0x040200
/* compile with:
* gcc -g -O0 xentest.c -o xentest -lxenlight
*/
void
fixctx (libxl_ctx *ctx)
{
const libxl_childproc_hooks libxl_child_hooks = {
.chldowner = libxl_sigchld_owner_libxl_always
};
libxl_childproc_setmode (ctx, &libxl_child_hooks, 0);
libxl_childproc_setmode (ctx, NULL, 0);
}
void
test ()
{
libxl_ctx *ctx = NULL;
if (libxl_ctx_alloc (&ctx, LIBXL_VERSION, XTL_NONE, NULL))
{
fprintf (stderr, "libxl_ctx_alloc failed");
exit (1);
}
fixctx (ctx);
libxl_ctx_free (ctx);
}
int
main (int argc, char **argv)
{
printf ("Before:\n");
system ("ls -la /proc/self/fd");
test ();
printf ("\nAfter:\n");
system ("ls -la /proc/self/fd");
exit (0);
}
--
Alex Bligh
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1
2014-08-18 13:02 [PATCH] tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1 Andrew Cooper
2014-08-18 13:10 ` Alex Bligh
@ 2014-08-26 23:34 ` Andrew Cooper
2014-08-27 1:55 ` Ian Campbell
2 siblings, 0 replies; 6+ messages in thread
From: Andrew Cooper @ 2014-08-26 23:34 UTC (permalink / raw)
To: Xen-devel; +Cc: Ian Jackson, Ian Campbell
On 18/08/2014 14:02, Andrew Cooper wrote:
> Otherwise, if it is not used, libxl_ctx_free() will close fd 0.
>
> Reported-by: Alex Bligh <alex@alex.org.uk>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
> ---
Ping? This is a rather nasty bug which needs fixing in 4.4 as well.
> tools/libxl/libxl.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
> index 3526539..a1e0b5e 100644
> --- a/tools/libxl/libxl.c
> +++ b/tools/libxl/libxl.c
> @@ -71,6 +71,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
> ctx->childproc_user = 0;
>
> ctx->sigchld_selfpipe[0] = -1;
> + ctx->sigchld_selfpipe[1] = -1;
> libxl__ev_fd_init(&ctx->sigchld_selfpipe_efd);
>
> /* The mutex is special because we can't idempotently destroy it */
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1
2014-08-18 13:02 [PATCH] tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1 Andrew Cooper
2014-08-18 13:10 ` Alex Bligh
2014-08-26 23:34 ` Andrew Cooper
@ 2014-08-27 1:55 ` Ian Campbell
2 siblings, 0 replies; 6+ messages in thread
From: Ian Campbell @ 2014-08-27 1:55 UTC (permalink / raw)
To: Andrew Cooper; +Cc: Ian Jackson, Alex Bligh, Xen-devel
On Mon, 2014-08-18 at 14:02 +0100, Andrew Cooper wrote:
> Otherwise, if it is not used, libxl_ctx_free() will close fd 0.
>
> Reported-by: Alex Bligh <alex@alex.org.uk>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked + applied, thanks.
Ian.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-08-27 1:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-18 13:02 [PATCH] tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1 Andrew Cooper
2014-08-18 13:10 ` Alex Bligh
2014-08-18 13:19 ` Andrew Cooper
2014-08-18 14:18 ` Alex Bligh
2014-08-26 23:34 ` Andrew Cooper
2014-08-27 1:55 ` Ian Campbell
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).