From 881972f1be174d9924ccfd3fb9ece05c3e111af6 Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez-Leon Date: Thu, 19 May 2016 16:32:20 -0400 Subject: [PATCH] Bug 452356 - C/C++ remote launch uses o.e.remote - wait for file permission change When uploading a file to a remote system, the file permissions are updated, however the process taking care of it may not have completed this task before the application tries to use it. This change forces the calling thread to wait for Max 1 sec for it to complete, If the process task takes longer an exception is thrown so the application can provide a meaningful message to the user. A second fix is provided in: execCmdInRemoteShell So this method now makes sure that the remote connection is opened before executing commands over the remote shell. Change-Id: Ibe8bd2709e1b1f446e1f74aa8a3df424ac7fa650 --- .../cdt/launch/remote/RemoteHelper.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RemoteHelper.java b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RemoteHelper.java index 153c174fa46..bc389c24cb2 100644 --- a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RemoteHelper.java +++ b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RemoteHelper.java @@ -17,7 +17,9 @@ package org.eclipse.cdt.launch.remote; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Date; import java.util.List; +import java.util.concurrent.TimeUnit; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.internal.launch.remote.Activator; @@ -113,9 +115,28 @@ public class RemoteHelper { localFile.copy(remoteFile, EFS.OVERWRITE, monitor); // Need to change the permissions to match the original file // permissions because of a bug in upload - remoteShellExec( + Process p = remoteShellExec( config, "", "chmod", "+x " + spaceEscapify(remoteExePath), new SubProgressMonitor(monitor, 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + // Wait if necessary for the permission change + try { + int timeOut = 10; + boolean exited = p.waitFor(timeOut, TimeUnit.SECONDS); + + if (!exited) { + Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, + "Failed to change file permissions in the remote system, path: " + remoteExePath, //$NON-NLS-1$ + null); + throw new CoreException(status); + } + } catch (InterruptedException e) { + Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, + "Interrupted while changing file permissions in the remote system, path: " //$NON-NLS-1$ + + remoteExePath, + e); + throw new CoreException(status); + } } catch (CoreException e) { abort(Messages.RemoteRunLaunchDelegate_6, e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); @@ -200,7 +221,10 @@ public class RemoteHelper { if (!prelaunchCmd.trim().equals("")) //$NON-NLS-1$ remoteCommand = prelaunchCmd + CMD_DELIMITER + remoteCommand; - IRemoteConnection conn = getCurrentConnection(config); + IRemoteConnection conn = getCurrentConnection(config); + if (!conn.isOpen()) { + conn.open(monitor); + } IRemoteCommandShellService shellService = conn.getService(IRemoteCommandShellService.class); IRemoteProcess p = null;