summaryrefslogtreecommitdiffstats
path: root/node-maintainer
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@oath.com>2017-09-13 16:26:17 +0200
committerValerij Fredriksen <valerijf@oath.com>2017-09-13 16:26:17 +0200
commit1ccec0ac4324ae63a0758838577e52f4d80edfd5 (patch)
tree6824be212487c5fadd5f9d2f0fa741a39637e5cb /node-maintainer
parentb4b5b51eec0bf08855b6e62d65275deddae7decc (diff)
Fix coredump handler
Diffstat (limited to 'node-maintainer')
-rw-r--r--node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoreCollector.java22
-rw-r--r--node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/CoreCollectorTest.java10
2 files changed, 21 insertions, 11 deletions
diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoreCollector.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoreCollector.java
index 86ef43b5bea..4681010940c 100644
--- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoreCollector.java
+++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoreCollector.java
@@ -59,18 +59,25 @@ public class CoreCollector {
Path readBinPathFallback(Path coredumpPath) throws IOException, InterruptedException {
String command = GDB_PATH + " -n -batch -core " + coredumpPath + " | grep \'^Core was generated by\'";
- Pair<Integer, String> result = processExecuter.exec(new String[]{"sh", "-c", command});
+ String[] wrappedCommand = new String[] {"/bin/sh", "-c", command};
+ Pair<Integer, String> result = processExecuter.exec(wrappedCommand);
Matcher matcher = CORE_GENERATOR_PATH_PATTERN.matcher(result.getSecond());
if (! matcher.find()) {
- throw new RuntimeException("Failed to extract binary path from " + result);
+ throw new RuntimeException(String.format("Failed to extract binary path from GDB, result: %s, command: %s",
+ result, Arrays.toString(wrappedCommand)));
}
return Paths.get(matcher.group("path").split(" ")[0]);
}
Path readBinPath(Path coredumpPath) throws IOException, InterruptedException {
+ String[] command = new String[] {"file", coredumpPath.toString()};
try {
- Pair<Integer, String> result = processExecuter.exec(new String[]{"file", coredumpPath.toString()});
+ Pair<Integer, String> result = processExecuter.exec(command);
+
+ if (result.getFirst() != 0) {
+ throw new RuntimeException("file command failed with " + result);
+ }
Matcher execfnMatcher = EXECFN_PATH_PATTERN.matcher(result.getSecond());
if (execfnMatcher.find()) {
@@ -82,7 +89,8 @@ public class CoreCollector {
return Paths.get(fromMatcher.group("path").split(" ")[0]);
}
} catch (Throwable e) {
- logger.log(Level.WARNING, "Failed getting bin path, trying fallback instead", e);
+ logger.log(Level.WARNING, String.format("Failed getting bin path, command: %s. " +
+ "Trying fallback instead", Arrays.toString(command)), e);
}
return readBinPathFallback(coredumpPath);
@@ -90,10 +98,10 @@ public class CoreCollector {
List<String> readBacktrace(Path coredumpPath, Path binPath, boolean allThreads) throws IOException, InterruptedException {
String threads = allThreads ? "thread apply all bt" : "bt";
- Pair<Integer, String> result = processExecuter.exec(
- new String[]{GDB_PATH, "-n", "-ex", threads, "-batch", binPath.toString(), coredumpPath.toString()});
+ String[] command = new String[]{GDB_PATH, "-n", "-ex", threads, "-batch", binPath.toString(), coredumpPath.toString()};
+ Pair<Integer, String> result = processExecuter.exec(command);
if (result.getFirst() != 0) {
- throw new RuntimeException("Failed to read backtrace " + result);
+ throw new RuntimeException("Failed to read backtrace " + result + ", Command: " + Arrays.toString(command));
}
return Arrays.asList(result.getSecond().split("\n"));
}
diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/CoreCollectorTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/CoreCollectorTest.java
index 227467f64d9..6e308e0201e 100644
--- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/CoreCollectorTest.java
+++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/CoreCollectorTest.java
@@ -90,7 +90,7 @@ public class CoreCollectorTest {
Path fallbackResponse = Paths.get("/response/from/fallback");
- mockExec(new String[]{"sh", "-c", GDB_PATH + " -n -batch -core /tmp/core.1234 | grep '^Core was generated by'"},
+ mockExec(new String[]{"/bin/sh", "-c", GDB_PATH + " -n -batch -core /tmp/core.1234 | grep '^Core was generated by'"},
"Core was generated by `/response/from/fallback'.");
mockExec(cmd,
"/tmp/core.1234: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style");
@@ -102,7 +102,7 @@ public class CoreCollectorTest {
@Test
public void extractsBinaryPathUsingGdbTest() throws IOException, InterruptedException {
- final String[] cmd = new String[]{"sh", "-c",
+ final String[] cmd = new String[]{"/bin/sh", "-c",
GDB_PATH + " -n -batch -core /tmp/core.1234 | grep '^Core was generated by'"};
mockExec(cmd, "Core was generated by `/usr/bin/program-from-gdb --identity foo/search/cluster.content_'.");
@@ -113,7 +113,8 @@ public class CoreCollectorTest {
coreCollector.readBinPathFallback(TEST_CORE_PATH);
fail("Expected not to be able to get bin path");
} catch (RuntimeException e) {
- assertEquals(e.getMessage(), "Failed to extract binary path from (1,Error 123)");
+ assertEquals("Failed to extract binary path from GDB, result: (1,Error 123), command: " +
+ "[/bin/sh, -c, /opt/vespa/bin64/gdb -n -batch -core /tmp/core.1234 | grep '^Core was generated by']", e.getMessage());
}
}
@@ -129,7 +130,8 @@ public class CoreCollectorTest {
coreCollector.readBacktrace(TEST_CORE_PATH, TEST_BIN_PATH, false);
fail("Expected not to be able to read backtrace");
} catch (RuntimeException e) {
- assertEquals("Failed to read backtrace (1,Failure)", e.getMessage());
+ assertEquals("Failed to read backtrace (1,Failure), Command: " +
+ "[/opt/vespa/bin64/gdb, -n, -ex, bt, -batch, /usr/bin/program, /tmp/core.1234]", e.getMessage());
}
}