VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp@ 60422

Last change on this file since 60422 was 59780, checked in by vboxsync, 9 years ago

Frontends/VBoxManage: fix typo in error check

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 43.5 KB
Line 
1/* $Id: VBoxManageMisc.cpp 59780 2016-02-23 08:09:57Z vboxsync $ */
2/** @file
3 * VBoxManage - VirtualBox's command-line interface.
4 */
5
6/*
7 * Copyright (C) 2006-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#ifndef VBOX_ONLY_DOCS
23# include <VBox/com/com.h>
24# include <VBox/com/string.h>
25# include <VBox/com/Guid.h>
26# include <VBox/com/array.h>
27# include <VBox/com/ErrorInfo.h>
28# include <VBox/com/errorprint.h>
29# include <VBox/com/VirtualBox.h>
30#endif /* !VBOX_ONLY_DOCS */
31
32#include <iprt/asm.h>
33#include <iprt/buildconfig.h>
34#include <iprt/cidr.h>
35#include <iprt/ctype.h>
36#include <iprt/dir.h>
37#include <iprt/env.h>
38#include <VBox/err.h>
39#include <iprt/file.h>
40#include <iprt/initterm.h>
41#include <iprt/param.h>
42#include <iprt/path.h>
43#include <iprt/stream.h>
44#include <iprt/string.h>
45#include <iprt/stdarg.h>
46#include <iprt/thread.h>
47#include <iprt/uuid.h>
48#include <iprt/getopt.h>
49#include <iprt/ctype.h>
50#include <VBox/version.h>
51#include <VBox/log.h>
52
53#include "VBoxManage.h"
54
55#include <list>
56
57using namespace com;
58
59
60
61RTEXITCODE handleRegisterVM(HandlerArg *a)
62{
63 HRESULT rc;
64
65 if (a->argc != 1)
66 return errorSyntax(USAGE_REGISTERVM, "Incorrect number of parameters");
67
68 ComPtr<IMachine> machine;
69 /** @todo Ugly hack to get both the API interpretation of relative paths
70 * and the client's interpretation of relative paths. Remove after the API
71 * has been redesigned. */
72 rc = a->virtualBox->OpenMachine(Bstr(a->argv[0]).raw(),
73 machine.asOutParam());
74 if (rc == VBOX_E_FILE_ERROR)
75 {
76 char szVMFileAbs[RTPATH_MAX] = "";
77 int vrc = RTPathAbs(a->argv[0], szVMFileAbs, sizeof(szVMFileAbs));
78 if (RT_FAILURE(vrc))
79 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Cannot convert filename \"%s\" to absolute path: %Rrc", a->argv[0], vrc);
80 CHECK_ERROR(a->virtualBox, OpenMachine(Bstr(szVMFileAbs).raw(),
81 machine.asOutParam()));
82 }
83 else if (FAILED(rc))
84 CHECK_ERROR(a->virtualBox, OpenMachine(Bstr(a->argv[0]).raw(),
85 machine.asOutParam()));
86 if (SUCCEEDED(rc))
87 {
88 ASSERT(machine);
89 CHECK_ERROR(a->virtualBox, RegisterMachine(machine));
90 }
91 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
92}
93
94static const RTGETOPTDEF g_aUnregisterVMOptions[] =
95{
96 { "--delete", 'd', RTGETOPT_REQ_NOTHING },
97 { "-delete", 'd', RTGETOPT_REQ_NOTHING }, // deprecated
98};
99
100RTEXITCODE handleUnregisterVM(HandlerArg *a)
101{
102 HRESULT rc;
103 const char *VMName = NULL;
104 bool fDelete = false;
105
106 int c;
107 RTGETOPTUNION ValueUnion;
108 RTGETOPTSTATE GetState;
109 // start at 0 because main() has hacked both the argc and argv given to us
110 RTGetOptInit(&GetState, a->argc, a->argv, g_aUnregisterVMOptions, RT_ELEMENTS(g_aUnregisterVMOptions),
111 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
112 while ((c = RTGetOpt(&GetState, &ValueUnion)))
113 {
114 switch (c)
115 {
116 case 'd': // --delete
117 fDelete = true;
118 break;
119
120 case VINF_GETOPT_NOT_OPTION:
121 if (!VMName)
122 VMName = ValueUnion.psz;
123 else
124 return errorSyntax(USAGE_UNREGISTERVM, "Invalid parameter '%s'", ValueUnion.psz);
125 break;
126
127 default:
128 if (c > 0)
129 {
130 if (RT_C_IS_PRINT(c))
131 return errorSyntax(USAGE_UNREGISTERVM, "Invalid option -%c", c);
132 else
133 return errorSyntax(USAGE_UNREGISTERVM, "Invalid option case %i", c);
134 }
135 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
136 return errorSyntax(USAGE_UNREGISTERVM, "unknown option: %s\n", ValueUnion.psz);
137 else if (ValueUnion.pDef)
138 return errorSyntax(USAGE_UNREGISTERVM, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
139 else
140 return errorSyntax(USAGE_UNREGISTERVM, "error: %Rrs", c);
141 }
142 }
143
144 /* check for required options */
145 if (!VMName)
146 return errorSyntax(USAGE_UNREGISTERVM, "VM name required");
147
148 ComPtr<IMachine> machine;
149 CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(VMName).raw(),
150 machine.asOutParam()),
151 RTEXITCODE_FAILURE);
152 SafeIfaceArray<IMedium> aMedia;
153 CHECK_ERROR_RET(machine, Unregister(CleanupMode_DetachAllReturnHardDisksOnly,
154 ComSafeArrayAsOutParam(aMedia)),
155 RTEXITCODE_FAILURE);
156 if (fDelete)
157 {
158 ComPtr<IProgress> pProgress;
159 CHECK_ERROR_RET(machine, DeleteConfig(ComSafeArrayAsInParam(aMedia), pProgress.asOutParam()),
160 RTEXITCODE_FAILURE);
161
162 rc = showProgress(pProgress);
163 CHECK_PROGRESS_ERROR_RET(pProgress, ("Machine delete failed"), RTEXITCODE_FAILURE);
164 }
165 else
166 {
167 /* Note that the IMachine::Unregister method will return the medium
168 * reference in a sane order, which means that closing will normally
169 * succeed, unless there is still another machine which uses the
170 * medium. No harm done if we ignore the error. */
171 for (size_t i = 0; i < aMedia.size(); i++)
172 {
173 IMedium *pMedium = aMedia[i];
174 if (pMedium)
175 rc = pMedium->Close();
176 }
177 rc = S_OK;
178 }
179 return RTEXITCODE_SUCCESS;
180}
181
182static const RTGETOPTDEF g_aCreateVMOptions[] =
183{
184 { "--name", 'n', RTGETOPT_REQ_STRING },
185 { "-name", 'n', RTGETOPT_REQ_STRING },
186 { "--groups", 'g', RTGETOPT_REQ_STRING },
187 { "--basefolder", 'p', RTGETOPT_REQ_STRING },
188 { "-basefolder", 'p', RTGETOPT_REQ_STRING },
189 { "--ostype", 'o', RTGETOPT_REQ_STRING },
190 { "-ostype", 'o', RTGETOPT_REQ_STRING },
191 { "--uuid", 'u', RTGETOPT_REQ_UUID },
192 { "-uuid", 'u', RTGETOPT_REQ_UUID },
193 { "--register", 'r', RTGETOPT_REQ_NOTHING },
194 { "-register", 'r', RTGETOPT_REQ_NOTHING },
195};
196
197RTEXITCODE handleCreateVM(HandlerArg *a)
198{
199 HRESULT rc;
200 Bstr bstrBaseFolder;
201 Bstr bstrName;
202 Bstr bstrOsTypeId;
203 Bstr bstrUuid;
204 bool fRegister = false;
205 com::SafeArray<BSTR> groups;
206
207 int c;
208 RTGETOPTUNION ValueUnion;
209 RTGETOPTSTATE GetState;
210 // start at 0 because main() has hacked both the argc and argv given to us
211 RTGetOptInit(&GetState, a->argc, a->argv, g_aCreateVMOptions, RT_ELEMENTS(g_aCreateVMOptions),
212 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
213 while ((c = RTGetOpt(&GetState, &ValueUnion)))
214 {
215 switch (c)
216 {
217 case 'n': // --name
218 bstrName = ValueUnion.psz;
219 break;
220
221 case 'g': // --groups
222 parseGroups(ValueUnion.psz, &groups);
223 break;
224
225 case 'p': // --basefolder
226 bstrBaseFolder = ValueUnion.psz;
227 break;
228
229 case 'o': // --ostype
230 bstrOsTypeId = ValueUnion.psz;
231 break;
232
233 case 'u': // --uuid
234 bstrUuid = Guid(ValueUnion.Uuid).toUtf16().raw();
235 break;
236
237 case 'r': // --register
238 fRegister = true;
239 break;
240
241 default:
242 return errorGetOpt(USAGE_CREATEVM, c, &ValueUnion);
243 }
244 }
245
246 /* check for required options */
247 if (bstrName.isEmpty())
248 return errorSyntax(USAGE_CREATEVM, "Parameter --name is required");
249
250 do
251 {
252 Bstr createFlags;
253 if (!bstrUuid.isEmpty())
254 createFlags = BstrFmt("UUID=%ls", bstrUuid.raw());
255 Bstr bstrPrimaryGroup;
256 if (groups.size())
257 bstrPrimaryGroup = groups[0];
258 Bstr bstrSettingsFile;
259 CHECK_ERROR_BREAK(a->virtualBox,
260 ComposeMachineFilename(bstrName.raw(),
261 bstrPrimaryGroup.raw(),
262 createFlags.raw(),
263 bstrBaseFolder.raw(),
264 bstrSettingsFile.asOutParam()));
265 ComPtr<IMachine> machine;
266 CHECK_ERROR_BREAK(a->virtualBox,
267 CreateMachine(bstrSettingsFile.raw(),
268 bstrName.raw(),
269 ComSafeArrayAsInParam(groups),
270 bstrOsTypeId.raw(),
271 createFlags.raw(),
272 machine.asOutParam()));
273
274 CHECK_ERROR_BREAK(machine, SaveSettings());
275 if (fRegister)
276 {
277 CHECK_ERROR_BREAK(a->virtualBox, RegisterMachine(machine));
278 }
279 Bstr uuid;
280 CHECK_ERROR_BREAK(machine, COMGETTER(Id)(uuid.asOutParam()));
281 Bstr settingsFile;
282 CHECK_ERROR_BREAK(machine, COMGETTER(SettingsFilePath)(settingsFile.asOutParam()));
283 RTPrintf("Virtual machine '%ls' is created%s.\n"
284 "UUID: %s\n"
285 "Settings file: '%ls'\n",
286 bstrName.raw(), fRegister ? " and registered" : "",
287 Utf8Str(uuid).c_str(), settingsFile.raw());
288 }
289 while (0);
290
291 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
292}
293
294static const RTGETOPTDEF g_aCloneVMOptions[] =
295{
296 { "--snapshot", 's', RTGETOPT_REQ_STRING },
297 { "--name", 'n', RTGETOPT_REQ_STRING },
298 { "--groups", 'g', RTGETOPT_REQ_STRING },
299 { "--mode", 'm', RTGETOPT_REQ_STRING },
300 { "--options", 'o', RTGETOPT_REQ_STRING },
301 { "--register", 'r', RTGETOPT_REQ_NOTHING },
302 { "--basefolder", 'p', RTGETOPT_REQ_STRING },
303 { "--uuid", 'u', RTGETOPT_REQ_UUID },
304};
305
306static int parseCloneMode(const char *psz, CloneMode_T *pMode)
307{
308 if (!RTStrICmp(psz, "machine"))
309 *pMode = CloneMode_MachineState;
310 else if (!RTStrICmp(psz, "machineandchildren"))
311 *pMode = CloneMode_MachineAndChildStates;
312 else if (!RTStrICmp(psz, "all"))
313 *pMode = CloneMode_AllStates;
314 else
315 return VERR_PARSE_ERROR;
316
317 return VINF_SUCCESS;
318}
319
320static int parseCloneOptions(const char *psz, com::SafeArray<CloneOptions_T> *options)
321{
322 int rc = VINF_SUCCESS;
323 while (psz && *psz && RT_SUCCESS(rc))
324 {
325 size_t len;
326 const char *pszComma = strchr(psz, ',');
327 if (pszComma)
328 len = pszComma - psz;
329 else
330 len = strlen(psz);
331 if (len > 0)
332 {
333 if (!RTStrNICmp(psz, "KeepAllMACs", len))
334 options->push_back(CloneOptions_KeepAllMACs);
335 else if (!RTStrNICmp(psz, "KeepNATMACs", len))
336 options->push_back(CloneOptions_KeepNATMACs);
337 else if (!RTStrNICmp(psz, "KeepDiskNames", len))
338 options->push_back(CloneOptions_KeepDiskNames);
339 else if ( !RTStrNICmp(psz, "Link", len)
340 || !RTStrNICmp(psz, "Linked", len))
341 options->push_back(CloneOptions_Link);
342 else
343 rc = VERR_PARSE_ERROR;
344 }
345 if (pszComma)
346 psz += len + 1;
347 else
348 psz += len;
349 }
350
351 return rc;
352}
353
354RTEXITCODE handleCloneVM(HandlerArg *a)
355{
356 HRESULT rc;
357 const char *pszSrcName = NULL;
358 const char *pszSnapshotName = NULL;
359 CloneMode_T mode = CloneMode_MachineState;
360 com::SafeArray<CloneOptions_T> options;
361 const char *pszTrgName = NULL;
362 const char *pszTrgBaseFolder = NULL;
363 bool fRegister = false;
364 Bstr bstrUuid;
365 com::SafeArray<BSTR> groups;
366
367 int c;
368 RTGETOPTUNION ValueUnion;
369 RTGETOPTSTATE GetState;
370 // start at 0 because main() has hacked both the argc and argv given to us
371 RTGetOptInit(&GetState, a->argc, a->argv, g_aCloneVMOptions, RT_ELEMENTS(g_aCloneVMOptions),
372 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
373 while ((c = RTGetOpt(&GetState, &ValueUnion)))
374 {
375 switch (c)
376 {
377 case 's': // --snapshot
378 pszSnapshotName = ValueUnion.psz;
379 break;
380
381 case 'n': // --name
382 pszTrgName = ValueUnion.psz;
383 break;
384
385 case 'g': // --groups
386 parseGroups(ValueUnion.psz, &groups);
387 break;
388
389 case 'p': // --basefolder
390 pszTrgBaseFolder = ValueUnion.psz;
391 break;
392
393 case 'm': // --mode
394 if (RT_FAILURE(parseCloneMode(ValueUnion.psz, &mode)))
395 return errorArgument("Invalid clone mode '%s'\n", ValueUnion.psz);
396 break;
397
398 case 'o': // --options
399 if (RT_FAILURE(parseCloneOptions(ValueUnion.psz, &options)))
400 return errorArgument("Invalid clone options '%s'\n", ValueUnion.psz);
401 break;
402
403 case 'u': // --uuid
404 bstrUuid = Guid(ValueUnion.Uuid).toUtf16().raw();
405 break;
406
407 case 'r': // --register
408 fRegister = true;
409 break;
410
411 case VINF_GETOPT_NOT_OPTION:
412 if (!pszSrcName)
413 pszSrcName = ValueUnion.psz;
414 else
415 return errorSyntax(USAGE_CLONEVM, "Invalid parameter '%s'", ValueUnion.psz);
416 break;
417
418 default:
419 return errorGetOpt(USAGE_CLONEVM, c, &ValueUnion);
420 }
421 }
422
423 /* Check for required options */
424 if (!pszSrcName)
425 return errorSyntax(USAGE_CLONEVM, "VM name required");
426
427 /* Get the machine object */
428 ComPtr<IMachine> srcMachine;
429 CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(pszSrcName).raw(),
430 srcMachine.asOutParam()),
431 RTEXITCODE_FAILURE);
432
433 /* If a snapshot name/uuid was given, get the particular machine of this
434 * snapshot. */
435 if (pszSnapshotName)
436 {
437 ComPtr<ISnapshot> srcSnapshot;
438 CHECK_ERROR_RET(srcMachine, FindSnapshot(Bstr(pszSnapshotName).raw(),
439 srcSnapshot.asOutParam()),
440 RTEXITCODE_FAILURE);
441 CHECK_ERROR_RET(srcSnapshot, COMGETTER(Machine)(srcMachine.asOutParam()),
442 RTEXITCODE_FAILURE);
443 }
444
445 /* Default name necessary? */
446 if (!pszTrgName)
447 pszTrgName = RTStrAPrintf2("%s Clone", pszSrcName);
448
449 Bstr createFlags;
450 if (!bstrUuid.isEmpty())
451 createFlags = BstrFmt("UUID=%ls", bstrUuid.raw());
452 Bstr bstrPrimaryGroup;
453 if (groups.size())
454 bstrPrimaryGroup = groups[0];
455 Bstr bstrSettingsFile;
456 CHECK_ERROR_RET(a->virtualBox,
457 ComposeMachineFilename(Bstr(pszTrgName).raw(),
458 bstrPrimaryGroup.raw(),
459 createFlags.raw(),
460 Bstr(pszTrgBaseFolder).raw(),
461 bstrSettingsFile.asOutParam()),
462 RTEXITCODE_FAILURE);
463
464 ComPtr<IMachine> trgMachine;
465 CHECK_ERROR_RET(a->virtualBox, CreateMachine(bstrSettingsFile.raw(),
466 Bstr(pszTrgName).raw(),
467 ComSafeArrayAsInParam(groups),
468 NULL,
469 createFlags.raw(),
470 trgMachine.asOutParam()),
471 RTEXITCODE_FAILURE);
472
473 /* Start the cloning */
474 ComPtr<IProgress> progress;
475 CHECK_ERROR_RET(srcMachine, CloneTo(trgMachine,
476 mode,
477 ComSafeArrayAsInParam(options),
478 progress.asOutParam()),
479 RTEXITCODE_FAILURE);
480 rc = showProgress(progress);
481 CHECK_PROGRESS_ERROR_RET(progress, ("Clone VM failed"), RTEXITCODE_FAILURE);
482
483 if (fRegister)
484 CHECK_ERROR_RET(a->virtualBox, RegisterMachine(trgMachine), RTEXITCODE_FAILURE);
485
486 Bstr bstrNewName;
487 CHECK_ERROR_RET(trgMachine, COMGETTER(Name)(bstrNewName.asOutParam()), RTEXITCODE_FAILURE);
488 RTPrintf("Machine has been successfully cloned as \"%ls\"\n", bstrNewName.raw());
489
490 return RTEXITCODE_SUCCESS;
491}
492
493RTEXITCODE handleStartVM(HandlerArg *a)
494{
495 HRESULT rc = S_OK;
496 std::list<const char *> VMs;
497 Bstr sessionType;
498
499 static const RTGETOPTDEF s_aStartVMOptions[] =
500 {
501 { "--type", 't', RTGETOPT_REQ_STRING },
502 { "-type", 't', RTGETOPT_REQ_STRING }, // deprecated
503 };
504 int c;
505 RTGETOPTUNION ValueUnion;
506 RTGETOPTSTATE GetState;
507 // start at 0 because main() has hacked both the argc and argv given to us
508 RTGetOptInit(&GetState, a->argc, a->argv, s_aStartVMOptions, RT_ELEMENTS(s_aStartVMOptions),
509 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
510 while ((c = RTGetOpt(&GetState, &ValueUnion)))
511 {
512 switch (c)
513 {
514 case 't': // --type
515 if (!RTStrICmp(ValueUnion.psz, "gui"))
516 {
517 sessionType = "gui";
518 }
519#ifdef VBOX_WITH_VBOXSDL
520 else if (!RTStrICmp(ValueUnion.psz, "sdl"))
521 {
522 sessionType = "sdl";
523 }
524#endif
525#ifdef VBOX_WITH_HEADLESS
526 else if (!RTStrICmp(ValueUnion.psz, "capture"))
527 {
528 sessionType = "capture";
529 }
530 else if (!RTStrICmp(ValueUnion.psz, "headless"))
531 {
532 sessionType = "headless";
533 }
534#endif
535 else
536 sessionType = ValueUnion.psz;
537 break;
538
539 case VINF_GETOPT_NOT_OPTION:
540 VMs.push_back(ValueUnion.psz);
541 break;
542
543 default:
544 if (c > 0)
545 {
546 if (RT_C_IS_PRINT(c))
547 return errorSyntax(USAGE_STARTVM, "Invalid option -%c", c);
548 else
549 return errorSyntax(USAGE_STARTVM, "Invalid option case %i", c);
550 }
551 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
552 return errorSyntax(USAGE_STARTVM, "unknown option: %s\n", ValueUnion.psz);
553 else if (ValueUnion.pDef)
554 return errorSyntax(USAGE_STARTVM, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
555 else
556 return errorSyntax(USAGE_STARTVM, "error: %Rrs", c);
557 }
558 }
559
560 /* check for required options */
561 if (VMs.empty())
562 return errorSyntax(USAGE_STARTVM, "at least one VM name or uuid required");
563
564 for (std::list<const char *>::const_iterator it = VMs.begin();
565 it != VMs.end();
566 ++it)
567 {
568 HRESULT rc2 = rc;
569 const char *pszVM = *it;
570 ComPtr<IMachine> machine;
571 CHECK_ERROR(a->virtualBox, FindMachine(Bstr(pszVM).raw(),
572 machine.asOutParam()));
573 if (machine)
574 {
575 Bstr env;
576#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
577 /* make sure the VM process will start on the same display as VBoxManage */
578 Utf8Str str;
579 const char *pszDisplay = RTEnvGet("DISPLAY");
580 if (pszDisplay)
581 str = Utf8StrFmt("DISPLAY=%s\n", pszDisplay);
582 const char *pszXAuth = RTEnvGet("XAUTHORITY");
583 if (pszXAuth)
584 str.append(Utf8StrFmt("XAUTHORITY=%s\n", pszXAuth));
585 env = str;
586#endif
587 ComPtr<IProgress> progress;
588 CHECK_ERROR(machine, LaunchVMProcess(a->session, sessionType.raw(),
589 env.raw(), progress.asOutParam()));
590 if (SUCCEEDED(rc) && !progress.isNull())
591 {
592 RTPrintf("Waiting for VM \"%s\" to power on...\n", pszVM);
593 CHECK_ERROR(progress, WaitForCompletion(-1));
594 if (SUCCEEDED(rc))
595 {
596 BOOL completed = true;
597 CHECK_ERROR(progress, COMGETTER(Completed)(&completed));
598 if (SUCCEEDED(rc))
599 {
600 ASSERT(completed);
601
602 LONG iRc;
603 CHECK_ERROR(progress, COMGETTER(ResultCode)(&iRc));
604 if (SUCCEEDED(rc))
605 {
606 if (SUCCEEDED(iRc))
607 RTPrintf("VM \"%s\" has been successfully started.\n", pszVM);
608 else
609 {
610 ProgressErrorInfo info(progress);
611 com::GluePrintErrorInfo(info);
612 }
613 rc = iRc;
614 }
615 }
616 }
617 }
618 }
619
620 /* it's important to always close sessions */
621 a->session->UnlockMachine();
622
623 /* make sure that we remember the failed state */
624 if (FAILED(rc2))
625 rc = rc2;
626 }
627
628 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
629}
630
631RTEXITCODE handleDiscardState(HandlerArg *a)
632{
633 HRESULT rc;
634
635 if (a->argc != 1)
636 return errorSyntax(USAGE_DISCARDSTATE, "Incorrect number of parameters");
637
638 ComPtr<IMachine> machine;
639 CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
640 machine.asOutParam()));
641 if (machine)
642 {
643 do
644 {
645 /* we have to open a session for this task */
646 CHECK_ERROR_BREAK(machine, LockMachine(a->session, LockType_Write));
647 do
648 {
649 ComPtr<IMachine> sessionMachine;
650 CHECK_ERROR_BREAK(a->session, COMGETTER(Machine)(sessionMachine.asOutParam()));
651 CHECK_ERROR_BREAK(sessionMachine, DiscardSavedState(true /* fDeleteFile */));
652 } while (0);
653 CHECK_ERROR_BREAK(a->session, UnlockMachine());
654 } while (0);
655 }
656
657 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
658}
659
660RTEXITCODE handleAdoptState(HandlerArg *a)
661{
662 HRESULT rc;
663
664 if (a->argc != 2)
665 return errorSyntax(USAGE_ADOPTSTATE, "Incorrect number of parameters");
666
667 ComPtr<IMachine> machine;
668 CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
669 machine.asOutParam()));
670 if (machine)
671 {
672 char szStateFileAbs[RTPATH_MAX] = "";
673 int vrc = RTPathAbs(a->argv[1], szStateFileAbs, sizeof(szStateFileAbs));
674 if (RT_FAILURE(vrc))
675 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Cannot convert filename \"%s\" to absolute path: %Rrc", a->argv[0], vrc);
676
677 do
678 {
679 /* we have to open a session for this task */
680 CHECK_ERROR_BREAK(machine, LockMachine(a->session, LockType_Write));
681 do
682 {
683 ComPtr<IMachine> sessionMachine;
684 CHECK_ERROR_BREAK(a->session, COMGETTER(Machine)(sessionMachine.asOutParam()));
685 CHECK_ERROR_BREAK(sessionMachine, AdoptSavedState(Bstr(szStateFileAbs).raw()));
686 } while (0);
687 CHECK_ERROR_BREAK(a->session, UnlockMachine());
688 } while (0);
689 }
690
691 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
692}
693
694RTEXITCODE handleGetExtraData(HandlerArg *a)
695{
696 HRESULT rc = S_OK;
697
698 if (a->argc != 2)
699 return errorSyntax(USAGE_GETEXTRADATA, "Incorrect number of parameters");
700
701 /* global data? */
702 if (!strcmp(a->argv[0], "global"))
703 {
704 /* enumeration? */
705 if (!strcmp(a->argv[1], "enumerate"))
706 {
707 SafeArray<BSTR> aKeys;
708 CHECK_ERROR(a->virtualBox, GetExtraDataKeys(ComSafeArrayAsOutParam(aKeys)));
709
710 for (size_t i = 0;
711 i < aKeys.size();
712 ++i)
713 {
714 Bstr bstrKey(aKeys[i]);
715 Bstr bstrValue;
716 CHECK_ERROR(a->virtualBox, GetExtraData(bstrKey.raw(),
717 bstrValue.asOutParam()));
718
719 RTPrintf("Key: %ls, Value: %ls\n", bstrKey.raw(), bstrValue.raw());
720 }
721 }
722 else
723 {
724 Bstr value;
725 CHECK_ERROR(a->virtualBox, GetExtraData(Bstr(a->argv[1]).raw(),
726 value.asOutParam()));
727 if (!value.isEmpty())
728 RTPrintf("Value: %ls\n", value.raw());
729 else
730 RTPrintf("No value set!\n");
731 }
732 }
733 else
734 {
735 ComPtr<IMachine> machine;
736 CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
737 machine.asOutParam()));
738 if (machine)
739 {
740 /* enumeration? */
741 if (!strcmp(a->argv[1], "enumerate"))
742 {
743 SafeArray<BSTR> aKeys;
744 CHECK_ERROR(machine, GetExtraDataKeys(ComSafeArrayAsOutParam(aKeys)));
745
746 for (size_t i = 0;
747 i < aKeys.size();
748 ++i)
749 {
750 Bstr bstrKey(aKeys[i]);
751 Bstr bstrValue;
752 CHECK_ERROR(machine, GetExtraData(bstrKey.raw(),
753 bstrValue.asOutParam()));
754
755 RTPrintf("Key: %ls, Value: %ls\n", bstrKey.raw(), bstrValue.raw());
756 }
757 }
758 else
759 {
760 Bstr value;
761 CHECK_ERROR(machine, GetExtraData(Bstr(a->argv[1]).raw(),
762 value.asOutParam()));
763 if (!value.isEmpty())
764 RTPrintf("Value: %ls\n", value.raw());
765 else
766 RTPrintf("No value set!\n");
767 }
768 }
769 }
770 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
771}
772
773RTEXITCODE handleSetExtraData(HandlerArg *a)
774{
775 HRESULT rc = S_OK;
776
777 if (a->argc < 2)
778 return errorSyntax(USAGE_SETEXTRADATA, "Not enough parameters");
779
780 /* global data? */
781 if (!strcmp(a->argv[0], "global"))
782 {
783 /** @todo passing NULL is deprecated */
784 if (a->argc < 3)
785 CHECK_ERROR(a->virtualBox, SetExtraData(Bstr(a->argv[1]).raw(),
786 NULL));
787 else if (a->argc == 3)
788 CHECK_ERROR(a->virtualBox, SetExtraData(Bstr(a->argv[1]).raw(),
789 Bstr(a->argv[2]).raw()));
790 else
791 return errorSyntax(USAGE_SETEXTRADATA, "Too many parameters");
792 }
793 else
794 {
795 ComPtr<IMachine> machine;
796 CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
797 machine.asOutParam()));
798 if (machine)
799 {
800 /* open an existing session for the VM */
801 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Shared), RTEXITCODE_FAILURE);
802 /* get the session machine */
803 ComPtr<IMachine> sessionMachine;
804 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(sessionMachine.asOutParam()), RTEXITCODE_FAILURE);
805 /** @todo passing NULL is deprecated */
806 if (a->argc < 3)
807 CHECK_ERROR(sessionMachine, SetExtraData(Bstr(a->argv[1]).raw(),
808 NULL));
809 else if (a->argc == 3)
810 CHECK_ERROR(sessionMachine, SetExtraData(Bstr(a->argv[1]).raw(),
811 Bstr(a->argv[2]).raw()));
812 else
813 return errorSyntax(USAGE_SETEXTRADATA, "Too many parameters");
814 }
815 }
816 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
817}
818
819RTEXITCODE handleSetProperty(HandlerArg *a)
820{
821 HRESULT rc;
822
823 /* there must be two arguments: property name and value */
824 if (a->argc != 2)
825 return errorSyntax(USAGE_SETPROPERTY, "Incorrect number of parameters");
826
827 ComPtr<ISystemProperties> systemProperties;
828 a->virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
829
830 if (!strcmp(a->argv[0], "machinefolder"))
831 {
832 /* reset to default? */
833 if (!strcmp(a->argv[1], "default"))
834 CHECK_ERROR(systemProperties, COMSETTER(DefaultMachineFolder)(NULL));
835 else
836 CHECK_ERROR(systemProperties, COMSETTER(DefaultMachineFolder)(Bstr(a->argv[1]).raw()));
837 }
838 else if (!strcmp(a->argv[0], "hwvirtexclusive"))
839 {
840 bool fHwVirtExclusive;
841
842 if (!strcmp(a->argv[1], "on"))
843 fHwVirtExclusive = true;
844 else if (!strcmp(a->argv[1], "off"))
845 fHwVirtExclusive = false;
846 else
847 return errorArgument("Invalid hwvirtexclusive argument '%s'", a->argv[1]);
848 CHECK_ERROR(systemProperties, COMSETTER(ExclusiveHwVirt)(fHwVirtExclusive));
849 }
850 else if ( !strcmp(a->argv[0], "vrdeauthlibrary")
851 || !strcmp(a->argv[0], "vrdpauthlibrary"))
852 {
853 if (!strcmp(a->argv[0], "vrdpauthlibrary"))
854 RTStrmPrintf(g_pStdErr, "Warning: 'vrdpauthlibrary' is deprecated. Use 'vrdeauthlibrary'.\n");
855
856 /* reset to default? */
857 if (!strcmp(a->argv[1], "default"))
858 CHECK_ERROR(systemProperties, COMSETTER(VRDEAuthLibrary)(NULL));
859 else
860 CHECK_ERROR(systemProperties, COMSETTER(VRDEAuthLibrary)(Bstr(a->argv[1]).raw()));
861 }
862 else if (!strcmp(a->argv[0], "websrvauthlibrary"))
863 {
864 /* reset to default? */
865 if (!strcmp(a->argv[1], "default"))
866 CHECK_ERROR(systemProperties, COMSETTER(WebServiceAuthLibrary)(NULL));
867 else
868 CHECK_ERROR(systemProperties, COMSETTER(WebServiceAuthLibrary)(Bstr(a->argv[1]).raw()));
869 }
870 else if (!strcmp(a->argv[0], "vrdeextpack"))
871 {
872 /* disable? */
873 if (!strcmp(a->argv[1], "null"))
874 CHECK_ERROR(systemProperties, COMSETTER(DefaultVRDEExtPack)(NULL));
875 else
876 CHECK_ERROR(systemProperties, COMSETTER(DefaultVRDEExtPack)(Bstr(a->argv[1]).raw()));
877 }
878 else if (!strcmp(a->argv[0], "loghistorycount"))
879 {
880 uint32_t uVal;
881 int vrc;
882 vrc = RTStrToUInt32Ex(a->argv[1], NULL, 0, &uVal);
883 if (vrc != VINF_SUCCESS)
884 return errorArgument("Error parsing Log history count '%s'", a->argv[1]);
885 CHECK_ERROR(systemProperties, COMSETTER(LogHistoryCount)(uVal));
886 }
887 else if (!strcmp(a->argv[0], "autostartdbpath"))
888 {
889 /* disable? */
890 if (!strcmp(a->argv[1], "null"))
891 CHECK_ERROR(systemProperties, COMSETTER(AutostartDatabasePath)(NULL));
892 else
893 CHECK_ERROR(systemProperties, COMSETTER(AutostartDatabasePath)(Bstr(a->argv[1]).raw()));
894 }
895 else if (!strcmp(a->argv[0], "defaultfrontend"))
896 {
897 Bstr bstrDefaultFrontend(a->argv[1]);
898 if (!strcmp(a->argv[1], "default"))
899 bstrDefaultFrontend.setNull();
900 CHECK_ERROR(systemProperties, COMSETTER(DefaultFrontend)(bstrDefaultFrontend.raw()));
901 }
902 else if (!strcmp(a->argv[0], "logginglevel"))
903 {
904 Bstr bstrLoggingLevel(a->argv[1]);
905 if (!strcmp(a->argv[1], "default"))
906 bstrLoggingLevel.setNull();
907 CHECK_ERROR(systemProperties, COMSETTER(LoggingLevel)(bstrLoggingLevel.raw()));
908 }
909 else
910 return errorSyntax(USAGE_SETPROPERTY, "Invalid parameter '%s'", a->argv[0]);
911
912 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
913}
914
915RTEXITCODE handleSharedFolder(HandlerArg *a)
916{
917 HRESULT rc;
918
919 /* we need at least a command and target */
920 if (a->argc < 2)
921 return errorSyntax(USAGE_SHAREDFOLDER, "Not enough parameters");
922
923 const char *pszMachineName = a->argv[1];
924 ComPtr<IMachine> machine;
925 CHECK_ERROR(a->virtualBox, FindMachine(Bstr(pszMachineName).raw(), machine.asOutParam()));
926 if (!machine)
927 return RTEXITCODE_FAILURE;
928
929 if (!strcmp(a->argv[0], "add"))
930 {
931 /* we need at least four more parameters */
932 if (a->argc < 5)
933 return errorSyntax(USAGE_SHAREDFOLDER_ADD, "Not enough parameters");
934
935 char *name = NULL;
936 char *hostpath = NULL;
937 bool fTransient = false;
938 bool fWritable = true;
939 bool fAutoMount = false;
940
941 for (int i = 2; i < a->argc; i++)
942 {
943 if ( !strcmp(a->argv[i], "--name")
944 || !strcmp(a->argv[i], "-name"))
945 {
946 if (a->argc <= i + 1 || !*a->argv[i+1])
947 return errorArgument("Missing argument to '%s'", a->argv[i]);
948 i++;
949 name = a->argv[i];
950 }
951 else if ( !strcmp(a->argv[i], "--hostpath")
952 || !strcmp(a->argv[i], "-hostpath"))
953 {
954 if (a->argc <= i + 1 || !*a->argv[i+1])
955 return errorArgument("Missing argument to '%s'", a->argv[i]);
956 i++;
957 hostpath = a->argv[i];
958 }
959 else if ( !strcmp(a->argv[i], "--readonly")
960 || !strcmp(a->argv[i], "-readonly"))
961 {
962 fWritable = false;
963 }
964 else if ( !strcmp(a->argv[i], "--transient")
965 || !strcmp(a->argv[i], "-transient"))
966 {
967 fTransient = true;
968 }
969 else if ( !strcmp(a->argv[i], "--automount")
970 || !strcmp(a->argv[i], "-automount"))
971 {
972 fAutoMount = true;
973 }
974 else
975 return errorSyntax(USAGE_SHAREDFOLDER_ADD, "Invalid parameter '%s'", Utf8Str(a->argv[i]).c_str());
976 }
977
978 if (NULL != strstr(name, " "))
979 return errorSyntax(USAGE_SHAREDFOLDER_ADD, "No spaces allowed in parameter '-name'!");
980
981 /* required arguments */
982 if (!name || !hostpath)
983 {
984 return errorSyntax(USAGE_SHAREDFOLDER_ADD, "Parameters --name and --hostpath are required");
985 }
986
987 if (fTransient)
988 {
989 ComPtr<IConsole> console;
990
991 /* open an existing session for the VM */
992 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Shared), RTEXITCODE_FAILURE);
993
994 /* get the session machine */
995 ComPtr<IMachine> sessionMachine;
996 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(sessionMachine.asOutParam()), RTEXITCODE_FAILURE);
997
998 /* get the session console */
999 CHECK_ERROR_RET(a->session, COMGETTER(Console)(console.asOutParam()), RTEXITCODE_FAILURE);
1000 if (console.isNull())
1001 return RTMsgErrorExit(RTEXITCODE_FAILURE,
1002 "Machine '%s' is not currently running.\n", pszMachineName);
1003
1004 CHECK_ERROR(console, CreateSharedFolder(Bstr(name).raw(),
1005 Bstr(hostpath).raw(),
1006 fWritable, fAutoMount));
1007 a->session->UnlockMachine();
1008 }
1009 else
1010 {
1011 /* open a session for the VM */
1012 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Write), RTEXITCODE_FAILURE);
1013
1014 /* get the mutable session machine */
1015 ComPtr<IMachine> sessionMachine;
1016 a->session->COMGETTER(Machine)(sessionMachine.asOutParam());
1017
1018 CHECK_ERROR(sessionMachine, CreateSharedFolder(Bstr(name).raw(),
1019 Bstr(hostpath).raw(),
1020 fWritable, fAutoMount));
1021 if (SUCCEEDED(rc))
1022 CHECK_ERROR(sessionMachine, SaveSettings());
1023
1024 a->session->UnlockMachine();
1025 }
1026 }
1027 else if (!strcmp(a->argv[0], "remove"))
1028 {
1029 /* we need at least two more parameters */
1030 if (a->argc < 3)
1031 return errorSyntax(USAGE_SHAREDFOLDER_REMOVE, "Not enough parameters");
1032
1033 char *name = NULL;
1034 bool fTransient = false;
1035
1036 for (int i = 2; i < a->argc; i++)
1037 {
1038 if ( !strcmp(a->argv[i], "--name")
1039 || !strcmp(a->argv[i], "-name"))
1040 {
1041 if (a->argc <= i + 1 || !*a->argv[i+1])
1042 return errorArgument("Missing argument to '%s'", a->argv[i]);
1043 i++;
1044 name = a->argv[i];
1045 }
1046 else if ( !strcmp(a->argv[i], "--transient")
1047 || !strcmp(a->argv[i], "-transient"))
1048 {
1049 fTransient = true;
1050 }
1051 else
1052 return errorSyntax(USAGE_SHAREDFOLDER_REMOVE, "Invalid parameter '%s'", Utf8Str(a->argv[i]).c_str());
1053 }
1054
1055 /* required arguments */
1056 if (!name)
1057 return errorSyntax(USAGE_SHAREDFOLDER_REMOVE, "Parameter --name is required");
1058
1059 if (fTransient)
1060 {
1061 /* open an existing session for the VM */
1062 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Shared), RTEXITCODE_FAILURE);
1063 /* get the session machine */
1064 ComPtr<IMachine> sessionMachine;
1065 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(sessionMachine.asOutParam()), RTEXITCODE_FAILURE);
1066 /* get the session console */
1067 ComPtr<IConsole> console;
1068 CHECK_ERROR_RET(a->session, COMGETTER(Console)(console.asOutParam()), RTEXITCODE_FAILURE);
1069 if (console.isNull())
1070 return RTMsgErrorExit(RTEXITCODE_FAILURE,
1071 "Machine '%s' is not currently running.\n", pszMachineName);
1072
1073 CHECK_ERROR(console, RemoveSharedFolder(Bstr(name).raw()));
1074
1075 a->session->UnlockMachine();
1076 }
1077 else
1078 {
1079 /* open a session for the VM */
1080 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Write), RTEXITCODE_FAILURE);
1081
1082 /* get the mutable session machine */
1083 ComPtr<IMachine> sessionMachine;
1084 a->session->COMGETTER(Machine)(sessionMachine.asOutParam());
1085
1086 CHECK_ERROR(sessionMachine, RemoveSharedFolder(Bstr(name).raw()));
1087
1088 /* commit and close the session */
1089 CHECK_ERROR(sessionMachine, SaveSettings());
1090 a->session->UnlockMachine();
1091 }
1092 }
1093 else
1094 return errorSyntax(USAGE_SHAREDFOLDER, "Invalid parameter '%s'", Utf8Str(a->argv[0]).c_str());
1095
1096 return RTEXITCODE_SUCCESS;
1097}
1098
1099RTEXITCODE handleExtPack(HandlerArg *a)
1100{
1101 if (a->argc < 1)
1102 return errorNoSubcommand();
1103
1104 ComObjPtr<IExtPackManager> ptrExtPackMgr;
1105 CHECK_ERROR2I_RET(a->virtualBox, COMGETTER(ExtensionPackManager)(ptrExtPackMgr.asOutParam()), RTEXITCODE_FAILURE);
1106
1107 RTGETOPTSTATE GetState;
1108 RTGETOPTUNION ValueUnion;
1109 int ch;
1110 HRESULT hrc = S_OK;
1111
1112 if (!strcmp(a->argv[0], "install"))
1113 {
1114 setCurrentSubcommand(HELP_SCOPE_EXTPACK_INSTALL);
1115 const char *pszName = NULL;
1116 bool fReplace = false;
1117
1118 static const RTGETOPTDEF s_aInstallOptions[] =
1119 {
1120 { "--replace", 'r', RTGETOPT_REQ_NOTHING },
1121 };
1122
1123 RTGetOptInit(&GetState, a->argc, a->argv, s_aInstallOptions, RT_ELEMENTS(s_aInstallOptions), 1, 0 /*fFlags*/);
1124 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
1125 {
1126 switch (ch)
1127 {
1128 case 'r':
1129 fReplace = true;
1130 break;
1131
1132 case VINF_GETOPT_NOT_OPTION:
1133 if (pszName)
1134 return errorSyntax("Too many extension pack names given to \"extpack uninstall\"");
1135 pszName = ValueUnion.psz;
1136 break;
1137
1138 default:
1139 return errorGetOpt(ch, &ValueUnion);
1140 }
1141 }
1142 if (!pszName)
1143 return errorSyntax("No extension pack name was given to \"extpack install\"");
1144
1145 char szPath[RTPATH_MAX];
1146 int vrc = RTPathAbs(pszName, szPath, sizeof(szPath));
1147 if (RT_FAILURE(vrc))
1148 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAbs(%s,,) failed with rc=%Rrc", pszName, vrc);
1149
1150 Bstr bstrTarball(szPath);
1151 Bstr bstrName;
1152 ComPtr<IExtPackFile> ptrExtPackFile;
1153 CHECK_ERROR2I_RET(ptrExtPackMgr, OpenExtPackFile(bstrTarball.raw(), ptrExtPackFile.asOutParam()), RTEXITCODE_FAILURE);
1154 CHECK_ERROR2I_RET(ptrExtPackFile, COMGETTER(Name)(bstrName.asOutParam()), RTEXITCODE_FAILURE);
1155 ComPtr<IProgress> ptrProgress;
1156 CHECK_ERROR2I_RET(ptrExtPackFile, Install(fReplace, NULL, ptrProgress.asOutParam()), RTEXITCODE_FAILURE);
1157 hrc = showProgress(ptrProgress);
1158 CHECK_PROGRESS_ERROR_RET(ptrProgress, ("Failed to install \"%s\"", szPath), RTEXITCODE_FAILURE);
1159
1160 RTPrintf("Successfully installed \"%ls\".\n", bstrName.raw());
1161 }
1162 else if (!strcmp(a->argv[0], "uninstall"))
1163 {
1164 setCurrentSubcommand(HELP_SCOPE_EXTPACK_UNINSTALL);
1165 const char *pszName = NULL;
1166 bool fForced = false;
1167
1168 static const RTGETOPTDEF s_aUninstallOptions[] =
1169 {
1170 { "--force", 'f', RTGETOPT_REQ_NOTHING },
1171 };
1172
1173 RTGetOptInit(&GetState, a->argc, a->argv, s_aUninstallOptions, RT_ELEMENTS(s_aUninstallOptions), 1, 0);
1174 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
1175 {
1176 switch (ch)
1177 {
1178 case 'f':
1179 fForced = true;
1180 break;
1181
1182 case VINF_GETOPT_NOT_OPTION:
1183 if (pszName)
1184 return errorSyntax("Too many extension pack names given to \"extpack uninstall\"");
1185 pszName = ValueUnion.psz;
1186 break;
1187
1188 default:
1189 return errorGetOpt(ch, &ValueUnion);
1190 }
1191 }
1192 if (!pszName)
1193 return errorSyntax("No extension pack name was given to \"extpack uninstall\"");
1194
1195 Bstr bstrName(pszName);
1196 ComPtr<IProgress> ptrProgress;
1197 CHECK_ERROR2I_RET(ptrExtPackMgr, Uninstall(bstrName.raw(), fForced, NULL, ptrProgress.asOutParam()), RTEXITCODE_FAILURE);
1198 hrc = showProgress(ptrProgress);
1199 CHECK_PROGRESS_ERROR_RET(ptrProgress, ("Failed to uninstall \"%s\"", pszName), RTEXITCODE_FAILURE);
1200
1201 RTPrintf("Successfully uninstalled \"%s\".\n", pszName);
1202 }
1203 else if (!strcmp(a->argv[0], "cleanup"))
1204 {
1205 setCurrentSubcommand(HELP_SCOPE_EXTPACK_CLEANUP);
1206 if (a->argc > 1)
1207 return errorTooManyParameters(&a->argv[1]);
1208 CHECK_ERROR2I_RET(ptrExtPackMgr, Cleanup(), RTEXITCODE_FAILURE);
1209 RTPrintf("Successfully performed extension pack cleanup\n");
1210 }
1211 else
1212 return errorUnknownSubcommand(a->argv[0]);
1213
1214 return RTEXITCODE_SUCCESS;
1215}
1216
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette