~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to guestd/toolsDaemon.c

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2008-08-15 21:21:40 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080815212140-05fhxj8wroosysmj
Tags: 2008.08.08-109361-1ubuntu1
* Merge from Debian unstable (LP: #258393), remaining Ubuntu change:
  - add ubuntu_toolchain_FTBFS.dpatch patch, fix FTBFS
* Update ubuntu_toolchain_FTBFS.dpatch patch for the new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#   include <windows.h>
42
42
#   include "win95.h"
43
43
#   include "win32u.h"
 
44
#   include "hgfsUsabilityLib.h"
44
45
#endif
45
46
 
46
47
 
78
79
#include "deployPkg.h"
79
80
#endif
80
81
 
 
82
#ifdef TOOLSDAEMON_HAS_RESOLUTION
 
83
#   include "resolution.h"
 
84
#endif
 
85
 
81
86
/* in 1/100 of a second */
82
87
#define RPCIN_POLL_TIME      10
83
88
/* sync the time once a minute */
86
91
/*
87
92
 * Table mapping state changes to their conf file names.
88
93
 */
 
94
/*
 
95
 * Bug 294328:  Mac OS guests do not (yet) support the state change RPCs.
 
96
 */
 
97
#ifndef __APPLE__
89
98
static const char *stateChgConfNames[] = {
90
99
   NULL,                     /* NONE */
91
100
   CONFNAME_POWEROFFSCRIPT,  /* HALT */
94
103
   CONFNAME_RESUMESCRIPT,    /* RESUME */
95
104
   CONFNAME_SUSPENDSCRIPT,   /* SUSPEND */
96
105
};
 
106
#endif
97
107
 
98
108
DblLnkLst_Links *ToolsDaemonEventQueue = NULL;  // main loop event queue
99
109
static char *guestTempDirectory = NULL;
164
174
      hostSecs = bp.out.ax.word;
165
175
   }
166
176
   hostUsecs = bp.out.bx.word;
 
177
 
 
178
   /*
 
179
    * maxTimeLag is computed by the VMX as the sum of two things:
 
180
    * 1) A threshold that keeps the tools from being over eager about
 
181
    *    resetting the time when it is only a little bit off.
 
182
    * 2) The current backlog of timer interrupts that still need to be
 
183
    *    delivered to the guest.
 
184
    */
167
185
   maxTimeLag = bp.out.cx.word;
168
186
 
