* in multithreaded applications to avoid potential race when initializing
* the library.
*
+ * Calling virInitialize is mandatory, unless your first API call is one of
+ * virConnectOpen*.
+ *
* Returns 0 in case of success, -1 in case of error
*/
int
char *defaultConn;
bool ret = true;
+ memset(ctl, 0, sizeof(vshControl));
+ ctl->imode = true; /* default is interactive mode */
+ ctl->log_fd = -1; /* Initialize log file descriptor */
+
if (!setlocale(LC_ALL, "")) {
perror("setlocale");
/* failure to setup locale is not fatal */
return EXIT_FAILURE;
}
+ if (virInitialize() < 0) {
+ vshError(ctl, "%s", _("Failed to initialize libvirt"));
+ return EXIT_FAILURE;
+ }
+
if (!(progname = strrchr(argv[0], '/')))
progname = argv[0];
else
progname++;
- memset(ctl, 0, sizeof(vshControl));
- ctl->imode = true; /* default is interactive mode */
- ctl->log_fd = -1; /* Initialize log file descriptor */
-
if ((defaultConn = getenv("VIRSH_DEFAULT_CONNECT_URI"))) {
ctl->name = vshStrdup(ctl, defaultConn);
}