VirtualBox

Changeset 99773 in vbox


Ignore:
Timestamp:
May 12, 2023 12:13:40 PM (17 months ago)
Author:
vboxsync
Message:

Guest Control/VBoxManage: Cleaned up argv0 handling with the "run" and "start" sub commands, so that they behave again like in older VBox versions (bugref:9320):

  • Added a "--arg0" parameter to explicitly specify a special argument 0.
  • Added more documentation and an example to the reference.
  • The final arguments will be printed in verbose mode (for easier debugging).
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/manual/en_US/man_VBoxManage-guestcontrol.xml

    r99498 r99773  
    5555      </group>
    5656      <arg choice="plain">run</arg>
     57      <arg>--arg0=<replaceable>argument 0</replaceable></arg>
    5758      <arg>--domain=<replaceable>domainname</replaceable></arg>
    5859      <arg>--dos2unix</arg>
     
    9091      </group>
    9192      <arg choice="plain">start</arg>
     93      <arg>--arg0=<replaceable>argument 0</replaceable></arg>
    9294      <arg>--domain=<replaceable>domainname</replaceable></arg>
    9395      <arg>--exe=<replaceable>filename</replaceable></arg>
     
    13671369--username user1 --passwordfile pw.txt
    13681370</screen>
     1371    <para>
     1372      The following <command>VBoxManage guestcontrol run</command>
     1373      command executes a <command>/usr/bin/busybox -l /usr</command>
     1374      command on the <literal>My OL VM</literal> Oracle Linux VM as the
     1375      <literal>user1</literal> user, explicitly using <literal>ls</literal>
     1376      as argument 0.
     1377    </para>
     1378<screen>
     1379$ VBoxManage --nologo guestcontrol "My OL VM" run --exe "/usr/bin/busybox" \
     1380--username user1 --passwordfile pw.txt --wait-stdout --arg0 ls -- -l /usr
     1381</screen>
     1382    <para>
     1383      The <option>--exe</option> option specifies the absolute path of
     1384      the command to run in the guest VM, <filename>/usr/bin/busybox</filename>.
     1385      Use the <option>--</option> option to pass any arguments that
     1386      follow it to the <command>busybox</command> command.
     1387    </para>
     1388    <para>
     1389      Use the <option>--username</option> option to specify the user
     1390      name, <literal>user1</literal> and use the
     1391      <option>--passwordfile</option> option to specify the name of a
     1392      file that includes the password for the <literal>user1</literal>
     1393      user, <filename>pw.txt</filename>.
     1394    </para>
     1395    <para>
     1396      The <option>--wait-stdout</option> option waits for the
     1397      <command>ls</command> guest process to complete before providing
     1398      the exit code and the command output. The
     1399      <option>--nologo</option> option suppresses the output of the logo
     1400      information.
     1401    </para>
     1402    <para>
     1403      The <option>--arg0</option> option explicitly specifies the argument 0
     1404      to use for the command to execute.
     1405    </para>
     1406  <para>
     1407    The default behavior of argument 0 is to either use
     1408    the value from <option>--exe</option>, or, if not set, the first
     1409    value passed after <option>--</option>.
     1410  </para>       
    13691411  </refsect1>
    13701412</refentry>
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp

    r99754 r99773  
    11701170    {
    11711171        GCTLCMD_COMMON_OPTION_DEFS()
     1172        { "--arg0",                         '0',                                      RTGETOPT_REQ_STRING  },
    11721173        { "--cwd",                          'C',                                      RTGETOPT_REQ_STRING  },
    11731174        { "--putenv",                       'E',                                      RTGETOPT_REQ_STRING  },
     
    12011202    com::SafeArray<IN_BSTR>                 aEnv;
    12021203    const char *                            pszImage            = NULL;
     1204    const char *                            pszArg0             = NULL; /* Argument 0 to use. pszImage will be used if not specified. */
    12031205    const char *                            pszCwd              = NULL;
    12041206    bool                                    fWaitForStdOut      = fRunCmd;
     
    12411243                case kGstCtrlRunOpt_Profile:
    12421244                    aCreateFlags.push_back(ProcessCreateFlag_Profile);
     1245                    break;
     1246
     1247                case '0':
     1248                    pszArg0 = ValueUnion.psz;
    12431249                    break;
    12441250
     
    12901296
    12911297                case VINF_GETOPT_NOT_OPTION:
    1292                     aArgs.push_back(Bstr(ValueUnion.psz).raw());
     1298                    /* VINF_GETOPT_NOT_OPTION comes after all options have been specified;
     1299                     * so if pszImage still is zero at this stage, we use the first non-option found
     1300                     * as the image being executed. */
    12931301                    if (!pszImage)
    1294                     {
    1295                         Assert(aArgs.size() == 1);
    12961302                        pszImage = ValueUnion.psz;
    1297                     }
     1303                    else /* Add anything else to the arguments vector. */
     1304                        aArgs.push_back(Bstr(ValueUnion.psz).raw());
    12981305                    break;
    12991306
     
    13071314        if (!pszImage || !*pszImage)
    13081315            return errorSyntax(GuestCtrl::tr("No executable specified!"));
     1316
     1317        /* Set the arg0 argument (descending precedence):
     1318         *   - If an argument 0 is explicitly specified (via "--arg0"), use this as argument 0.
     1319         *   - When an image is specified explicitly (via "--exe <image>"), use <image> as argument 0.
     1320         *     Note: This is (and ever was) the default behavior users expect, so don't change this! */
     1321        if (pszArg0)
     1322            aArgs.push_front(Bstr(pszArg0).raw());
     1323        else
     1324            aArgs.push_front(Bstr(pszImage).raw());
     1325
     1326        if (pCtx->cVerbose) /* Print the final execution parameters in verbose mode. */
     1327        {
     1328            RTPrintf(GuestCtrl::tr("Executing:\n  Image : %s\n"), pszImage);
     1329            for (size_t i = 0; i < aArgs.size(); i++)
     1330                RTPrintf(GuestCtrl::tr("  arg[%d]: %ls\n"), i, aArgs[i]);
     1331        }
     1332        /* No altering of aArgs and/or pszImage after this point! */
    13091333
    13101334        /*
Note: See TracChangeset for help on using the changeset viewer.

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