169
187
   if (hostSecs <= 0) {
197
215
#endif
198
216
 
199
217
   /*
200
 
    * Adjust the guest OS time to equal the host OS time if the
201
 
    * difference is significant
 
218
    * Adjust the guest OS time to equal the host OS time if:
 
219
    * 1) The guest OS is behind the host OS by more than maxTimeLag.
 
220
    * 2) The guest OS is ahead of the host OS and syncBackward
 
221
    *    is specified. syncBackwards is set to TRUE when the tools
 
222
    *    daemon starts and when the timesync feature is toggled from
 
223
    *    FALSE => TRUE.
202
224
    */
203
 
   if (diff > maxTimeLag || (diff < -maxTimeLag && syncBackward)) {
 
225
   if (diff > maxTimeLag || syncBackward) {
204
226
      if (!System_AddToCurrentTime(diffSecs, diffUsecs)) {
205
227
          Warning("Unable to set the guest OS time: %s.\n\n",
206
228
                  Msg_ErrString());
708
730
 */
709
731
 
710
732
static Bool
711
 
ToolsDaemonTcloReset(char const **result,     // OUT
712
 
                     size_t *resultLen,       // OUT
713
 
                     const char *name,        // IN
714
 
                     const char *args,        // IN
715
 
                     size_t argsSize,         // Ignored
716
 
                     void *clientData)        // Ignored
 
733
ToolsDaemonTcloReset(RpcInData *data)  // IN/OUT
717
734
{
718
735
   /*
719
736
    * Mandatory reset RPC
727
744
    * reinitialize the channel if appropriate. [greg]
728
745
    */
729
746
   EventManager_Add(ToolsDaemonEventQueue, (int) (RPCIN_POLL_TIME * 1.5),
730
 
                    ToolsDaemonResetSent, clientData);
 
747
                    ToolsDaemonResetSent, data->clientData);
731
748
 
732
 
   return RpcIn_SetRetVals(result, resultLen, "ATR " TOOLS_DAEMON_NAME,
733
 
                           TRUE);
 
749
   return RPCIN_SETRETVALS(data, "ATR " TOOLS_DAEMON_NAME, TRUE);
734
750
}
735
751
 
736
752
 
800
816
 
801
817
 
802
818
/*
 
819
 * Bug 294328:  Mac OS guests do not (yet) support the state change RPCs.
 
820
 */
 
821
#ifndef __APPLE__
 
822
/*
803
823
 *-----------------------------------------------------------------------------
804
824
 *
805
825
 * ToolsDaemonTcloStateChange --
825
845
                           void *clientData)        // IN
826
846
{
827
847
   int i;
 
848
   ProcMgr_ProcArgs procArgs;
828
849
   ToolsDaemon_Data *data = (ToolsDaemon_Data *)clientData;
829
850
 
830
851
   ASSERT(data);
855
876
            return RpcIn_SetRetVals(result, resultLen, "", TRUE);
856
877
         }
857
878
#ifdef N_PLAT_NLM
 
879
         procArgs = NULL;
858
880
         scriptCmd = Str_Asprintf(NULL, "%s", script);
859
881
#elif !defined(_WIN32)
 
882
         procArgs = NULL;
860
883
         ASSERT(data->execLogPath);
861
884
         scriptCmd = Str_Asprintf(NULL, "(%s) 2>&1 >> %s",
862
885
                                  script, data->execLogPath);
863
886
#else
 
887
         /*
 
888
          * Pass the CREATE_NO_WINDOW flag to CreateProcess so that the
 
889
          * cmd.exe window will not be visible to the user in the guest.
 
890
          */
 
891
         memset(&procArgs, 0, sizeof procArgs);
 
892
         procArgs.bInheritHandles = TRUE;
 
893
         procArgs.dwCreationFlags = CREATE_NO_WINDOW;
 
894
 
864
895
         {
865
896
            char systemDir[1024 * 3];
866
 
 
867
897
            Win32U_GetSystemDirectory(systemDir, sizeof systemDir);
868
898
            scriptCmd = Str_Asprintf(NULL, "%s\\cmd.exe /c \"%s\"", systemDir, script);
869
899
         }
875
905
                                    "Could not format cmd to run scritps",
876
906
                                    FALSE);
877
907
         }
878
 
         data->asyncProc = ProcMgr_ExecAsync(scriptCmd, NULL);
 
908
         data->asyncProc = ProcMgr_ExecAsync(scriptCmd, &procArgs);
879
909
 
880
910
         if (data->asyncProc) {
881
911
            data->asyncProcCb = ToolsDaemonStateChangeDone;
900
930
   return RpcIn_SetRetVals(result, resultLen, "Invalid state change command",
901
931
                           FALSE);
902
932
}
 
933
#endif // ifndef __APPLE__
903
934
 
904
935
 
905
936
/*
930
961
#ifdef _WIN32
931
962
   unsigned int minResolutionWidth;
932
963
   unsigned int minResolutionHeight;
 
964
#endif
933
965
   ToolsDaemon_Data *data;
934
966
 
935
967
   data = (ToolsDaemon_Data *)clientData;
936
968
   ASSERT(data);
937
969
 
 
970
#ifdef _WIN32
938
971
   /*
939
972
    * Inform the VMX that we support setting the guest
940
973
    * resolution and display topology. Currently, this only
983
1016
   }
984
1017
#endif
985
1018
 
 
1019
#ifdef TOOLSDAEMON_HAS_RESOLUTION
 
1020
   Resolution_RegisterCaps();
 
1021
#endif
 
1022
 
 
1023
   /*
 
1024
    * Bug 294328:  Mac OS guests do not (yet) support the state change RPCs.
 
1025
    */
 
1026
#ifndef __APPLE__
986
1027
   if (!RpcOut_sendOne(NULL, NULL, "tools.capability.statechange")) {
987
1028
      Debug("ToolsDaemonTcloCapReg: VMware doesn't support tools.capability.statechange. "
988
1029
            "Trying .haltreboot\n");
996
1037
      Debug("ToolsDaemonTcloCapReg: VMX doesn't support "
997
1038
            "tools.capability.softpowerop_retry.");
998
1039
   }
 
1040
#endif  // ifndef __APPLE__
999
1041
 
1000
1042
/*
1001
1043
 * This is a _WIN32 || linux check, with the additional check since linux is
1045
1087
   }
1046
1088
#endif
1047
1089
 
1048
 
   if (!GuestApp_SetVersion()) {
 
1090
   /*
 
1091
    * Send the monolithic Tools version. Using a configuration option, users
 
1092
    * can override the Tools version such that the VMX treats the Tools as not
 
1093
    * to be managed by the VMware platform.
 
1094
    */
 
1095
   if (!RpcOut_sendOne(NULL, NULL, "tools.set.version %u",
 
1096
                       GuestApp_GetDictEntryBool(*data->pConfDict,
 
1097
                                                 CONFNAME_DISABLETOOLSVERSION) ?
 
1098
                       TOOLS_VERSION_UNMANAGED : TOOLS_VERSION_CURRENT)) {
1049
1099
      Debug("Daemon: Error setting tools version during 'Capabilities_Register'"
1050
1100
            "request.\n");
1051
1101
   }
1056
1106
   }
