]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
toolbox-cmd: show full path to current scripts
authorVMware, Inc <>
Thu, 24 Feb 2011 22:54:13 +0000 (14:54 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 24 Feb 2011 22:54:13 +0000 (14:54 -0800)
Let's show full path to scripts when executing
vmware-toolbox-cmd script XXX current

Scripts with relative paths are assumed to be under tools
install dir.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/toolbox/toolboxcmd-scripts.c

index da88bb30366c836b700c35792ace935bc395730d..d9e3f5bec47bba9b34c5a05417eedf9a9ac2f246 100644 (file)
@@ -134,9 +134,10 @@ GetConfEntry(const char *progName,  // IN: program name (argv[0])
              const char *apm,       // IN: apm name
              ScriptType type)       // IN: Script type (default or current)
 {
-   gchar *entry = NULL;
-   GKeyFile *confDict = NULL;
+   gchar *entry;
+   GKeyFile *confDict;
    const char *confName;
+   int len;
    int ret;
 
    confName = GetConfName(apm);
@@ -149,16 +150,42 @@ GetConfEntry(const char *progName,  // IN: program name (argv[0])
 
    confDict = LoadConfFile();
 
-   if (type == Default) {
-      entry = g_strdup(GuestApp_GetDefaultScript(confName));
-   } else if (type == Current) {
+   switch (type) {
+   case Current:
       entry = g_key_file_get_string(confDict, "powerops", confName, NULL);
-      if (entry == NULL) {
-         entry = g_strdup(GuestApp_GetDefaultScript(confName));
+      if (entry) {
+         break;
       }
+      /* Fall through */
+
+   default:
+      entry = g_strdup(GuestApp_GetDefaultScript(confName));
+      break;
    }
 
-   if (strlen(entry) > 0) {
+   len = strlen(entry);
+   if (len > 0) {
+
+      /* If script path is not absolute, assume the Tools install path. */
+      if (!g_path_is_absolute(entry)) {
+         char *defaultPath = GuestApp_GetInstallPath();
+         char *tmp;
+         Bool quoted;
+
+         ASSERT(defaultPath != NULL);
+
+         /* Cope with old configs that added quotes around script paths. */
+         quoted = (entry[0] == '"' && entry[len - 1] == '"');
+         tmp = g_strdup_printf("%s%c%.*s", defaultPath, DIRSEPC,
+                                quoted ? len - 2 : len,
+                                quoted ? entry + 1 : entry);
+
+         vm_free(defaultPath);
+
+         g_free(entry);
+         entry = tmp;
+      }
+
       g_print("%s\n", entry);
       ret = EXIT_SUCCESS;
    } else {