mirror of https://gitee.com/openkylin/libvirt.git
add cd and pwd commands to virsh
* src/virsh.c: adds cd and pwd commands to virsh useful for save and restore commands * docs/virsh.pod virsh.1: update the documentation * AUTHORS: add Paolo Bonzini
This commit is contained in:
parent
08a2e796e8
commit
c4951f11b7
1
AUTHORS
1
AUTHORS
|
@ -77,6 +77,7 @@ Patches have also been contributed by:
|
|||
Amy Griffis <amy.griffis@hp.com>
|
||||
Henrik Persson E <henrik.e.persson@ericsson.com>
|
||||
Satoru SATOH <satoru.satoh@gmail.com>
|
||||
Paolo Bonzini <pbonzini@redhat.com>
|
||||
|
||||
[....send patches to get your name here....]
|
||||
|
||||
|
|
|
@ -82,6 +82,18 @@ Running hypervisor: Xen 3.0.0
|
|||
|
||||
=back
|
||||
|
||||
=item B<cd> I<directory> optional
|
||||
|
||||
Will change current directory to I<directory>. The default directory
|
||||
for the B<cd> command is the home directory or, if there is no I<HOME>
|
||||
variable in the environment, the root directory.
|
||||
|
||||
This command is only available in interactive mode.
|
||||
|
||||
=item B<pwd>
|
||||
|
||||
Will print the current directory.
|
||||
|
||||
=item B<connect> I<URI> optional I<--readonly>
|
||||
|
||||
(Re)-Connect to the hypervisor. This is a build-in command after shell
|
||||
|
|
79
src/virsh.c
79
src/virsh.c
|
@ -6046,6 +6046,83 @@ editReadBackFile (vshControl *ctl, const char *filename)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* "cd" command
|
||||
*/
|
||||
static const vshCmdInfo info_cd[] = {
|
||||
{"help", gettext_noop("change the current directory")},
|
||||
{"desc", gettext_noop("Change the current directory.")},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static const vshCmdOptDef opts_cd[] = {
|
||||
{"dir", VSH_OT_DATA, 0, gettext_noop("directory to switch to (default: home or else root)")},
|
||||
{NULL, 0, 0, NULL}
|
||||
};
|
||||
|
||||
static int
|
||||
cmdCd(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
||||
{
|
||||
const char *dir;
|
||||
int found;
|
||||
|
||||
if (!ctl->imode) {
|
||||
vshError(ctl, FALSE, _("cd: command valid only in interactive mode"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
dir = vshCommandOptString(cmd, "dir", &found);
|
||||
if (!found) {
|
||||
uid_t uid = geteuid();
|
||||
dir = virGetUserDirectory(NULL, uid);
|
||||
}
|
||||
if (!dir)
|
||||
dir = "/";
|
||||
|
||||
if (chdir (dir) == -1) {
|
||||
vshError(ctl, FALSE, _("cd: %s: %s"), strerror (errno), dir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* "pwd" command
|
||||
*/
|
||||
static const vshCmdInfo info_pwd[] = {
|
||||
{"help", gettext_noop("print the current directory")},
|
||||
{"desc", gettext_noop("Print the current directory.")},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static int
|
||||
cmdPwd(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char *cwd;
|
||||
size_t path_max;
|
||||
int err = TRUE;
|
||||
|
||||
path_max = (size_t) PATH_MAX + 2;
|
||||
cwd = vshMalloc (ctl, path_max);
|
||||
while (cwd) {
|
||||
err = getcwd (cwd, path_max) == NULL;
|
||||
if (!err || errno != ERANGE)
|
||||
break;
|
||||
|
||||
path_max *= 2;
|
||||
cwd = vshRealloc (ctl, cwd, path_max);
|
||||
}
|
||||
|
||||
if (err)
|
||||
vshError(ctl, FALSE, _("pwd: cannot get current directory: %s"), strerror (errno));
|
||||
else
|
||||
vshPrint (ctl, _("%s\n"), cwd);
|
||||
|
||||
free (cwd);
|
||||
return !err;
|
||||
}
|
||||
|
||||
/*
|
||||
* "edit" command
|
||||
*/
|
||||
|
@ -6209,6 +6286,7 @@ static const vshCmdDef commands[] = {
|
|||
{"attach-interface", cmdAttachInterface, opts_attach_interface, info_attach_interface},
|
||||
{"autostart", cmdAutostart, opts_autostart, info_autostart},
|
||||
{"capabilities", cmdCapabilities, NULL, info_capabilities},
|
||||
{"cd", cmdCd, opts_cd, info_cd},
|
||||
{"connect", cmdConnect, opts_connect, info_connect},
|
||||
{"console", cmdConsole, opts_console, info_console},
|
||||
{"create", cmdCreate, opts_create, info_create},
|
||||
|
@ -6277,6 +6355,7 @@ static const vshCmdDef commands[] = {
|
|||
{"pool-undefine", cmdPoolUndefine, opts_pool_undefine, info_pool_undefine},
|
||||
{"pool-uuid", cmdPoolUuid, opts_pool_uuid, info_pool_uuid},
|
||||
|
||||
{"pwd", cmdPwd, NULL, info_pwd},
|
||||
{"quit", cmdQuit, NULL, info_quit},
|
||||
{"reboot", cmdReboot, opts_reboot, info_reboot},
|
||||
{"restore", cmdRestore, opts_restore, info_restore},
|
||||
|
|
12
virsh.1
12
virsh.1
|
@ -132,7 +132,7 @@
|
|||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "VIRSH 1"
|
||||
.TH VIRSH 1 "2009-04-16" "libvirt-0.6.2" "Virtualization Support"
|
||||
.TH VIRSH 1 "2009-07-02" "libvirt-0.6.4" "Virtualization Support"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
|
@ -214,6 +214,16 @@ Running hypervisor: Xen 3.0.0
|
|||
.RE
|
||||
.RS 4
|
||||
.RE
|
||||
.IP "\fBcd\fR \fIdirectory\fR optional" 4
|
||||
.IX Item "cd directory optional"
|
||||
Will change current directory to \fIdirectory\fR. The default directory
|
||||
for the \fBcd\fR command is the home directory or, if there is no \fI\s-1HOME\s0\fR
|
||||
variable in the environment, the root directory.
|
||||
.Sp
|
||||
This command is only available in interactive mode.
|
||||
.IP "\fBpwd\fR" 4
|
||||
.IX Item "pwd"
|
||||
Will print the current directory.
|
||||
.IP "\fBconnect\fR \fI\s-1URI\s0\fR optional \fI\-\-readonly\fR" 4
|
||||
.IX Item "connect URI optional --readonly"
|
||||
(Re)\-Connect to the hypervisor. This is a build-in command after shell
|
||||
|
|
Loading…
Reference in New Issue