On Tue, Apr 28, 2009 at 11:31:53AM -0400, Cole Robinson wrote:
Wraps __virExec with the VIR_EXEC_DAEMON flag. Waits on the
intermediate
process to ensure we don't end up with any zombies, and differentiates between
original process errors and intermediate process errors.
+int virExecDaemonize(virConnectPtr conn,
+ const char *const*argv,
+ const char *const*envp,
+ const fd_set *keepfd,
+ pid_t *retpid,
+ int infd, int *outfd, int *errfd,
+ int flags,
+ virExecHook hook,
+ void *data) {
+ int ret;
+ int childstat = 0;
+
+ ret = virExecWithHook(conn, argv, envp, keepfd, retpid,
+ infd, outfd, errfd,
+ flags |= VIR_EXEC_DAEMON,
+ hook, data);
+
+ /* Wait for intermediate process to exit */
+ while (waitpid(*retpid, &childstat, 0) == -1 &&
+ errno == EINTR);
I think we should only call waitpid() if 'ret == 0', because if ret is
not 0, *retpid won't have been set and will thus contain random garbage.
+
+ /* __virExec should have set an error */
+ if (ret != 0)
+ return -1;
+
+ if (childstat != 0) {
+ ReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ _("Intermediate daemon process exited with status %d."),
+ WEXITSTATUS(childstat));
+ ret = -2;
+ }
+
+ return ret;
+}
+
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|