diff options
author | Ian Jackson <Ian.Jackson@eu.citrix.com> | 2012-05-29 10:31:37 +0100 |
---|---|---|
committer | Ian Jackson <Ian.Jackson@eu.citrix.com> | 2012-05-29 10:31:37 +0100 |
commit | 8d7aec41547d798761dcb308387f276667f9989a (patch) | |
tree | 34f19025dcc497e0d0fc6786edca8b6d78093f80 /tools/libxl/xl.h | |
parent | 017c08fa0da81e62c85ef5a018af2fe665acbbaf (diff) | |
download | xen-8d7aec41547d798761dcb308387f276667f9989a.tar.gz xen-8d7aec41547d798761dcb308387f276667f9989a.tar.bz2 xen-8d7aec41547d798761dcb308387f276667f9989a.zip |
xl: track child processes for the benefit of libxl
Each time xl forks, it needs to record the pid, so that its exit
status can be preserved if it happens that libxl's event loop reaped
it. Consequently we also have a new wrapper for waitpid, which in
that case returns the previously-reaped status.
When we get a console ready callback from libxl, check to see if we
have spawned but not reaped a previous console client, and if so reap
it now. (This is necessary to prevent improper use of the xlchild
struct, but has the happy consequence of checking the exit status of
the first console client in the pygrub case.)
Refactor the two calls to libxl_ctx_alloc into a new function
xl_ctx_alloc which also sets the child reaped handler callback.
All of this has the effect of suppressing a message
unknown child [nnnn] unexpected exited status zero
which would sometimes (depending on a race) appear with `xl create -c'
and pygrub.
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Reported-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Cc: Roger Pau Monne <roger.pau@citrix.com>
[ ijc -- corrected return codes in xl_reaped_callback to match documented
convention. ]
Committed-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools/libxl/xl.h')
-rw-r--r-- | tools/libxl/xl.h | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h index b7eacaa7e4..2af9428124 100644 --- a/tools/libxl/xl.h +++ b/tools/libxl/xl.h @@ -15,6 +15,8 @@ #ifndef XL_H #define XL_H +#include <assert.h> + #include "xentoollog.h" struct cmd_spec { @@ -108,8 +110,32 @@ struct cmd_spec *cmdtable_lookup(const char *s); extern libxl_ctx *ctx; extern xentoollog_logger_stdiostream *logger; -pid_t xl_fork(libxl_ctx *ctx); /* like fork, but prints and dies if it fails */ -void postfork(void); + +void xl_ctx_alloc(void); + +/* child processes */ + +typedef struct { + /* every struct like this must be in XLCHILD_LIST */ + pid_t pid; /* 0: not in use */ + int reaped; /* valid iff pid!=0 */ + int status; /* valid iff reaped */ +} xlchild; + +typedef enum { + child_console, child_waitdaemon, child_migration, + child_max +} xlchildnum; + +extern xlchild children[child_max]; + +pid_t xl_fork(xlchildnum); /* like fork, but prints and dies if it fails */ +void postfork(void); /* needed only if we aren't going to exec right away */ + +/* Handles EINTR. Clears out the xlchild so it can be reused. */ +pid_t xl_waitpid(xlchildnum, int *status, int flags); + +int xl_child_pid(xlchildnum); /* returns 0 if child struct is not in use */ /* global options */ extern int autoballoon; |