git.annexia.org
/
libguestfs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
todo docs: Discuss shrinking filesystems and specifying sizes in guestfish.
[libguestfs.git]
/
src
/
guestfs.c
diff --git
a/src/guestfs.c
b/src/guestfs.c
index
3910895
..
fe08cb5
100644
(file)
--- a/
src/guestfs.c
+++ b/
src/guestfs.c
@@
-1257,10
+1257,12
@@
guestfs__launch (guestfs_h *g)
"%s " /* (selinux) */
"%s " /* (vmchannel) */
"%s " /* (verbose) */
"%s " /* (selinux) */
"%s " /* (vmchannel) */
"%s " /* (verbose) */
+ "TERM=%s " /* (TERM environment variable) */
"%s", /* (append) */
g->selinux ? "selinux=1 enforcing=0" : "selinux=0",
vmchannel ? vmchannel : "",
g->verbose ? "guestfs_verbose=1" : "",
"%s", /* (append) */
g->selinux ? "selinux=1 enforcing=0" : "selinux=0",
vmchannel ? vmchannel : "",
g->verbose ? "guestfs_verbose=1" : "",
+ getenv ("TERM") ? : "linux",
g->append ? g->append : "");
add_cmdline (g, "-kernel");
g->append ? g->append : "");
add_cmdline (g, "-kernel");
@@
-1287,7
+1289,7
@@
guestfs__launch (guestfs_h *g)
if (dup (wfd[0]) == -1) {
dup_failed:
perror ("dup failed");
if (dup (wfd[0]) == -1) {
dup_failed:
perror ("dup failed");
- _exit (
1
);
+ _exit (
EXIT_FAILURE
);
}
if (dup (rfd[1]) == -1)
goto dup_failed;
}
if (dup (rfd[1]) == -1)
goto dup_failed;
@@
-1307,7
+1309,7
@@
guestfs__launch (guestfs_h *g)
execv (g->qemu, g->cmdline); /* Run qemu. */
perror (g->qemu);
execv (g->qemu, g->cmdline); /* Run qemu. */
perror (g->qemu);
- _exit (
1
);
+ _exit (
EXIT_FAILURE
);
}
/* Parent (library). */
}
/* Parent (library). */
@@
-1339,11
+1341,11
@@
guestfs__launch (guestfs_h *g)
*/
for (;;) {
if (kill (qemu_pid, 0) == -1) /* qemu's gone away, we aren't needed */
*/
for (;;) {
if (kill (qemu_pid, 0) == -1) /* qemu's gone away, we aren't needed */
- _exit (
0
);
+ _exit (
EXIT_SUCCESS
);
if (kill (parent_pid, 0) == -1) {
/* Parent's gone away, qemu still around, so kill qemu. */
kill (qemu_pid, 9);
if (kill (parent_pid, 0) == -1) {
/* Parent's gone away, qemu still around, so kill qemu. */
kill (qemu_pid, 9);
- _exit (
0
);
+ _exit (
EXIT_SUCCESS
);
}
sleep (2);
}
}
sleep (2);
}
@@
-1403,6
+1405,7
@@
guestfs__launch (guestfs_h *g)
"libguestfs: warning: unexpected connection from UID %d to port %d\n",
uid, null_vmchannel_sock);
close (sock);
"libguestfs: warning: unexpected connection from UID %d to port %d\n",
uid, null_vmchannel_sock);
close (sock);
+ sock = -1;
continue;
}
}
continue;
}
}
@@
-1497,7
+1500,7
@@
guestfs__launch (guestfs_h *g)
close (wfd[1]);
close (rfd[0]);
}
close (wfd[1]);
close (rfd[0]);
}
- kill (g->pid, 9);
+
if (g->pid > 0)
kill (g->pid, 9);
if (g->recoverypid > 0) kill (g->recoverypid, 9);
waitpid (g->pid, NULL, 0);
if (g->recoverypid > 0) waitpid (g->recoverypid, NULL, 0);
if (g->recoverypid > 0) kill (g->recoverypid, 9);
waitpid (g->pid, NULL, 0);
if (g->recoverypid > 0) waitpid (g->recoverypid, NULL, 0);
@@
-1845,7
+1848,7
@@
guestfs__kill_subprocess (guestfs_h *g)
if (g->verbose)
fprintf (stderr, "sending SIGTERM to process %d\n", g->pid);
if (g->verbose)
fprintf (stderr, "sending SIGTERM to process %d\n", g->pid);
- kill (g->pid, SIGTERM);
+
if (g->pid > 0)
kill (g->pid, SIGTERM);
if (g->recoverypid > 0) kill (g->recoverypid, 9);
return 0;
if (g->recoverypid > 0) kill (g->recoverypid, 9);
return 0;
@@
-1996,7
+1999,7
@@
child_cleanup (guestfs_h *g)
if (g->verbose)
fprintf (stderr, "child_cleanup: %p: child process died\n", g);
if (g->verbose)
fprintf (stderr, "child_cleanup: %p: child process died\n", g);
- /*kill (g->pid, SIGTERM);*/
+ /*
if (g->pid > 0)
kill (g->pid, SIGTERM);*/
if (g->recoverypid > 0) kill (g->recoverypid, 9);
waitpid (g->pid, NULL, 0);
if (g->recoverypid > 0) waitpid (g->recoverypid, NULL, 0);
if (g->recoverypid > 0) kill (g->recoverypid, 9);
waitpid (g->pid, NULL, 0);
if (g->recoverypid > 0) waitpid (g->recoverypid, NULL, 0);
@@
-2363,8
+2366,16
@@
accept_from_daemon (guestfs_h *g)
int sock = -1;
while (sock == -1) {
int sock = -1;
while (sock == -1) {
+ /* If the qemu process has died, clean up the zombie (RHBZ#579155).
+ * By partially polling in the select below we ensure that this
+ * function will be called eventually.
+ */
+ waitpid (g->pid, NULL, WNOHANG);
+
rset2 = rset;
rset2 = rset;
- int r = select (max_fd+1, &rset2, NULL, NULL, NULL);
+
+ struct timeval tv = { .tv_sec = 1, .tv_usec = 0 };
+ int r = select (max_fd+1, &rset2, NULL, NULL, &tv);
if (r == -1) {
if (errno == EINTR || errno == EAGAIN)
continue;
if (r == -1) {
if (errno == EINTR || errno == EAGAIN)
continue;