Jelajahi Sumber

HADOOP-13467. Shell#getSignalKillCommand should use the bash builtin on Linux. (Arpit Agarwal)

Arpit Agarwal 8 tahun lalu
induk
melakukan
365a27099c

+ 8 - 3
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java

@@ -311,11 +311,16 @@ public abstract class Shell {
       }
       }
     }
     }
 
 
+    // Use the bash-builtin instead of the Unix kill command (usually
+    // /bin/kill) as the bash-builtin supports "--" in all Hadoop supported
+    // OSes.
+    final String quotedPid = bashQuote(pid);
     if (isSetsidAvailable) {
     if (isSetsidAvailable) {
-      // Use the shell-builtin as it support "--" in all Hadoop supported OSes
-      return new String[] {"kill", "-" + code, "--", "-" + pid};
+      return new String[] { "bash", "-c", "kill -" + code + " -- -" +
+          quotedPid };
     } else {
     } else {
-      return new String[] {"kill", "-" + code, pid };
+      return new String[] { "bash", "-c", "kill -" + code + " " +
+          quotedPid };
     }
     }
   }
   }
 
 

+ 8 - 4
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java

@@ -240,9 +240,11 @@ public class TestShell extends Assert {
       expectedCommand =
       expectedCommand =
           new String[]{getWinUtilsPath(), "task", "isAlive", anyPid };
           new String[]{getWinUtilsPath(), "task", "isAlive", anyPid };
     } else if (Shell.isSetsidAvailable) {
     } else if (Shell.isSetsidAvailable) {
-      expectedCommand = new String[] {"kill", "-0", "--", "-" + anyPid };
+      expectedCommand = new String[] { "bash", "-c", "kill -0 -- -'" +
+            anyPid + "'"};
     } else {
     } else {
-      expectedCommand = new String[] {"kill", "-0", anyPid };
+      expectedCommand = new String[] {"bash", "-c", "kill -0 '" + anyPid +
+            "'" };
     }
     }
     Assert.assertArrayEquals(expectedCommand, checkProcessAliveCommand);
     Assert.assertArrayEquals(expectedCommand, checkProcessAliveCommand);
   }
   }
@@ -260,9 +262,11 @@ public class TestShell extends Assert {
       expectedCommand =
       expectedCommand =
           new String[]{getWinUtilsPath(), "task", "kill", anyPid };
           new String[]{getWinUtilsPath(), "task", "kill", anyPid };
     } else if (Shell.isSetsidAvailable) {
     } else if (Shell.isSetsidAvailable) {
-      expectedCommand = new String[] {"kill", "-9", "--", "-" + anyPid };
+      expectedCommand = new String[] { "bash", "-c", "kill -9 -- -'" + anyPid +
+            "'"};
     } else {
     } else {
-      expectedCommand = new String[] {"kill", "-9", anyPid };
+      expectedCommand = new String[]{ "bash", "-c", "kill -9 '" + anyPid +
+            "'"};
     }
     }
     Assert.assertArrayEquals(expectedCommand, checkProcessAliveCommand);
     Assert.assertArrayEquals(expectedCommand, checkProcessAliveCommand);
   }
   }