You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2021/02/07 21:43:02 UTC
[geode] 01/01: Redirect to/from /dev/null
This is an automated email from the ASF dual-hosted git repository.
jbarrett pushed a commit to branch wip/exec
in repository https://gitbox.apache.org/repos/asf/geode.git
commit 0da69fef873b62bb4a06bcffbc9237251477fca3
Author: Jacob Barrett <jb...@pivotal.io>
AuthorDate: Sun Feb 7 13:41:50 2021 -0800
Redirect to/from /dev/null
---
.../internal/cli/commands/StartLocatorCommand.java | 20 +++++++++++++++++---
.../internal/cli/commands/StartServerCommand.java | 20 +++++++++++++++++---
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
index 859e1d8..ef737bd 100644
--- a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
+++ b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
@@ -15,6 +15,10 @@
package org.apache.geode.management.internal.cli.commands;
+import static java.lang.ProcessBuilder.Redirect.from;
+import static java.lang.ProcessBuilder.Redirect.to;
+import static org.apache.geode.internal.util.IOUtils.close;
+
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
@@ -221,8 +225,9 @@ public class StartLocatorCommand extends OfflineGfshCommand {
final Process locatorProcess =
getProcess(locatorLauncher.getWorkingDirectory(), locatorCommandLine);
- locatorProcess.getInputStream().close();
- locatorProcess.getOutputStream().close();
+ // These should be redirected to /dev/null but close to be safe.
+ close(locatorProcess.getInputStream());
+ close(locatorProcess.getOutputStream());
// fix TRAC bug #51967 by using NON_BLOCKING on Windows
final ProcessStreamReader.ReadingMode readingMode = SystemUtils.isWindows()
@@ -287,6 +292,9 @@ public class StartLocatorCommand extends OfflineGfshCommand {
// stop will close
stderrReader.stopAsync(StartMemberUtils.PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS);
+ // the readers doesn't seem to close so just in case we close here.
+ close(locatorProcess.getErrorStream());
+
// ErrorStream
getGfsh().getSignalHandler().unregisterListener(locatorSignalListener);
}
@@ -346,10 +354,16 @@ public class StartLocatorCommand extends OfflineGfshCommand {
return result;
}
+ static final File DEV_NULL = new File(System.getProperty("os.name")
+ .startsWith("Windows") ? "NUL" : "/dev/null");
+
Process getProcess(String workingDir, String[] locatorCommandLine)
throws IOException {
return new ProcessBuilder(locatorCommandLine)
- .directory(new File(workingDir)).start();
+ .directory(new File(workingDir))
+ .redirectInput(from(DEV_NULL))
+ .redirectOutput(to(DEV_NULL))
+ .start();
}
// TODO should we connect implicitly when in non-interactive, headless mode (e.g. gfsh -e "start
diff --git a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
index 6e4eec8..bd30b14 100644
--- a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
+++ b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
@@ -14,6 +14,10 @@
*/
package org.apache.geode.management.internal.cli.commands;
+import static java.lang.ProcessBuilder.Redirect.from;
+import static java.lang.ProcessBuilder.Redirect.to;
+import static org.apache.geode.internal.util.IOUtils.close;
+
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -349,8 +353,9 @@ public class StartServerCommand extends OfflineGfshCommand {
Process serverProcess =
getProcess(serverLauncher.getWorkingDirectory(), serverCommandLine);
- serverProcess.getInputStream().close();
- serverProcess.getOutputStream().close();
+ // These should be redirected to /dev/null but close to be safe.
+ close(serverProcess.getInputStream());
+ close(serverProcess.getOutputStream());
// fix TRAC bug #51967 by using NON_BLOCKING on Windows
final ProcessStreamReader.ReadingMode readingMode = SystemUtils.isWindows()
@@ -413,8 +418,12 @@ public class StartServerCommand extends OfflineGfshCommand {
} while (!(registeredServerSignalListener && serverSignalListener.isSignaled())
&& serverState.isStartingOrNotResponding());
} finally {
- stderrReader.stopAsync(StartMemberUtils.PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS);
// stop will close ErrorStream
+ stderrReader.stopAsync(StartMemberUtils.PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS);
+
+ // the readers doesn't seem to close so just in case we close here.
+ close(serverProcess.getErrorStream());
+
getGfsh().getSignalHandler().unregisterListener(serverSignalListener);
}
@@ -431,8 +440,13 @@ public class StartServerCommand extends OfflineGfshCommand {
}
}
+ static final File DEV_NULL = new File(System.getProperty("os.name")
+ .startsWith("Windows") ? "NUL" : "/dev/null");
+
Process getProcess(String workingDir, String[] serverCommandLine) throws IOException {
return new ProcessBuilder(serverCommandLine)
+ .redirectInput(from(DEV_NULL))
+ .redirectOutput(to(DEV_NULL))
.directory(new File(workingDir)).start();
}