1057
1107
#endif
1058
1108
 
 
1109
#if defined(WIN32)
 
1110
   HgfsUsability_RegisterServiceCaps();
 
1111
#endif
 
1112
 
1059
1113
   return RpcIn_SetRetVals(result, resultLen, "", TRUE);
1060
1114
}
1061
1115
 
1123
1177
                         size_t argsSize,         // Ignored
1124
1178
                         void *clientData)        // IN
1125
1179
{
1126
 
   Bool retVal;
 
1180
   Bool retVal = FALSE;
1127
1181
   char *option;
1128
1182
   char *value;
1129
1183
   unsigned int index = 0;
1169
1223
      if (strcmp(value, "1") != 0 && strcmp(value, "0") != 0) {
1170
1224
         goto invalid_value;
1171
1225
      }
 
1226
   } else if (strcmp(option, TOOLSOPTION_LINK_ROOT_HGFS_SHARE) == 0) {
 
1227
      /*
 
1228
       * Check to make sure that we actually support creating the link
 
1229
       * on this platform.
 
1230
       */
 
1231
      if (!data->linkHgfsCB || !data->unlinkHgfsCB) {
 
1232
         goto invalid_option;
 
1233
      }
 
1234
 
 
1235
      if (strcmp(value, "1") != 0 && strcmp(value, "0") != 0) {
 
1236
         goto invalid_value;
 
1237
      }
1172
1238
   } else {
1173
1239
      goto invalid_option;
1174
1240
   }
1264
1330
            }
1265
1331
         }
1266
1332
      }
 
1333
   } else if (strcmp(option, TOOLSOPTION_LINK_ROOT_HGFS_SHARE) == 0) {
 
1334
      if (strcmp(value, "1") == 0) {
 
1335
         /* Validated that data->linkHgfsCB existed above. */
 
1336
         retVal = data->linkHgfsCB(data->linkHgfsCBData);
 
1337
      } else if (strcmp(value, "0") == 0) {
 
1338
         /* Validated that data->unlinkHgfsCB existed above. */
 
1339
         retVal = data->unlinkHgfsCB(data->unlinkHgfsCBData);
 
1340
      }
 
1341
 
 
1342
      if (!retVal) {
 
1343
         RpcIn_SetRetVals(result, resultLen,
 
1344
                          "Could not link/unlink root share.",
 
1345
                          retVal = FALSE);
 
1346
         goto exit;
 
1347
      }
1267
1348
   }
1268
1349
 
1269
1350
   /* success! */
