tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1
PATCH 1/1 tools/libxl: Initialise both parts of ctx->sigchld_selfpipe[] to -1
Otherwise, if it is not used, libxl_ctx_free() will close fd 0.
--- tools/libxl/libxl.c | 1 + 1 file changed, 1 insertion(+)
tools/libxl/libxl.c +1 -0
@@ -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 */
Signature · 1 line
1.7.10.4
Quoted 1 line · Andrew Cooper
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
Quoted 21 lines
Reported-by Alex Bligh <[email protected]>Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>--- tools/libxl/libxl.c | 1 + 1 file changed, 1 insertion(+)tools/libxl/libxl.c +1
-0@@ -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 */
Signature · 1 line
Alex Bligh
Quoted 7 lines · Alex Bligh
Quoted 1 line · Andrew Cooper
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_selfpipeto 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
Quoted 24 lines
Quoted 23 lines
Reported-by Alex Bligh <[email protected]>Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>--- tools/libxl/libxl.c | 1 + 1 file changed, 1 insertion(+)tools/libxl/libxl.c +1
-0@@ -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 */
Quoted 6 lines · Andrew Cooper
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);
}
Signature · 1 line
Alex Bligh
Quoted 7 lines · Andrew Cooper
Otherwise, if it is not used,
libxl_ctx_free()will close fd 0.Reported-by Alex Bligh <[email protected]>Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>---
Ping? This is a rather nasty bug which needs fixing in 4.4 as well.
Quoted 15 lines
tools/libxl/libxl.c | 1 + 1 file changed, 1 insertion(+)tools/libxl/libxl.c +1
-0@@ -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 */
Quoted 6 lines · Andrew Cooper
Otherwise, if it is not used,
libxl_ctx_free()will close fd 0.Reported-by Alex Bligh <[email protected]>Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>
Acked + applied, thanks.
Ian.