mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 02:51:16 +00:00
Allow stdin to be specified with virExec()
This commit is contained in:
parent
4f34d57223
commit
af7378db35
@ -1,3 +1,10 @@
|
||||
Mon Aug 13 21:18:48 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
||||
|
||||
* src/util.h, src/util.c: Allow a file descriptor to be supplied
|
||||
for STDIN when calling virExec(), or if -1, redirect from /dev/null
|
||||
* src/qemu_driver.c, src/openvz_driver.c: Pass in -1 for new stdin
|
||||
parameter above where neccessary
|
||||
|
||||
Mon Aug 13 20:13:48 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
||||
|
||||
* src/qemu_driver.c: Use \r instead of \n for monitor commands to
|
||||
|
@ -342,7 +342,7 @@ static int openvzListDomains(virConnectPtr conn, int *ids, int nids) {
|
||||
char buf[32];
|
||||
const char *cmd[] = {VZLIST, "-ovpsid", "-H" , NULL};
|
||||
|
||||
ret = virExec(conn, (char **)cmd, &pid, &outfd, &errfd);
|
||||
ret = virExec(conn, (char **)cmd, &pid, -1, &outfd, &errfd);
|
||||
if(ret == -1) {
|
||||
error(conn, VIR_ERR_INTERNAL_ERROR, "Could not exec " VZLIST);
|
||||
return (int)NULL;
|
||||
@ -373,7 +373,7 @@ static int openvzListDefinedDomains(virConnectPtr conn,
|
||||
const char *cmd[] = {VZLIST, "-ovpsid", "-H", NULL};
|
||||
|
||||
/* the -S options lists only stopped domains */
|
||||
ret = virExec(conn, (char **)cmd, &pid, &outfd, &errfd);
|
||||
ret = virExec(conn, (char **)cmd, &pid, -1, &outfd, &errfd);
|
||||
if(ret == -1) {
|
||||
error(conn, VIR_ERR_INTERNAL_ERROR, "Could not exec " VZLIST);
|
||||
return (int)NULL;
|
||||
|
@ -655,7 +655,8 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
||||
qemudLog(QEMUD_WARN, "Unable to write argv to logfile %d: %s",
|
||||
errno, strerror(errno));
|
||||
|
||||
if (virExecNonBlock(conn, argv, &vm->pid, &vm->stdout, &vm->stderr) == 0) {
|
||||
if (virExecNonBlock(conn, argv, &vm->pid,
|
||||
-1, &vm->stdout, &vm->stderr) == 0) {
|
||||
vm->id = driver->nextvmid++;
|
||||
vm->state = VIR_DOMAIN_RUNNING;
|
||||
|
||||
@ -912,7 +913,7 @@ dhcpStartDhcpDaemon(virConnectPtr conn,
|
||||
if (qemudBuildDnsmasqArgv(conn, network, &argv) < 0)
|
||||
return -1;
|
||||
|
||||
ret = virExecNonBlock(conn, argv, &network->dnsmasqPid, NULL, NULL);
|
||||
ret = virExecNonBlock(conn, argv, &network->dnsmasqPid, -1, NULL, NULL);
|
||||
|
||||
for (i = 0; argv[i]; i++)
|
||||
free(argv[i]);
|
||||
|
12
src/util.c
12
src/util.c
@ -79,7 +79,7 @@ static int virSetNonBlock(int fd) {
|
||||
static int
|
||||
_virExec(virConnectPtr conn,
|
||||
char **argv,
|
||||
int *retpid, int *outfd, int *errfd, int non_block) {
|
||||
int *retpid, int infd, int *outfd, int *errfd, int non_block) {
|
||||
int pid, null;
|
||||
int pipeout[2] = {-1,-1};
|
||||
int pipeerr[2] = {-1,-1};
|
||||
@ -140,7 +140,7 @@ _virExec(virConnectPtr conn,
|
||||
if (pipeerr[0] > 0 && close(pipeerr[0]) < 0)
|
||||
_exit(1);
|
||||
|
||||
if (dup2(null, STDIN_FILENO) < 0)
|
||||
if (dup2(infd >= 0 ? infd : null, STDIN_FILENO) < 0)
|
||||
_exit(1);
|
||||
if (dup2(pipeout[1] > 0 ? pipeout[1] : null, STDOUT_FILENO) < 0)
|
||||
_exit(1);
|
||||
@ -176,16 +176,16 @@ _virExec(virConnectPtr conn,
|
||||
int
|
||||
virExec(virConnectPtr conn,
|
||||
char **argv,
|
||||
int *retpid, int *outfd, int *errfd) {
|
||||
int *retpid, int infd, int *outfd, int *errfd) {
|
||||
|
||||
return(_virExec(conn, argv, retpid, outfd, errfd, 0));
|
||||
return(_virExec(conn, argv, retpid, infd, outfd, errfd, 0));
|
||||
}
|
||||
|
||||
int
|
||||
virExecNonBlock(virConnectPtr conn,
|
||||
char **argv,
|
||||
int *retpid, int *outfd, int *errfd) {
|
||||
int *retpid, int infd, int *outfd, int *errfd) {
|
||||
|
||||
return(_virExec(conn, argv, retpid, outfd, errfd, 1));
|
||||
return(_virExec(conn, argv, retpid, infd, outfd, errfd, 1));
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,6 @@
|
||||
* File created Jul 18, 2007 - Shuveb Hussain <shuveb@binarykarma.com>
|
||||
*/
|
||||
|
||||
int virExec(virConnectPtr conn, char **argv, int *retpid, int *outfd, int *errfd);
|
||||
int virExecNonBlock(virConnectPtr conn, char **argv, int *retpid, int *outfd, int *errfd);
|
||||
int virExec(virConnectPtr conn, char **argv, int *retpid, int infd, int *outfd, int *errfd);
|
||||
int virExecNonBlock(virConnectPtr conn, char **argv, int *retpid, int infd, int *outfd, int *errfd);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user