提交 028c3088 编写于 作者: C Cole Robinson

remote: Convert SSH tunnel to virCommand

上级 b3ecd780
...@@ -426,8 +426,8 @@ doRemoteOpen (virConnectPtr conn, ...@@ -426,8 +426,8 @@ doRemoteOpen (virConnectPtr conn,
char *name = NULL, *command = NULL, *sockname = NULL, *netcat = NULL; char *name = NULL, *command = NULL, *sockname = NULL, *netcat = NULL;
char *port = NULL, *authtype = NULL, *username = NULL; char *port = NULL, *authtype = NULL, *username = NULL;
int no_verify = 0, no_tty = 0; int no_verify = 0, no_tty = 0;
char **cmd_argv = NULL;
char *pkipath = NULL; char *pkipath = NULL;
virCommandPtr cmd = NULL;
/* Return code from this function, and the private data. */ /* Return code from this function, and the private data. */
int retcode = VIR_DRV_OPEN_ERROR; int retcode = VIR_DRV_OPEN_ERROR;
...@@ -741,50 +741,26 @@ doRemoteOpen (virConnectPtr conn, ...@@ -741,50 +741,26 @@ doRemoteOpen (virConnectPtr conn,
} }
case trans_ssh: { case trans_ssh: {
int j, nr_args = 6; cmd = virCommandNew(command ? command : "ssh");
if (username) nr_args += 2; /* For -l username */
if (no_tty) nr_args += 5; /* For -T -o BatchMode=yes -e none */
if (port) nr_args += 2; /* For -p port */
command = command ? command : strdup ("ssh");
if (command == NULL)
goto out_of_memory;
/* Generate the final command argv[] array. /* Generate the final command argv[] array.
* ssh [-p $port] [-l $username] $hostname $netcat -U $sockname [NULL] */ * ssh [-p $port] [-l $username] $hostname $netcat -U $sockname */
if (VIR_ALLOC_N(cmd_argv, nr_args) < 0)
goto out_of_memory;
j = 0;
cmd_argv[j++] = strdup (command);
if (port) { if (port) {
cmd_argv[j++] = strdup ("-p"); virCommandAddArgList(cmd, "-p", port, NULL);
cmd_argv[j++] = strdup (port);
} }
if (username) { if (username) {
cmd_argv[j++] = strdup ("-l"); virCommandAddArgList(cmd, "-l", username, NULL);
cmd_argv[j++] = strdup (username);
} }
if (no_tty) { if (no_tty) {
cmd_argv[j++] = strdup ("-T"); virCommandAddArgList(cmd, "-T", "-o", "BatchMode=yes", "-e",
cmd_argv[j++] = strdup ("-o"); "none", NULL);
cmd_argv[j++] = strdup ("BatchMode=yes");
cmd_argv[j++] = strdup ("-e");
cmd_argv[j++] = strdup ("none");
} }
cmd_argv[j++] = strdup (priv->hostname); virCommandAddArgList(cmd, priv->hostname, netcat ? netcat : "nc",
cmd_argv[j++] = strdup (netcat ? netcat : "nc"); "-U", (sockname ? sockname :
cmd_argv[j++] = strdup ("-U"); (flags & VIR_CONNECT_RO
cmd_argv[j++] = strdup (sockname ? sockname : ? LIBVIRTD_PRIV_UNIX_SOCKET_RO
(flags & VIR_CONNECT_RO : LIBVIRTD_PRIV_UNIX_SOCKET)), NULL);
? LIBVIRTD_PRIV_UNIX_SOCKET_RO
: LIBVIRTD_PRIV_UNIX_SOCKET));
cmd_argv[j++] = 0;
assert (j == nr_args);
for (j = 0; j < (nr_args-1); j++)
if (cmd_argv[j] == NULL)
goto out_of_memory;
priv->is_secure = 1; priv->is_secure = 1;
} }
...@@ -811,9 +787,11 @@ doRemoteOpen (virConnectPtr conn, ...@@ -811,9 +787,11 @@ doRemoteOpen (virConnectPtr conn,
goto failed; goto failed;
} }
if (virExec((const char**)cmd_argv, NULL, NULL, virCommandSetInputFD(cmd, sv[1]);
&pid, sv[1], &(sv[1]), &(errfd[1]), virCommandSetOutputFD(cmd, &(sv[1]));
VIR_EXEC_CLEAR_CAPS) < 0) virCommandSetErrorFD(cmd, &(errfd[1]));
virCommandClearCaps(cmd);
if (virCommandRunAsync(cmd, &pid) < 0)
goto failed; goto failed;
/* Parent continues here. */ /* Parent continues here. */
...@@ -942,14 +920,7 @@ doRemoteOpen (virConnectPtr conn, ...@@ -942,14 +920,7 @@ doRemoteOpen (virConnectPtr conn,
VIR_FREE(netcat); VIR_FREE(netcat);
VIR_FREE(username); VIR_FREE(username);
VIR_FREE(port); VIR_FREE(port);
if (cmd_argv) { virCommandFree(cmd);
char **cmd_argv_ptr = cmd_argv;
while (*cmd_argv_ptr) {
VIR_FREE(*cmd_argv_ptr);
cmd_argv_ptr++;
}
VIR_FREE(cmd_argv);
}
VIR_FREE(pkipath); VIR_FREE(pkipath);
return retcode; return retcode;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部