extern "C" {
#endif
#include "vmware/tools/plugin.h"
+ #include "vmware/tools/threadPool.h"
#ifdef __cplusplus
}
#endif
}
+/*
+ * ---------------------------------------------------------------------------
+ * DeployPkgExecDeploy --
+ *
+ * Start the deploy execution in a new thread.
+ *
+ * Return Value:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ * ---------------------------------------------------------------------------
+ */
+
+void
+DeployPkgExecDeploy(ToolsAppCtx *ctx, // IN: app context
+ void *pkgName) // IN: pkg file name
+{
+ char errMsg[2048];
+ ToolsDeployPkgError ret;
+ gchar *msg;
+ char *pkgNameStr = (char *) pkgName;
+
+ g_debug("%s: Deploypkg deploy task started.\n", __FUNCTION__);
+
+ /* Unpack the package and run the command. */
+ ret = DeployPkgDeployPkgInGuest(pkgNameStr, errMsg, sizeof errMsg);
+ if (ret != TOOLSDEPLOYPKG_ERROR_SUCCESS) {
+ msg = g_strdup_printf("deployPkg.update.state %d %d %s",
+ TOOLSDEPLOYPKG_DEPLOYING,
+ TOOLSDEPLOYPKG_ERROR_DEPLOY_FAILED,
+ errMsg);
+ if (!RpcChannel_Send(ctx->rpc, msg, strlen(msg), NULL, NULL)) {
+ g_warning("%s: failed to send error code %d for state TOOLSDEPLOYPKG_DEPLOYING\n",
+ __FUNCTION__,
+ TOOLSDEPLOYPKG_ERROR_DEPLOY_FAILED);
+ }
+ g_free(msg);
+ g_warning("DeployPkgInGuest failed, error = %d\n", ret);
+ }
+
+ /* Attempt to delete the package file and tempdir. */
+ Log("Deleting file %s\n", pkgNameStr);
+ if (File_Unlink(pkgNameStr) == 0) {
+ char *vol, *dir, *path;
+ File_SplitName(pkgNameStr, &vol, &dir, NULL);
+ path = Str_Asprintf(NULL, "%s%s", vol, dir);
+ if (path != NULL) {
+ Log("Deleting directory %s\n", path);
+ File_DeleteEmptyDirectory(path);
+ free(path);
+ }
+ free(vol);
+ free(dir);
+ } else {
+ g_warning("Unable to delete the file: %s\n", pkgNameStr);
+ }
+}
+
+
/*
*-----------------------------------------------------------------------------
*
- * DeployPkgTcloDeploy --
+ * DeployPkg_TcloDeploy --
*
* TCLO handler for "deployPkg.deploy". Start image guest package deployment.
*
* Return value:
* TRUE if success
- * FALSE if anything failed
+ * FALSE if pkg file path is not valid
*
* Side effects:
* None
gboolean
DeployPkg_TcloDeploy(RpcInData *data) // IN
{
- char errMsg[2048];
- ToolsDeployPkgError ret;
- char *argCopy, *pkgStart, *pkgEnd;
+ char *argCopy, *pkgStart, *pkgEnd, *pkgName;
const char *white = " \t\r\n";
/* Set state to DEPLOYING. */
msg = g_strdup_printf("deployPkg.update.state %d",
TOOLSDEPLOYPKG_DEPLOYING);
if (!RpcChannel_Send(ctx->rpc, msg, strlen(msg), NULL, NULL)) {
- g_warning("%s: failed update state to TOOLSDEPLOYPKG_DEPLOYING\n",
+ g_warning("%s: failed to update state to TOOLSDEPLOYPKG_DEPLOYING\n",
__FUNCTION__);
}
g_free(msg);
TOOLSDEPLOYPKG_ERROR_DEPLOY_FAILED,
pkgStart);
if (!RpcChannel_Send(ctx->rpc, msg, strlen(msg), NULL, NULL)) {
- g_warning("%s: failed update state to TOOLSDEPLOYPKG_DEPLOYING\n",
- __FUNCTION__);
+ g_warning("%s: failed to send error code %d for state TOOLSDEPLOYPKG_DEPLOYING\n",
+ __FUNCTION__,
+ TOOLSDEPLOYPKG_ERROR_DEPLOY_FAILED);
}
g_free(msg);
g_warning("Package file '%s' doesn't exist!!\n", pkgStart);
- goto ExitPoint;
+
+ free(argCopy);
+ return RPCIN_SETRETVALS(data, "failed to get package file", FALSE);
}
- /* Unpack the package and run the command. */
- ret = DeployPkgDeployPkgInGuest(pkgStart, errMsg, sizeof errMsg);
- if (ret != TOOLSDEPLOYPKG_ERROR_SUCCESS) {
+ pkgName = Util_SafeStrdup(pkgStart);
+ if (!ToolsCorePool_SubmitTask(ctx, DeployPkgExecDeploy, pkgName, free)) {
+ g_warning("%s: failed to start deploy execution thread\n",
+ __FUNCTION__);
msg = g_strdup_printf("deployPkg.update.state %d %d %s",
TOOLSDEPLOYPKG_DEPLOYING,
TOOLSDEPLOYPKG_ERROR_DEPLOY_FAILED,
- errMsg);
+ "failed to spawn deploy execution thread");
if (!RpcChannel_Send(ctx->rpc, msg, strlen(msg), NULL, NULL)) {
- g_warning("%s: failed update state to TOOLSDEPLOYPKG_DEPLOYING\n",
- __FUNCTION__);
+ g_warning("%s: failed to send error code %d for state TOOLSDEPLOYPKG_DEPLOYING\n",
+ __FUNCTION__,
+ TOOLSDEPLOYPKG_ERROR_DEPLOY_FAILED);
}
g_free(msg);
- g_warning("DeployPkgInGuest failed, error = %d\n", ret);
- }
-
- ExitPoint:
-
- /* Attempt to delete the package file and tempdir. */
- Log("Deleting file %s\n", pkgStart);
- if (File_Unlink(pkgStart) == 0) {
- char *vol, *dir, *path;
- File_SplitName(pkgStart, &vol, &dir, NULL);
- path = Str_Asprintf(NULL, "%s%s", vol, dir);
- if (path != NULL) {
- Log("Deleting directory %s\n", path);
- File_DeleteEmptyDirectory(path);
- free(path);
- }
- free(vol);
- free(dir);
}
free(argCopy);