1335
1416
Bool
1336
1417
ToolsDaemon_Init_Backdoor(ToolsDaemon_Data * data) // IN/OUT
1337
1418
{
1338
 
   int i;
1339
 
 
1340
1419
   data->in = RpcIn_Construct(ToolsDaemonEventQueue);
1341
1420
   if (data->in == NULL) {
1342
1421
      Warning("Unable to create the RpcIn object.\n\n");
1367
1446
   RpcIn_RegisterCallback(data->in, "Set_Option",
1368
1447
                          ToolsDaemonTcloSetOption, data);
1369
1448
 
1370
 
   for (i = 0; i < ARRAYSIZE(stateChangeCmdTable); i++) {
1371
 
      RpcIn_RegisterCallback(data->in, stateChangeCmdTable[i].tcloCmd,
1372
 
                             ToolsDaemonTcloStateChange, data);
 
1449
   /*
 
1450
    * Bug 294328:  Mac OS guests do not (yet) support the state change RPCs.
 
1451
    */
 
1452
#ifndef __APPLE__
 
1453
   {
 
1454
      int i;
 
1455
      for (i = 0; i < ARRAYSIZE(stateChangeCmdTable); i++) {
 
1456
         RpcIn_RegisterCallback(data->in, stateChangeCmdTable[i].tcloCmd,
 
1457
                                ToolsDaemonTcloStateChange, data);
 
1458
      }
1373
1459
   }
 
1460
#endif // ifndef __APPLE__
1374
1461
 
1375
1462
#if !defined(N_PLAT_NLM)
1376
1463
   FoundryToolsDaemon_RegisterRoutines(data->in,
1386
1473
   }
1387
1474
#endif
1388
1475
 
 
1476
#ifdef TOOLSDAEMON_HAS_RESOLUTION
 
1477
   Resolution_InitBackdoor(data->in);
 
1478
#endif
 
1479
 
1389
1480
#if !defined(__FreeBSD__) && !defined(sun) && !defined(N_PLAT_NLM)
1390
1481
   DeployPkg_Register(data->in);
1391
1482
#endif
1412
1503
 */
1413
1504
 
1414
1505
ToolsDaemon_Data *
1415
 
ToolsDaemon_Init(GuestApp_Dict **pConfDict,     // IN
1416
 
                 const char *execLogPath,       // IN
1417
 
                 ToolsDaemon_Callback haltCB,   // IN
1418
 
                 void *haltCBData,              // IN
1419
 
                 ToolsDaemon_Callback rebootCB, // IN
1420
 
                 void *rebootCBData,            // IN
1421
 
                 ToolsDaemon_Callback resetCB,  // IN
1422
 
                 void *resetCBData)             // IN
 
1506
ToolsDaemon_Init(GuestApp_Dict **pConfDict,         // IN
 
1507
                 const char *execLogPath,           // IN
 
1508
                 ToolsDaemon_Callback haltCB,       // IN
 
1509
                 void *haltCBData,                  // IN
 
1510
                 ToolsDaemon_Callback rebootCB,     // IN
 
1511
                 void *rebootCBData,                // IN
 
1512
                 ToolsDaemon_Callback resetCB,      // IN
 
1513
                 void *resetCBData,                 // IN
 
1514
                 ToolsDaemon_Callback linkHgfsCB,   // IN
 
1515
                 void *linkHgfsCBData,              // IN
 
1516
                 ToolsDaemon_Callback unlinkHgfsCB, // IN
 
1517
                 void *unlinkHgfsCBData)            // IN
1423
1518
{
1424
1519
   ToolsDaemon_Data *data;
1425
1520
 
1446
1541
   data->lastFailedStateChg = GUESTOS_STATECHANGE_NONE;
1447
1542
   data->resetCB = resetCB;
1448
1543
   data->resetCBData = resetCBData;
 
1544
   data->linkHgfsCB = linkHgfsCB;
 
1545
   data->linkHgfsCBData = linkHgfsCBData;
 
1546
   data->unlinkHgfsCB = unlinkHgfsCB;
 
1547
   data->unlinkHgfsCBData = unlinkHgfsCBData;
1449
1548
   data->timeSyncPeriod = 0;
1450
1549
 
1451
1550
#if ALLOW_TOOLS_IN_FOREIGN_VM
1454
1553
   }
1455
1554
#endif
1456
1555
 
1457
 
#ifdef VMX86_DEBUG
 
1556
#if defined(VMX86_DEBUG) && !defined(__APPLE__)
1458
1557
   {
1459
1558
      int i;
1460
1559
 
1474
1573
      goto error;
1475
1574
   }
1476
1575
 
 
1576
#ifdef TOOLSDAEMON_HAS_RESOLUTION
 
1577
   if (!Resolution_Init(TOOLS_DAEMON_NAME, NULL)) {
 
1578
      Debug("%s: Unable to initialize Guest Fit feature\n", __func__);
 
1579
   }
 
1580
#endif
 
1581
 
1477
1582
   /*
1478
1583
    * Load the conf file, then setup a periodic check and reload.
1479
1584
    */
1588
1693
   if (!RpcOut_sendOne(NULL, NULL, "tools.capability.resolution_min 0 0")) {
1589
1694
      Debug("%s: Unable to clear minimum resolution\n", __FUNCTION__);
1590
1695
   }
 
1696
 
 
1697
   HgfsUsability_UnregisterServiceCaps();
 
1698
#endif
 
1699
 
 
1700
#ifdef TOOLSDAEMON_HAS_RESOLUTION
 
1701
   Resolution_Cleanup();
1591
1702
#endif
1592
1703
 
1593
1704
#if defined(_WIN32) || defined(linux)