1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00
libvirt/tools/virsh.c

953 lines
26 KiB
C
Raw Normal View History

/*
* virsh.c: a shell to exercise the libvirt API
*
* Copyright (C) 2005, 2007-2015 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
* Daniel Veillard <veillard@redhat.com>
2005-12-08 17:22:52 +03:00
* Karel Zak <kzak@redhat.com>
2006-05-29 19:39:31 +04:00
* Daniel P. Berrange <berrange@redhat.com>
*/
#include <config.h>
#include "virsh.h"
#include <stdio.h>
2005-12-08 13:23:34 +03:00
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
2005-12-08 13:23:34 +03:00
#include <getopt.h>
2005-12-08 17:22:52 +03:00
#include <sys/time.h>
#include <fcntl.h>
#include <locale.h>
#include <time.h>
#include <limits.h>
#include <sys/stat.h>
#include <inttypes.h>
#include <signal.h>
2005-12-08 13:23:34 +03:00
#if WITH_READLINE
# include <readline/readline.h>
# include <readline/history.h>
#endif
2005-12-08 13:23:34 +03:00
#include "internal.h"
#include "virerror.h"
#include "virbuffer.h"
2012-12-12 22:06:53 +04:00
#include "viralloc.h"
#include <libvirt/libvirt-qemu.h>
#include <libvirt/libvirt-lxc.h>
#include "virfile.h"
maint: use gnulib configmake rather than open-coding things * bootstrap.conf (gnulib_modules): Add configmake. * daemon/Makefile.am (libvirtd_CFLAGS): Drop defines provided by gnulib. * src/Makefile.am (INCLUDES): Likewise. * tests/Makefile.am (INCLUDES): Likewise. * tools/Makefile.am (virsh_CFLAGS): Likewise. * daemon/libvirtd.c (qemudInitPaths, usage, main): Update clients. * src/cpu/cpu_map.c (CPUMAPFILE): Likewise. * src/driver.c (DEFAULT_DRIVER_DIR): Likewise. * src/internal.h (_): Likewise. * src/libvirt.c (virInitialize): Likewise. * src/lxc/lxc_conf.h (LXC_CONFIG_DIR, LXC_STATE_DIR, LXC_LOG_DIR): Likewise. * src/lxc/lxc_conf.c (lxcCapsInit, lxcLoadDriverConfig): Likewise. * src/network/bridge_driver.c (NETWORK_PID_DIR) (NETWORK_STATE_DIR, DNSMASQ_STATE_DIR, networkStartup): Likewise. * src/nwfilter/nwfilter_driver.c (nwfilterDriverStartup): Likewise. * src/qemu/qemu_conf.c (qemudLoadDriverConfig): Likewise. * src/qemu/qemu_driver.c (qemudStartup): Likewise. * src/remote/remote_driver.h (LIBVIRTD_PRIV_UNIX_SOCKET) (LIBVIRTD_PRIV_UNIX_SOCKET_RO, LIBVIRTD_CONFIGURATION_FILE) (LIBVIRT_PKI_DIR): Likewise. * src/secret/secret_driver.c (secretDriverStartup): Likewise. * src/security/security_apparmor.c (VIRT_AA_HELPER): Likewise. * src/security/virt-aa-helper.c (main): Likewise. * src/storage/storage_backend_disk.c (PARTHELPER): Likewise. * src/storage/storage_driver.c (storageDriverStartup): Likewise. * src/uml/uml_driver.c (TEMPDIR, umlStartup): Likewise. * src/util/hooks.c (LIBVIRT_HOOK_DIR): Likewise. * tools/virsh.c (main): Likewise. * docs/hooks.html.in: Likewise.
2010-11-16 17:54:17 +03:00
#include "configmake.h"
#include "virthread.h"
#include "vircommand.h"
#include "conf/domain_conf.h"
#include "virtypedparam.h"
#include "virstring.h"
2005-12-08 13:23:34 +03:00
#include "virsh-console.h"
#include "virsh-domain.h"
#include "virsh-domain-monitor.h"
#include "virsh-host.h"
#include "virsh-interface.h"
#include "virsh-network.h"
#include "virsh-nodedev.h"
#include "virsh-nwfilter.h"
#include "virsh-pool.h"
#include "virsh-secret.h"
#include "virsh-snapshot.h"
#include "virsh-volume.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO
# define SA_SIGINFO 0
#endif
2005-12-08 13:23:34 +03:00
static char *progname;
virsh: Categorize commands into groups for virsh help Change the virsh help out. The new output of "virsh help" and "virsh --help" will be like: Secret (help keyword 'secret'): secret-define define or modify a secret from an XML file secret-dumpxml secret attributes in XML secret-set-value set a secret value secret-get-value Output a secret value secret-undefine undefine a secret secret-list list secrets Snapshot (help keyword 'snapshot'): snapshot-create Create a snapshot snapshot-current Get the current snapshot snapshot-delete Delete a domain snapshot snapshot-dumpxml Dump XML for a domain snapshot snapshot-list List snapshots for a domain snapshot-revert Revert a domain to a snapshot Also support output help information of specified command group, e.g. % ./tools/virsh help "Network Filter" Network Filter (help keyword 'filter'): nwfilter-define define or update a network filter from an XML file nwfilter-undefine undefine a network filter nwfilter-dumpxml network filter information in XML nwfilter-list list network filters nwfilter-edit edit XML configuration for a network filter Each group has a help keyword, e.g. % ./tools/virsh help filter Network Filter (help keyword 'filter'): nwfilter-define define or update a network filter from an XML file nwfilter-undefine undefine a network filter nwfilter-dumpxml network filter information in XML nwfilter-list list network filters nwfilter-edit edit XML configuration for a network filter * tools/virsh.c: - introduce new struct "vshCmdGrp" and macros to define the groups. - split previous array "commands" into small arrays which are orgnized by group - changed some functions, e.g. "vshCmdDefSearch" - Added new functions, e.g. "vshCmdGrpSearch" - commands of each group are in "alphabetical order" now. - command groups are in "alphabetical order" now. - the commands are categorized with reference of http://wiki.libvirt.org/page/VirshHelpV2 (by Justin) - the modifications doesn't affect tests * TODO: - doc
2010-11-30 09:37:04 +03:00
static const vshCmdGrp cmdGroups[];
static const vshClientHooks hooks;
2009-02-09 17:24:06 +03:00
/*
* Detection of disconnections and automatic reconnection support
*/
static int disconnected; /* we may have been disconnected */
/*
* virshCatchDisconnect:
*
* We get here when the connection was closed. We can't do much in the
* handler, just save the fact it was raised.
*/
static void
virshCatchDisconnect(virConnectPtr conn ATTRIBUTE_UNUSED,
int reason,
void *opaque ATTRIBUTE_UNUSED)
{
if (reason != VIR_CONNECT_CLOSE_REASON_CLIENT)
disconnected++;
}
/* Main Function which should be used for connecting.
* This function properly handles keepalive settings. */
virConnectPtr
virshConnect(vshControl *ctl, const char *uri, bool readonly)
{
virConnectPtr c = NULL;
int interval = 5; /* Default */
int count = 6; /* Default */
bool keepalive_forced = false;
if (ctl->keepalive_interval >= 0) {
interval = ctl->keepalive_interval;
keepalive_forced = true;
}
if (ctl->keepalive_count >= 0) {
count = ctl->keepalive_count;
keepalive_forced = true;
}
c = virConnectOpenAuth(uri, virConnectAuthPtrDefault,
readonly ? VIR_CONNECT_RO : 0);
if (!c)
return NULL;
if (interval > 0 &&
virConnectSetKeepAlive(c, interval, count) != 0) {
if (keepalive_forced) {
vshError(ctl, "%s",
_("Cannot setup keepalive on connection "
"as requested, disconnecting"));
virConnectClose(c);
return NULL;
}
vshDebug(ctl, VSH_ERR_INFO, "%s",
_("Failed to setup keepalive on connection\n"));
}
return c;
}
/*
* virshReconnect:
*
* Reconnect after a disconnect from libvirtd
*
*/
static void
virshReconnect(vshControl *ctl)
{
bool connected = false;
virshControlPtr priv = ctl->privData;
if (priv->conn) {
int ret;
connected = true;
virConnectUnregisterCloseCallback(priv->conn, virshCatchDisconnect);
ret = virConnectClose(priv->conn);
if (ret < 0)
vshError(ctl, "%s", _("Failed to disconnect from the hypervisor"));
else if (ret > 0)
vshError(ctl, "%s", _("One or more references were leaked after "
"disconnect from the hypervisor"));
}
priv->conn = virshConnect(ctl, ctl->connname, priv->readonly);
if (!priv->conn) {
if (disconnected)
vshError(ctl, "%s", _("Failed to reconnect to the hypervisor"));
else
vshError(ctl, "%s", _("failed to connect to the hypervisor"));
} else {
if (virConnectRegisterCloseCallback(priv->conn, virshCatchDisconnect,
NULL, NULL) < 0)
vshError(ctl, "%s", _("Unable to register disconnect callback"));
if (connected)
vshError(ctl, "%s", _("Reconnected to the hypervisor"));
}
disconnected = 0;
priv->useGetInfo = false;
priv->useSnapshotOld = false;
priv->blockJobNoBytes = false;
}
int virshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED,
const char *bytes, size_t nbytes, void *opaque)
{
int *fd = opaque;
return safewrite(*fd, bytes, nbytes);
}
/* ---------------
* Command Connect
* ---------------
*/
static const vshCmdOptDef opts_connect[] = {
{.name = "name",
.type = VSH_OT_STRING,
.flags = VSH_OFLAG_EMPTY_OK,
.help = N_("hypervisor connection URI")
},
{.name = "readonly",
.type = VSH_OT_BOOL,
.help = N_("read-only connection")
},
{.name = NULL}
};
static const vshCmdInfo info_connect[] = {
{.name = "help",
.data = N_("(re)connect to hypervisor")
},
{.name = "desc",
.data = N_("Connect to local hypervisor. This is built-in "
"command after shell start up.")
},
{.name = NULL}
};
static bool
cmdConnect(vshControl *ctl, const vshCmd *cmd)
{
bool ro = vshCommandOptBool(cmd, "readonly");
const char *name = NULL;
virshControlPtr priv = ctl->privData;
if (priv->conn) {
int ret;
virConnectUnregisterCloseCallback(priv->conn, virshCatchDisconnect);
ret = virConnectClose(priv->conn);
if (ret < 0)
vshError(ctl, "%s", _("Failed to disconnect from the hypervisor"));
else if (ret > 0)
vshError(ctl, "%s", _("One or more references were leaked after "
"disconnect from the hypervisor"));
priv->conn = NULL;
}
VIR_FREE(ctl->connname);
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
return false;
ctl->connname = vshStrdup(ctl, name);
priv->useGetInfo = false;
priv->useSnapshotOld = false;
priv->blockJobNoBytes = false;
priv->readonly = ro;
priv->conn = virshConnect(ctl, ctl->connname, priv->readonly);
if (!priv->conn) {
vshError(ctl, "%s", _("Failed to connect to the hypervisor"));
return false;
}
if (virConnectRegisterCloseCallback(priv->conn, virshCatchDisconnect,
NULL, NULL) < 0)
vshError(ctl, "%s", _("Unable to register disconnect callback"));
return true;
}
/* ---------------
* Utils for work with runtime commands data
* ---------------
*/
static bool
virshConnectionUsability(vshControl *ctl, virConnectPtr conn)
{
if (!conn ||
virConnectIsAlive(conn) == 0) {
vshError(ctl, "%s", _("no valid connection"));
return false;
}
/* The connection is considered dead only if
* virConnectIsAlive() successfuly says so.
*/
vshResetLibvirtError();
return true;
}
static void *
virshConnectionHandler(vshControl *ctl)
{
virshControlPtr priv = ctl->privData;
if (!priv->conn || disconnected)
virshReconnect(ctl);
if (virshConnectionUsability(ctl, priv->conn))
return priv->conn;
return NULL;
}
/* ---------------
* Misc utils
* ---------------
*/
int
virshDomainState(vshControl *ctl, virDomainPtr dom, int *reason)
{
virDomainInfo info;
virshControlPtr priv = ctl->privData;
if (reason)
*reason = -1;
if (!priv->useGetInfo) {
int state;
if (virDomainGetState(dom, &state, reason, 0) < 0) {
virErrorPtr err = virGetLastError();
if (err && err->code == VIR_ERR_NO_SUPPORT)
priv->useGetInfo = true;
else
return -1;
} else {
return state;
}
}
/* fall back to virDomainGetInfo if virDomainGetState is not supported */
if (virDomainGetInfo(dom, &info) < 0)
return -1;
else
return info.state;
}
/*
* Initialize connection.
*/
static bool
virshInit(vshControl *ctl)
{
virshControlPtr priv = ctl->privData;
/* Since we have the commandline arguments parsed, we need to
* re-initialize all the debugging to make it work properly */
vshInitDebug(ctl);
if (priv->conn)
return false;
/* set up the library error handler */
virSetErrorFunc(NULL, vshErrorHandler);
if (virEventRegisterDefaultImpl() < 0)
return false;
if (virThreadCreate(&ctl->eventLoop, true, vshEventLoop, ctl) < 0)
return false;
ctl->eventLoopStarted = true;
if ((ctl->eventTimerId = virEventAddTimeout(-1, vshEventTimeout, ctl,
NULL)) < 0)
return false;
if (ctl->connname) {
virshReconnect(ctl);
/* Connecting to a named connection must succeed, but we delay
* connecting to the default connection until we need it
* (since the first command might be 'connect' which allows a
* non-default connection, or might be 'help' which needs no
* connection).
*/
if (!priv->conn) {
virsh: use common namespacing Convert the exported items in virsh.h to use a common 'vsh' prefix. * tools/virsh.h (VIRSH_MAX_XML_FILE): Rename... (VSH_MAX_XML_FILE): ...and parenthesize. (DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete. (vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype. (editWriteToTempFile, editFile, editReadBackFile, prettyCapacity) (virshReportError): Rename... (vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile) (vshPrettyCapacity, vshReportError): ...into vsh namespace. (jobWatchTimeoutFunc): Move to virsh-domain.c. * tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC. (main): Inline former CTRL_CLOSE_BRACKET. (vshUsage, vshInit, vshDeinit, vshParseArgv): Make static. (prettyCapacity, virshReportError, editWriteToTempFile, editFile): Fix naming, and adjust usage. (vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust usage. * tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare) (cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice) (cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount) (cmdAttachDevice, cmdDomjobinfo): Likewise. * tools/virsh-edit.c (do): Likewise. * tools/virsh-interface.c (cmdInterfaceDefine): Likewise. * tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine): Likewise. * tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise. * tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise. * tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine) (cmdPoolDiscoverSources, cmdPoolList): Likewise. * tools/virsh-secret.c (cmdSecretDefine): Likewise. * tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate) (vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent) (vshGetSnapshotParent): Likewise. * tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom) (cmdVolInfo, cmdVolList): Likewise.
2012-08-19 08:10:17 +04:00
vshReportError(ctl);
return false;
}
}
2005-12-08 13:23:34 +03:00
return true;
2005-12-08 13:23:34 +03:00
}
static void
virshDeinitTimer(int timer ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED)
{
/* nothing to be done here */
}
2005-12-08 13:23:34 +03:00
/*
* Deinitialize virsh
2005-12-08 13:23:34 +03:00
*/
virsh: use common namespacing Convert the exported items in virsh.h to use a common 'vsh' prefix. * tools/virsh.h (VIRSH_MAX_XML_FILE): Rename... (VSH_MAX_XML_FILE): ...and parenthesize. (DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete. (vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype. (editWriteToTempFile, editFile, editReadBackFile, prettyCapacity) (virshReportError): Rename... (vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile) (vshPrettyCapacity, vshReportError): ...into vsh namespace. (jobWatchTimeoutFunc): Move to virsh-domain.c. * tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC. (main): Inline former CTRL_CLOSE_BRACKET. (vshUsage, vshInit, vshDeinit, vshParseArgv): Make static. (prettyCapacity, virshReportError, editWriteToTempFile, editFile): Fix naming, and adjust usage. (vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust usage. * tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare) (cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice) (cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount) (cmdAttachDevice, cmdDomjobinfo): Likewise. * tools/virsh-edit.c (do): Likewise. * tools/virsh-interface.c (cmdInterfaceDefine): Likewise. * tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine): Likewise. * tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise. * tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise. * tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine) (cmdPoolDiscoverSources, cmdPoolList): Likewise. * tools/virsh-secret.c (cmdSecretDefine): Likewise. * tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate) (vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent) (vshGetSnapshotParent): Likewise. * tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom) (cmdVolInfo, cmdVolList): Likewise.
2012-08-19 08:10:17 +04:00
static bool
virshDeinit(vshControl *ctl)
{
virshControlPtr priv = ctl->privData;
vshDeinit(ctl);
VIR_FREE(ctl->connname);
if (priv->conn) {
int ret;
virConnectUnregisterCloseCallback(priv->conn, virshCatchDisconnect);
ret = virConnectClose(priv->conn);
if (ret < 0)
vshError(ctl, "%s", _("Failed to disconnect from the hypervisor"));
else if (ret > 0)
vshError(ctl, "%s", _("One or more references were leaked after "
"disconnect from the hypervisor"));
2005-12-08 13:23:34 +03:00
}
2007-12-01 18:45:25 +03:00
virResetLastError();
if (ctl->eventLoopStarted) {
int timer;
virMutexLock(&ctl->lock);
ctl->quit = true;
/* HACK: Add a dummy timeout to break event loop */
timer = virEventAddTimeout(0, virshDeinitTimer, NULL, NULL);
virMutexUnlock(&ctl->lock);
virThreadJoin(&ctl->eventLoop);
if (timer != -1)
virEventRemoveTimeout(timer);
if (ctl->eventTimerId != -1)
virEventRemoveTimeout(ctl->eventTimerId);
ctl->eventLoopStarted = false;
}
virMutexDestroy(&ctl->lock);
return true;
2005-12-08 13:23:34 +03:00
}
2005-12-08 13:23:34 +03:00
/*
* Print usage
*/
virsh: use common namespacing Convert the exported items in virsh.h to use a common 'vsh' prefix. * tools/virsh.h (VIRSH_MAX_XML_FILE): Rename... (VSH_MAX_XML_FILE): ...and parenthesize. (DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete. (vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype. (editWriteToTempFile, editFile, editReadBackFile, prettyCapacity) (virshReportError): Rename... (vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile) (vshPrettyCapacity, vshReportError): ...into vsh namespace. (jobWatchTimeoutFunc): Move to virsh-domain.c. * tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC. (main): Inline former CTRL_CLOSE_BRACKET. (vshUsage, vshInit, vshDeinit, vshParseArgv): Make static. (prettyCapacity, virshReportError, editWriteToTempFile, editFile): Fix naming, and adjust usage. (vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust usage. * tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare) (cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice) (cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount) (cmdAttachDevice, cmdDomjobinfo): Likewise. * tools/virsh-edit.c (do): Likewise. * tools/virsh-interface.c (cmdInterfaceDefine): Likewise. * tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine): Likewise. * tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise. * tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise. * tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine) (cmdPoolDiscoverSources, cmdPoolList): Likewise. * tools/virsh-secret.c (cmdSecretDefine): Likewise. * tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate) (vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent) (vshGetSnapshotParent): Likewise. * tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom) (cmdVolInfo, cmdVolList): Likewise.
2012-08-19 08:10:17 +04:00
static void
virshUsage(void)
{
virsh: Categorize commands into groups for virsh help Change the virsh help out. The new output of "virsh help" and "virsh --help" will be like: Secret (help keyword 'secret'): secret-define define or modify a secret from an XML file secret-dumpxml secret attributes in XML secret-set-value set a secret value secret-get-value Output a secret value secret-undefine undefine a secret secret-list list secrets Snapshot (help keyword 'snapshot'): snapshot-create Create a snapshot snapshot-current Get the current snapshot snapshot-delete Delete a domain snapshot snapshot-dumpxml Dump XML for a domain snapshot snapshot-list List snapshots for a domain snapshot-revert Revert a domain to a snapshot Also support output help information of specified command group, e.g. % ./tools/virsh help "Network Filter" Network Filter (help keyword 'filter'): nwfilter-define define or update a network filter from an XML file nwfilter-undefine undefine a network filter nwfilter-dumpxml network filter information in XML nwfilter-list list network filters nwfilter-edit edit XML configuration for a network filter Each group has a help keyword, e.g. % ./tools/virsh help filter Network Filter (help keyword 'filter'): nwfilter-define define or update a network filter from an XML file nwfilter-undefine undefine a network filter nwfilter-dumpxml network filter information in XML nwfilter-list list network filters nwfilter-edit edit XML configuration for a network filter * tools/virsh.c: - introduce new struct "vshCmdGrp" and macros to define the groups. - split previous array "commands" into small arrays which are orgnized by group - changed some functions, e.g. "vshCmdDefSearch" - Added new functions, e.g. "vshCmdGrpSearch" - commands of each group are in "alphabetical order" now. - command groups are in "alphabetical order" now. - the commands are categorized with reference of http://wiki.libvirt.org/page/VirshHelpV2 (by Justin) - the modifications doesn't affect tests * TODO: - doc
2010-11-30 09:37:04 +03:00
const vshCmdGrp *grp;
const vshCmdDef *cmd;
virsh: Categorize commands into groups for virsh help Change the virsh help out. The new output of "virsh help" and "virsh --help" will be like: Secret (help keyword 'secret'): secret-define define or modify a secret from an XML file secret-dumpxml secret attributes in XML secret-set-value set a secret value secret-get-value Output a secret value secret-undefine undefine a secret secret-list list secrets Snapshot (help keyword 'snapshot'): snapshot-create Create a snapshot snapshot-current Get the current snapshot snapshot-delete Delete a domain snapshot snapshot-dumpxml Dump XML for a domain snapshot snapshot-list List snapshots for a domain snapshot-revert Revert a domain to a snapshot Also support output help information of specified command group, e.g. % ./tools/virsh help "Network Filter" Network Filter (help keyword 'filter'): nwfilter-define define or update a network filter from an XML file nwfilter-undefine undefine a network filter nwfilter-dumpxml network filter information in XML nwfilter-list list network filters nwfilter-edit edit XML configuration for a network filter Each group has a help keyword, e.g. % ./tools/virsh help filter Network Filter (help keyword 'filter'): nwfilter-define define or update a network filter from an XML file nwfilter-undefine undefine a network filter nwfilter-dumpxml network filter information in XML nwfilter-list list network filters nwfilter-edit edit XML configuration for a network filter * tools/virsh.c: - introduce new struct "vshCmdGrp" and macros to define the groups. - split previous array "commands" into small arrays which are orgnized by group - changed some functions, e.g. "vshCmdDefSearch" - Added new functions, e.g. "vshCmdGrpSearch" - commands of each group are in "alphabetical order" now. - command groups are in "alphabetical order" now. - the commands are categorized with reference of http://wiki.libvirt.org/page/VirshHelpV2 (by Justin) - the modifications doesn't affect tests * TODO: - doc
2010-11-30 09:37:04 +03:00
fprintf(stdout, _("\n%s [options]... [<command_string>]"
"\n%s [options]... <command> [args...]\n\n"
" options:\n"
" -c | --connect=URI hypervisor connection URI\n"
" -d | --debug=NUM debug level [0-4]\n"
" -e | --escape <char> set escape sequence for console\n"
" -h | --help this help\n"
" -k | --keepalive-interval=NUM\n"
" keepalive interval in seconds, 0 for disable\n"
" -K | --keepalive-count=NUM\n"
" number of possible missed keepalive messages\n"
" -l | --log=FILE output logging to file\n"
" -q | --quiet quiet mode\n"
" -r | --readonly connect readonly\n"
" -t | --timing print timing information\n"
" -v short version\n"
" -V long version\n"
" --version[=TYPE] version, TYPE is short or long (default short)\n"
" commands (non interactive mode):\n\n"), progname,
progname);
virsh: Categorize commands into groups for virsh help Change the virsh help out. The new output of "virsh help" and "virsh --help" will be like: Secret (help keyword 'secret'): secret-define define or modify a secret from an XML file secret-dumpxml secret attributes in XML secret-set-value set a secret value secret-get-value Output a secret value secret-undefine undefine a secret secret-list list secrets Snapshot (help keyword 'snapshot'): snapshot-create Create a snapshot snapshot-current Get the current snapshot snapshot-delete Delete a domain snapshot snapshot-dumpxml Dump XML for a domain snapshot snapshot-list List snapshots for a domain snapshot-revert Revert a domain to a snapshot Also support output help information of specified command group, e.g. % ./tools/virsh help "Network Filter" Network Filter (help keyword 'filter'): nwfilter-define define or update a network filter from an XML file nwfilter-undefine undefine a network filter nwfilter-dumpxml network filter information in XML nwfilter-list list network filters nwfilter-edit edit XML configuration for a network filter Each group has a help keyword, e.g. % ./tools/virsh help filter Network Filter (help keyword 'filter'): nwfilter-define define or update a network filter from an XML file nwfilter-undefine undefine a network filter nwfilter-dumpxml network filter information in XML nwfilter-list list network filters nwfilter-edit edit XML configuration for a network filter * tools/virsh.c: - introduce new struct "vshCmdGrp" and macros to define the groups. - split previous array "commands" into small arrays which are orgnized by group - changed some functions, e.g. "vshCmdDefSearch" - Added new functions, e.g. "vshCmdGrpSearch" - commands of each group are in "alphabetical order" now. - command groups are in "alphabetical order" now. - the commands are categorized with reference of http://wiki.libvirt.org/page/VirshHelpV2 (by Justin) - the modifications doesn't affect tests * TODO: - doc
2010-11-30 09:37:04 +03:00
for (grp = cmdGroups; grp->name; grp++) {
fprintf(stdout, _(" %s (help keyword '%s')\n"),
grp->name, grp->keyword);
for (cmd = grp->commands; cmd->name; cmd++) {
if (cmd->flags & VSH_CMD_FLAG_ALIAS)
continue;
virsh: Categorize commands into groups for virsh help Change the virsh help out. The new output of "virsh help" and "virsh --help" will be like: Secret (help keyword 'secret'): secret-define define or modify a secret from an XML file secret-dumpxml secret attributes in XML secret-set-value set a secret value secret-get-value Output a secret value secret-undefine undefine a secret secret-list list secrets Snapshot (help keyword 'snapshot'): snapshot-create Create a snapshot snapshot-current Get the current snapshot snapshot-delete Delete a domain snapshot snapshot-dumpxml Dump XML for a domain snapshot snapshot-list List snapshots for a domain snapshot-revert Revert a domain to a snapshot Also support output help information of specified command group, e.g. % ./tools/virsh help "Network Filter" Network Filter (help keyword 'filter'): nwfilter-define define or update a network filter from an XML file nwfilter-undefine undefine a network filter nwfilter-dumpxml network filter information in XML nwfilter-list list network filters nwfilter-edit edit XML configuration for a network filter Each group has a help keyword, e.g. % ./tools/virsh help filter Network Filter (help keyword 'filter'): nwfilter-define define or update a network filter from an XML file nwfilter-undefine undefine a network filter nwfilter-dumpxml network filter information in XML nwfilter-list list network filters nwfilter-edit edit XML configuration for a network filter * tools/virsh.c: - introduce new struct "vshCmdGrp" and macros to define the groups. - split previous array "commands" into small arrays which are orgnized by group - changed some functions, e.g. "vshCmdDefSearch" - Added new functions, e.g. "vshCmdGrpSearch" - commands of each group are in "alphabetical order" now. - command groups are in "alphabetical order" now. - the commands are categorized with reference of http://wiki.libvirt.org/page/VirshHelpV2 (by Justin) - the modifications doesn't affect tests * TODO: - doc
2010-11-30 09:37:04 +03:00
fprintf(stdout,
" %-30s %s\n", cmd->name,
_(vshCmddefGetInfo(cmd, "help")));
}
virsh: Categorize commands into groups for virsh help Change the virsh help out. The new output of "virsh help" and "virsh --help" will be like: Secret (help keyword 'secret'): secret-define define or modify a secret from an XML file secret-dumpxml secret attributes in XML secret-set-value set a secret value secret-get-value Output a secret value secret-undefine undefine a secret secret-list list secrets Snapshot (help keyword 'snapshot'): snapshot-create Create a snapshot snapshot-current Get the current snapshot snapshot-delete Delete a domain snapshot snapshot-dumpxml Dump XML for a domain snapshot snapshot-list List snapshots for a domain snapshot-revert Revert a domain to a snapshot Also support output help information of specified command group, e.g. % ./tools/virsh help "Network Filter" Network Filter (help keyword 'filter'): nwfilter-define define or update a network filter from an XML file nwfilter-undefine undefine a network filter nwfilter-dumpxml network filter information in XML nwfilter-list list network filters nwfilter-edit edit XML configuration for a network filter Each group has a help keyword, e.g. % ./tools/virsh help filter Network Filter (help keyword 'filter'): nwfilter-define define or update a network filter from an XML file nwfilter-undefine undefine a network filter nwfilter-dumpxml network filter information in XML nwfilter-list list network filters nwfilter-edit edit XML configuration for a network filter * tools/virsh.c: - introduce new struct "vshCmdGrp" and macros to define the groups. - split previous array "commands" into small arrays which are orgnized by group - changed some functions, e.g. "vshCmdDefSearch" - Added new functions, e.g. "vshCmdGrpSearch" - commands of each group are in "alphabetical order" now. - command groups are in "alphabetical order" now. - the commands are categorized with reference of http://wiki.libvirt.org/page/VirshHelpV2 (by Justin) - the modifications doesn't affect tests * TODO: - doc
2010-11-30 09:37:04 +03:00
fprintf(stdout, "\n");
}
fprintf(stdout, "%s",
_("\n (specify help <group> for details about the commands in the group)\n"));
fprintf(stdout, "%s",
_("\n (specify help <command> for details about the command)\n\n"));
return;
2005-12-08 13:23:34 +03:00
}
/*
* Show version and options compiled in
*/
static void
virshShowVersion(vshControl *ctl ATTRIBUTE_UNUSED)
{
/* FIXME - list a copyright blurb, as in GNU programs? */
vshPrint(ctl, _("Virsh command line tool of libvirt %s\n"), VERSION);
vshPrint(ctl, _("See web site at %s\n\n"), "http://libvirt.org/");
vshPrint(ctl, "%s", _("Compiled with support for:\n"));
vshPrint(ctl, "%s", _(" Hypervisors:"));
#ifdef WITH_QEMU
vshPrint(ctl, " QEMU/KVM");
#endif
#ifdef WITH_LXC
vshPrint(ctl, " LXC");
#endif
#ifdef WITH_UML
vshPrint(ctl, " UML");
#endif
#ifdef WITH_XEN
vshPrint(ctl, " Xen");
#endif
#ifdef WITH_LIBXL
vshPrint(ctl, " LibXL");
#endif
#ifdef WITH_OPENVZ
vshPrint(ctl, " OpenVZ");
#endif
#ifdef WITH_VMWARE
vshPrint(ctl, " VMWare");
#endif
#ifdef WITH_PHYP
vshPrint(ctl, " PHYP");
#endif
#ifdef WITH_VBOX
vshPrint(ctl, " VirtualBox");
#endif
#ifdef WITH_ESX
vshPrint(ctl, " ESX");
#endif
#ifdef WITH_HYPERV
vshPrint(ctl, " Hyper-V");
#endif
#ifdef WITH_XENAPI
vshPrint(ctl, " XenAPI");
#endif
#ifdef WITH_BHYVE
vshPrint(ctl, " Bhyve");
#endif
#ifdef WITH_TEST
vshPrint(ctl, " Test");
#endif
vshPrint(ctl, "\n");
vshPrint(ctl, "%s", _(" Networking:"));
#ifdef WITH_REMOTE
vshPrint(ctl, " Remote");
#endif
#ifdef WITH_NETWORK
vshPrint(ctl, " Network");
#endif
#ifdef WITH_BRIDGE
vshPrint(ctl, " Bridging");
#endif
#if defined(WITH_INTERFACE)
vshPrint(ctl, " Interface");
# if defined(WITH_NETCF)
vshPrint(ctl, " netcf");
# elif defined(WITH_UDEV)
vshPrint(ctl, " udev");
# endif
#endif
#ifdef WITH_NWFILTER
vshPrint(ctl, " Nwfilter");
#endif
#ifdef WITH_VIRTUALPORT
vshPrint(ctl, " VirtualPort");
#endif
vshPrint(ctl, "\n");
vshPrint(ctl, "%s", _(" Storage:"));
#ifdef WITH_STORAGE_DIR
vshPrint(ctl, " Dir");
#endif
#ifdef WITH_STORAGE_DISK
vshPrint(ctl, " Disk");
#endif
#ifdef WITH_STORAGE_FS
vshPrint(ctl, " Filesystem");
#endif
#ifdef WITH_STORAGE_SCSI
vshPrint(ctl, " SCSI");
#endif
#ifdef WITH_STORAGE_MPATH
vshPrint(ctl, " Multipath");
#endif
#ifdef WITH_STORAGE_ISCSI
vshPrint(ctl, " iSCSI");
#endif
#ifdef WITH_STORAGE_LVM
vshPrint(ctl, " LVM");
#endif
#ifdef WITH_STORAGE_RBD
vshPrint(ctl, " RBD");
#endif
#ifdef WITH_STORAGE_SHEEPDOG
vshPrint(ctl, " Sheepdog");
#endif
#ifdef WITH_STORAGE_GLUSTER
vshPrint(ctl, " Gluster");
#endif
vshPrint(ctl, "\n");
vshPrint(ctl, "%s", _(" Miscellaneous:"));
#ifdef WITH_LIBVIRTD
vshPrint(ctl, " Daemon");
#endif
#ifdef WITH_NODE_DEVICES
vshPrint(ctl, " Nodedev");
#endif
#ifdef WITH_SECDRIVER_APPARMOR
vshPrint(ctl, " AppArmor");
#endif
#ifdef WITH_SECDRIVER_SELINUX
vshPrint(ctl, " SELinux");
#endif
#ifdef WITH_SECRETS
vshPrint(ctl, " Secrets");
#endif
#ifdef ENABLE_DEBUG
vshPrint(ctl, " Debug");
#endif
#ifdef WITH_DTRACE_PROBES
vshPrint(ctl, " DTrace");
#endif
#if WITH_READLINE
vshPrint(ctl, " Readline");
#endif
#ifdef WITH_DRIVER_MODULES
vshPrint(ctl, " Modular");
#endif
vshPrint(ctl, "\n");
}
static bool
virshAllowedEscapeChar(char c)
{
/* Allowed escape characters:
* a-z A-Z @ [ \ ] ^ _
*/
return ('a' <= c && c <= 'z') ||
('@' <= c && c <= '_');
}
/*
* argv[]: virsh [options] [command]
*
*/
virsh: use common namespacing Convert the exported items in virsh.h to use a common 'vsh' prefix. * tools/virsh.h (VIRSH_MAX_XML_FILE): Rename... (VSH_MAX_XML_FILE): ...and parenthesize. (DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete. (vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype. (editWriteToTempFile, editFile, editReadBackFile, prettyCapacity) (virshReportError): Rename... (vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile) (vshPrettyCapacity, vshReportError): ...into vsh namespace. (jobWatchTimeoutFunc): Move to virsh-domain.c. * tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC. (main): Inline former CTRL_CLOSE_BRACKET. (vshUsage, vshInit, vshDeinit, vshParseArgv): Make static. (prettyCapacity, virshReportError, editWriteToTempFile, editFile): Fix naming, and adjust usage. (vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust usage. * tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare) (cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice) (cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount) (cmdAttachDevice, cmdDomjobinfo): Likewise. * tools/virsh-edit.c (do): Likewise. * tools/virsh-interface.c (cmdInterfaceDefine): Likewise. * tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine): Likewise. * tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise. * tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise. * tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine) (cmdPoolDiscoverSources, cmdPoolList): Likewise. * tools/virsh-secret.c (cmdSecretDefine): Likewise. * tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate) (vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent) (vshGetSnapshotParent): Likewise. * tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom) (cmdVolInfo, cmdVolList): Likewise.
2012-08-19 08:10:17 +04:00
static bool
virshParseArgv(vshControl *ctl, int argc, char **argv)
{
int arg, len, debug, keepalive;
size_t i;
int longindex = -1;
virshControlPtr priv = ctl->privData;
struct option opt[] = {
{"connect", required_argument, NULL, 'c'},
{"debug", required_argument, NULL, 'd'},
{"escape", required_argument, NULL, 'e'},
{"help", no_argument, NULL, 'h'},
{"keepalive-interval", required_argument, NULL, 'k'},
{"keepalive-count", required_argument, NULL, 'K'},
{"log", required_argument, NULL, 'l'},
{"quiet", no_argument, NULL, 'q'},
{"readonly", no_argument, NULL, 'r'},
{"timing", no_argument, NULL, 't'},
{"version", optional_argument, NULL, 'v'},
{NULL, 0, NULL, 0}
};
/* Standard (non-command) options. The leading + ensures that no
* argument reordering takes place, so that command options are
* not confused with top-level virsh options. */
while ((arg = getopt_long(argc, argv, "+:c:d:e:hk:K:l:qrtvV", opt, &longindex)) != -1) {
switch (arg) {
case 'c':
VIR_FREE(ctl->connname);
ctl->connname = vshStrdup(ctl, optarg);
break;
case 'd':
if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) {
vshError(ctl, _("option %s takes a numeric argument"),
longindex == -1 ? "-d" : "--debug");
exit(EXIT_FAILURE);
}
if (debug < VSH_ERR_DEBUG || debug > VSH_ERR_ERROR)
vshError(ctl, _("ignoring debug level %d out of range [%d-%d]"),
debug, VSH_ERR_DEBUG, VSH_ERR_ERROR);
else
ctl->debug = debug;
break;
case 'e':
len = strlen(optarg);
if ((len == 2 && *optarg == '^' &&
virshAllowedEscapeChar(optarg[1])) ||
(len == 1 && *optarg != '^')) {
priv->escapeChar = optarg;
} else {
vshError(ctl, _("Invalid string '%s' for escape sequence"),
optarg);
exit(EXIT_FAILURE);
}
break;
case 'h':
virshUsage();
exit(EXIT_SUCCESS);
break;
case 'k':
if (virStrToLong_i(optarg, NULL, 0, &keepalive) < 0) {
vshError(ctl,
_("Invalid value for option %s"),
longindex == -1 ? "-k" : "--keepalive-interval");
exit(EXIT_FAILURE);
}
if (keepalive < 0) {
vshError(ctl,
_("option %s requires a positive integer argument"),
longindex == -1 ? "-k" : "--keepalive-interval");
exit(EXIT_FAILURE);
}
ctl->keepalive_interval = keepalive;
break;
case 'K':
if (virStrToLong_i(optarg, NULL, 0, &keepalive) < 0) {
vshError(ctl,
_("Invalid value for option %s"),
longindex == -1 ? "-K" : "--keepalive-count");
exit(EXIT_FAILURE);
}
if (keepalive < 0) {
vshError(ctl,
_("option %s requires a positive integer argument"),
longindex == -1 ? "-K" : "--keepalive-count");
exit(EXIT_FAILURE);
}
ctl->keepalive_count = keepalive;
break;
case 'l':
vshCloseLogFile(ctl);
ctl->logfile = vshStrdup(ctl, optarg);
vshOpenLogFile(ctl);
break;
case 'q':
ctl->quiet = true;
break;
case 't':
ctl->timing = true;
break;
case 'r':
priv->readonly = true;
break;
case 'v':
if (STRNEQ_NULLABLE(optarg, "long")) {
puts(VERSION);
exit(EXIT_SUCCESS);
}
/* fall through */
case 'V':
virshShowVersion(ctl);
exit(EXIT_SUCCESS);
case ':':
for (i = 0; opt[i].name != NULL; i++) {
if (opt[i].val == optopt)
break;
}
if (opt[i].name)
vshError(ctl, _("option '-%c'/'--%s' requires an argument"),
optopt, opt[i].name);
else
vshError(ctl, _("option '-%c' requires an argument"), optopt);
exit(EXIT_FAILURE);
case '?':
if (optopt)
vshError(ctl, _("unsupported option '-%c'. See --help."), optopt);
else
vshError(ctl, _("unsupported option '%s'. See --help."), argv[optind - 1]);
exit(EXIT_FAILURE);
default:
vshError(ctl, _("unknown option"));
exit(EXIT_FAILURE);
}
longindex = -1;
}
if (argc > optind) {
/* parse command */
ctl->imode = false;
if (argc - optind == 1) {
vshDebug(ctl, VSH_ERR_INFO, "commands: \"%s\"\n", argv[optind]);
return vshCommandStringParse(ctl, argv[optind]);
} else {
return vshCommandArgvParse(ctl, argc - optind, argv + optind);
}
}
return true;
}
static const vshCmdDef virshCmds[] = {
VSH_CMD_CD,
VSH_CMD_ECHO,
VSH_CMD_EXIT,
VSH_CMD_HELP,
VSH_CMD_PWD,
VSH_CMD_QUIT,
{.name = "connect",
.handler = cmdConnect,
.opts = opts_connect,
.info = info_connect,
.flags = VSH_CMD_FLAG_NOCONNECT
},
{.name = NULL}
};
static const vshCmdGrp cmdGroups[] = {
{VIRSH_CMD_GRP_DOM_MANAGEMENT, "domain", domManagementCmds},
{VIRSH_CMD_GRP_DOM_MONITORING, "monitor", domMonitoringCmds},
{VIRSH_CMD_GRP_HOST_AND_HV, "host", hostAndHypervisorCmds},
{VIRSH_CMD_GRP_IFACE, "interface", ifaceCmds},
{VIRSH_CMD_GRP_NWFILTER, "filter", nwfilterCmds},
{VIRSH_CMD_GRP_NETWORK, "network", networkCmds},
{VIRSH_CMD_GRP_NODEDEV, "nodedev", nodedevCmds},
{VIRSH_CMD_GRP_SECRET, "secret", secretCmds},
{VIRSH_CMD_GRP_SNAPSHOT, "snapshot", snapshotCmds},
{VIRSH_CMD_GRP_STORAGE_POOL, "pool", storagePoolCmds},
{VIRSH_CMD_GRP_STORAGE_VOL, "volume", storageVolCmds},
{VIRSH_CMD_GRP_VIRSH, "virsh", virshCmds},
{NULL, NULL, NULL}
};
2005-12-08 13:23:34 +03:00
static const vshClientHooks hooks = {
.connHandler = virshConnectionHandler
};
int
main(int argc, char **argv)
{
vshControl _ctl, *ctl = &_ctl;
virshControl virshCtl;
const char *defaultConn;
bool ret = true;
2005-12-08 13:23:34 +03:00
memset(ctl, 0, sizeof(vshControl));
memset(&virshCtl, 0, sizeof(virshControl));
ctl->name = "virsh"; /* hardcoded name of the binary */
ctl->imode = true; /* default is interactive mode */
ctl->log_fd = -1; /* Initialize log file descriptor */
ctl->debug = VSH_DEBUG_DEFAULT;
ctl->hooks = &hooks;
/* In order to distinguish default from setting to 0 */
ctl->keepalive_interval = -1;
ctl->keepalive_count = -1;
ctl->eventPipe[0] = -1;
ctl->eventPipe[1] = -1;
ctl->eventTimerId = -1;
virshCtl.escapeChar = "^]"; /* Same default as telnet */
ctl->privData = &virshCtl;
if (!(progname = strrchr(argv[0], '/')))
progname = argv[0];
else
progname++;
ctl->progname = progname;
if (!setlocale(LC_ALL, "")) {
perror("setlocale");
2009-01-29 14:49:33 +03:00
/* failure to setup locale is not fatal */
}
maint: use gnulib configmake rather than open-coding things * bootstrap.conf (gnulib_modules): Add configmake. * daemon/Makefile.am (libvirtd_CFLAGS): Drop defines provided by gnulib. * src/Makefile.am (INCLUDES): Likewise. * tests/Makefile.am (INCLUDES): Likewise. * tools/Makefile.am (virsh_CFLAGS): Likewise. * daemon/libvirtd.c (qemudInitPaths, usage, main): Update clients. * src/cpu/cpu_map.c (CPUMAPFILE): Likewise. * src/driver.c (DEFAULT_DRIVER_DIR): Likewise. * src/internal.h (_): Likewise. * src/libvirt.c (virInitialize): Likewise. * src/lxc/lxc_conf.h (LXC_CONFIG_DIR, LXC_STATE_DIR, LXC_LOG_DIR): Likewise. * src/lxc/lxc_conf.c (lxcCapsInit, lxcLoadDriverConfig): Likewise. * src/network/bridge_driver.c (NETWORK_PID_DIR) (NETWORK_STATE_DIR, DNSMASQ_STATE_DIR, networkStartup): Likewise. * src/nwfilter/nwfilter_driver.c (nwfilterDriverStartup): Likewise. * src/qemu/qemu_conf.c (qemudLoadDriverConfig): Likewise. * src/qemu/qemu_driver.c (qemudStartup): Likewise. * src/remote/remote_driver.h (LIBVIRTD_PRIV_UNIX_SOCKET) (LIBVIRTD_PRIV_UNIX_SOCKET_RO, LIBVIRTD_CONFIGURATION_FILE) (LIBVIRT_PKI_DIR): Likewise. * src/secret/secret_driver.c (secretDriverStartup): Likewise. * src/security/security_apparmor.c (VIRT_AA_HELPER): Likewise. * src/security/virt-aa-helper.c (main): Likewise. * src/storage/storage_backend_disk.c (PARTHELPER): Likewise. * src/storage/storage_driver.c (storageDriverStartup): Likewise. * src/uml/uml_driver.c (TEMPDIR, umlStartup): Likewise. * src/util/hooks.c (LIBVIRT_HOOK_DIR): Likewise. * tools/virsh.c (main): Likewise. * docs/hooks.html.in: Likewise.
2010-11-16 17:54:17 +03:00
if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
perror("bindtextdomain");
return EXIT_FAILURE;
}
maint: use gnulib configmake rather than open-coding things * bootstrap.conf (gnulib_modules): Add configmake. * daemon/Makefile.am (libvirtd_CFLAGS): Drop defines provided by gnulib. * src/Makefile.am (INCLUDES): Likewise. * tests/Makefile.am (INCLUDES): Likewise. * tools/Makefile.am (virsh_CFLAGS): Likewise. * daemon/libvirtd.c (qemudInitPaths, usage, main): Update clients. * src/cpu/cpu_map.c (CPUMAPFILE): Likewise. * src/driver.c (DEFAULT_DRIVER_DIR): Likewise. * src/internal.h (_): Likewise. * src/libvirt.c (virInitialize): Likewise. * src/lxc/lxc_conf.h (LXC_CONFIG_DIR, LXC_STATE_DIR, LXC_LOG_DIR): Likewise. * src/lxc/lxc_conf.c (lxcCapsInit, lxcLoadDriverConfig): Likewise. * src/network/bridge_driver.c (NETWORK_PID_DIR) (NETWORK_STATE_DIR, DNSMASQ_STATE_DIR, networkStartup): Likewise. * src/nwfilter/nwfilter_driver.c (nwfilterDriverStartup): Likewise. * src/qemu/qemu_conf.c (qemudLoadDriverConfig): Likewise. * src/qemu/qemu_driver.c (qemudStartup): Likewise. * src/remote/remote_driver.h (LIBVIRTD_PRIV_UNIX_SOCKET) (LIBVIRTD_PRIV_UNIX_SOCKET_RO, LIBVIRTD_CONFIGURATION_FILE) (LIBVIRT_PKI_DIR): Likewise. * src/secret/secret_driver.c (secretDriverStartup): Likewise. * src/security/security_apparmor.c (VIRT_AA_HELPER): Likewise. * src/security/virt-aa-helper.c (main): Likewise. * src/storage/storage_backend_disk.c (PARTHELPER): Likewise. * src/storage/storage_driver.c (storageDriverStartup): Likewise. * src/uml/uml_driver.c (TEMPDIR, umlStartup): Likewise. * src/util/hooks.c (LIBVIRT_HOOK_DIR): Likewise. * tools/virsh.c (main): Likewise. * docs/hooks.html.in: Likewise.
2010-11-16 17:54:17 +03:00
if (!textdomain(PACKAGE)) {
perror("textdomain");
return EXIT_FAILURE;
}
if (isatty(STDIN_FILENO)) {
ctl->istty = true;
#ifndef WIN32
if (tcgetattr(STDIN_FILENO, &ctl->termattr) < 0)
ctl->istty = false;
#endif
}
if (virMutexInit(&ctl->lock) < 0) {
vshError(ctl, "%s", _("Failed to initialize mutex"));
return EXIT_FAILURE;
}
if (virInitialize() < 0) {
vshError(ctl, "%s", _("Failed to initialize libvirt"));
return EXIT_FAILURE;
}
virFileActivateDirOverride(argv[0]);
if ((defaultConn = virGetEnvBlockSUID("VIRSH_DEFAULT_CONNECT_URI")))
ctl->connname = vshStrdup(ctl, defaultConn);
if (vshInit(ctl, cmdGroups, NULL) < 0)
exit(EXIT_FAILURE);
if (!virshParseArgv(ctl, argc, argv) ||
!virshInit(ctl)) {
virshDeinit(ctl);
2005-12-08 13:23:34 +03:00
exit(EXIT_FAILURE);
2007-12-01 18:45:25 +03:00
}
2005-12-08 13:23:34 +03:00
if (!ctl->imode) {
ret = vshCommandRun(ctl, ctl->cmd);
} else {
2005-12-08 13:23:34 +03:00
/* interactive mode */
if (!ctl->quiet) {
2006-05-22 18:38:33 +04:00
vshPrint(ctl,
_("Welcome to %s, the virtualization interactive terminal.\n\n"),
progname);
vshPrint(ctl, "%s",
_("Type: 'help' for help with commands\n"
" 'quit' to quit\n\n"));
2005-12-08 13:23:34 +03:00
}
2005-12-08 13:23:34 +03:00
do {
const char *prompt = virshCtl.readonly ? VIRSH_PROMPT_RO
: VIRSH_PROMPT_RW;
ctl->cmdstr =
vshReadline(ctl, prompt);
if (ctl->cmdstr == NULL)
break; /* EOF */
2005-12-08 13:23:34 +03:00
if (*ctl->cmdstr) {
#if WITH_READLINE
2005-12-08 13:23:34 +03:00
add_history(ctl->cmdstr);
#endif
if (vshCommandStringParse(ctl, ctl->cmdstr))
2005-12-08 13:23:34 +03:00
vshCommandRun(ctl, ctl->cmd);
}
VIR_FREE(ctl->cmdstr);
} while (ctl->imode);
2005-12-08 13:23:34 +03:00
if (ctl->cmdstr == NULL)
fputc('\n', stdout); /* line break after alone prompt */
2005-12-08 13:23:34 +03:00
}
virshDeinit(ctl);
2005-12-08 13:23:34 +03:00
exit(ret ? EXIT_SUCCESS : EXIT_FAILURE);
}