[platform] passes the PID to watch for to the restarter script (IDEA-162263)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Tue, 18 Oct 2016 17:43:40 +0000 (19:43 +0200)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Tue, 18 Oct 2016 17:43:40 +0000 (19:43 +0200)
bin/linux/restart.py
platform/platform-impl/src/com/intellij/util/Restarter.java

index 93bf229db65e632dd4dfb4b703816d8d1099b9f6..96397f82b9467ca923d4351082511060eeb4f83c 100755 (executable)
@@ -6,17 +6,17 @@ import os
 import sys
 import time
 
-if len(sys.argv) < 2:
-    raise Exception('At least one argument expected')
+if len(sys.argv) < 3:
+    raise Exception('usage: restart.py <pid> <path> [optional command]')
 
-pid = os.getppid()
+pid = int(sys.argv[1])
 while os.getppid() == pid:
     time.sleep(0.5)
 
-if len(sys.argv) > 2:
-    os.spawnv(os.P_WAIT, sys.argv[2], sys.argv[2:])
+if len(sys.argv) > 3:
+    os.spawnv(os.P_WAIT, sys.argv[3], sys.argv[3:])
 
-to_launch = sys.argv[1]
+to_launch = sys.argv[2]
 if sys.platform == 'darwin':
     os.execv('/usr/bin/open', ['/usr/bin/open', to_launch])
 else:
index ad3fac4234eaf76cde1f1eff7aed522fdadbadda..69610eb6cbe91d823775acaa794182b7e89f8264 100644 (file)
@@ -21,6 +21,7 @@ import com.intellij.openapi.application.PathManager;
 import com.intellij.openapi.util.SystemInfo;
 import com.intellij.openapi.util.io.FileUtilRt;
 import com.intellij.openapi.util.text.StringUtil;
+import com.sun.jna.Library;
 import com.sun.jna.Native;
 import com.sun.jna.Pointer;
 import com.sun.jna.WString;
@@ -46,7 +47,9 @@ public class Restarter {
       return PathManager.getHomePath().contains(".app") && new File(PathManager.getBinPath(), "restarter").canExecute();
     }
     if (SystemInfo.isUnix) {
-      return CreateDesktopEntryAction.getLauncherScript() != null && new File(PathManager.getBinPath(), "restart.py").canExecute();
+      return JnaLoader.isLoaded() &&
+             CreateDesktopEntryAction.getLauncherScript() != null &&
+             new File(PathManager.getBinPath(), "restart.py").canExecute();
     }
 
     return false;
@@ -135,7 +138,12 @@ public class Restarter {
   private static void restartOnUnix(String... beforeRestart) throws IOException {
     String launcherScript = CreateDesktopEntryAction.getLauncherScript();
     if (launcherScript == null) throw new IOException("Launcher script not found in " + PathManager.getBinPath());
+
+    LibC lib = (LibC)Native.loadLibrary("c", LibC.class);
+    int pid = lib.getpid();
+
     doScheduleRestart(new File(PathManager.getBinPath(), "restart.py"), commands -> {
+      commands.add(String.valueOf(pid));
       commands.add(launcherScript);
       Collections.addAll(commands, beforeRestart);
     });
@@ -182,4 +190,9 @@ public class Restarter {
   private interface Shell32 extends StdCallLibrary {
     Pointer CommandLineToArgvW(WString command_line, IntByReference argc);
   }
+
+  @SuppressWarnings("SpellCheckingInspection")
+  private interface LibC extends Library {
+    int getpid();
+  }
 }
\ No newline at end of file