command: don't mix RunAsync and daemons

It doesn't make sense to run a daemon without synchronously
waiting for the child process to reply whether the daemon has
been kicked off and pidfile written yet.

* src/util/command.c (VIR_EXEC_RUN_SYNC): New constant.
(virCommandRun): Set temporary flag.
(virCommandRunAsync): Use it to prevent async runs of intermediate
child when spawning asynchronous daemon grandchild.
This commit is contained in:
Eric Blake 2011-03-23 17:42:27 -06:00
parent 208a044a54
commit 4e808602f1

View File

@ -41,6 +41,11 @@
virReportErrorHelper(NULL, VIR_FROM_NONE, code, __FILE__, \ virReportErrorHelper(NULL, VIR_FROM_NONE, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__) __FUNCTION__, __LINE__, __VA_ARGS__)
enum {
/* Internal-use extension beyond public VIR_EXEC_ flags */
VIR_EXEC_RUN_SYNC = 0x40000000,
};
struct _virCommand { struct _virCommand {
int has_error; /* ENOMEM on allocation failure, -1 for anything else. */ int has_error; /* ENOMEM on allocation failure, -1 for anything else. */
@ -1050,6 +1055,7 @@ virCommandRun(virCommandPtr cmd, int *exitstatus)
} }
} }
cmd->flags |= VIR_EXEC_RUN_SYNC;
if (virCommandRunAsync(cmd, NULL) < 0) { if (virCommandRunAsync(cmd, NULL) < 0) {
if (cmd->inbuf) { if (cmd->inbuf) {
int tmpfd = infd[0]; int tmpfd = infd[0];
@ -1139,6 +1145,7 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
int ret; int ret;
char *str; char *str;
int i; int i;
bool synchronous = false;
if (!cmd || cmd->has_error == ENOMEM) { if (!cmd || cmd->has_error == ENOMEM) {
virReportOOMError(); virReportOOMError();
@ -1150,6 +1157,9 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
return -1; return -1;
} }
synchronous = cmd->flags & VIR_EXEC_RUN_SYNC;
cmd->flags &= ~VIR_EXEC_RUN_SYNC;
/* Buffer management can only be requested via virCommandRun. */ /* Buffer management can only be requested via virCommandRun. */
if ((cmd->inbuf && cmd->infd == -1) || if ((cmd->inbuf && cmd->infd == -1) ||
(cmd->outbuf && cmd->outfdptr != &cmd->outfd) || (cmd->outbuf && cmd->outfdptr != &cmd->outfd) ||
@ -1166,6 +1176,11 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
return -1; return -1;
} }
if (!synchronous && (cmd->flags & VIR_EXEC_DAEMON)) {
virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
_("daemonized command cannot use virCommandRunAsync"));
return -1;
}
if (cmd->pwd && (cmd->flags & VIR_EXEC_DAEMON)) { if (cmd->pwd && (cmd->flags & VIR_EXEC_DAEMON)) {
virCommandError(VIR_ERR_INTERNAL_ERROR, virCommandError(VIR_ERR_INTERNAL_ERROR,
_("daemonized command cannot set working directory %s"), _("daemonized command cannot set working directory %s"),