On 03/18/2011 12:54 PM, Daniel P. Berrange wrote:
Introduces a simple wrapper around the raw POSIX sockets APIs
and name resolution APIs. Allows for easy creation of client
and server sockets with correct usage of name resolution APIs
for protocol agnostic socket setup.
+int virNetSocketNewConnectCommand(virCommandPtr cmd,
+ virNetSocketPtr *retsock)
+{
+
+ if (virCommandRunAsync(cmd, &pid) < 0)
+ goto error;
+
+ /* Parent continues here. */
+ VIR_FORCE_CLOSE(sv[1]);
+ VIR_FORCE_CLOSE(errfd[1]);
+
+ if (!(*retsock = virNetSocketNew(NULL, NULL, true, sv[0], errfd[0], pid)))
+ goto error;
+
+ virCommandFree(cmd);
+
+ return 0;
+
+error:
+ VIR_FORCE_CLOSE(sv[0]);
+ VIR_FORCE_CLOSE(sv[1]);
+ VIR_FORCE_CLOSE(errfd[0]);
+ VIR_FORCE_CLOSE(errfd[1]);
+
+ if (pid > 0) {
+ kill(pid, SIGTERM);
+ if (virCommandWait(cmd, NULL) < 0) {
+ kill(pid, SIGKILL);
+ if (virCommandWait(cmd, NULL) < 0) {
+ VIR_WARN("Unable to wait for command %d", pid);
+ }
+ }
+ }
+
+ virCommandFree(cmd);
This looks like a perfect candidate to use my proposed
virCommandAbort():
https://www.redhat.com/archives/libvir-list/2011-March/msg01045.html
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org