mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 03:05:18 +08:00
Added: Store pid in ExecutionCommand for sessions and tasks
This commit is contained in:
@@ -58,6 +58,8 @@ public class ExecutionCommand {
|
||||
/** The optional unique id for the {@link ExecutionCommand}. */
|
||||
public Integer id;
|
||||
|
||||
/** The process id of command. */
|
||||
public int mPid = -1;
|
||||
|
||||
/** The current state of the {@link ExecutionCommand}. */
|
||||
private ExecutionState currentState = ExecutionState.PRE_EXECUTION;
|
||||
@@ -266,6 +268,9 @@ public class ExecutionCommand {
|
||||
|
||||
logString.append(executionCommand.getCommandIdAndLabelLogString()).append(":");
|
||||
|
||||
if (executionCommand.mPid != -1)
|
||||
logString.append("\n").append(executionCommand.getPidLogString());
|
||||
|
||||
if (executionCommand.previousState != ExecutionState.PRE_EXECUTION)
|
||||
logString.append("\n").append(executionCommand.getPreviousStateLogString());
|
||||
logString.append("\n").append(executionCommand.getCurrentStateLogString());
|
||||
@@ -358,6 +363,8 @@ public class ExecutionCommand {
|
||||
|
||||
markdownString.append("## ").append(executionCommand.commandLabel).append("\n");
|
||||
|
||||
if (executionCommand.mPid != -1)
|
||||
markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Pid", executionCommand.mPid, "-"));
|
||||
|
||||
markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Previous State", executionCommand.previousState.getName(), "-"));
|
||||
markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Current State", executionCommand.currentState.getName(), "-"));
|
||||
@@ -408,6 +415,10 @@ public class ExecutionCommand {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getPidLogString() {
|
||||
return "Pid: `" + mPid + "`";
|
||||
}
|
||||
|
||||
public String getCurrentStateLogString() {
|
||||
return "Current State: `" + currentState.getName() + "`";
|
||||
}
|
||||
|
@@ -137,16 +137,16 @@ public final class AppShell {
|
||||
* @param context The {@link Context} for operations.
|
||||
*/
|
||||
private void executeInner(@NonNull final Context context) throws IllegalThreadStateException, InterruptedException {
|
||||
final int pid = ShellUtils.getPid(mProcess);
|
||||
mExecutionCommand.mPid = ShellUtils.getPid(mProcess);
|
||||
|
||||
Logger.logDebug(LOG_TAG, "Running \"" + mExecutionCommand.getCommandIdAndLabelLogString() + "\" AppShell with pid " + pid);
|
||||
Logger.logDebug(LOG_TAG, "Running \"" + mExecutionCommand.getCommandIdAndLabelLogString() + "\" AppShell with pid " + mExecutionCommand.mPid);
|
||||
|
||||
mExecutionCommand.resultData.exitCode = null;
|
||||
|
||||
// setup stdin, and stdout and stderr gobblers
|
||||
DataOutputStream STDIN = new DataOutputStream(mProcess.getOutputStream());
|
||||
StreamGobbler STDOUT = new StreamGobbler(pid + "-stdout", mProcess.getInputStream(), mExecutionCommand.resultData.stdout, mExecutionCommand.backgroundCustomLogLevel);
|
||||
StreamGobbler STDERR = new StreamGobbler(pid + "-stderr", mProcess.getErrorStream(), mExecutionCommand.resultData.stderr, mExecutionCommand.backgroundCustomLogLevel);
|
||||
StreamGobbler STDOUT = new StreamGobbler(mExecutionCommand.mPid + "-stdout", mProcess.getInputStream(), mExecutionCommand.resultData.stdout, mExecutionCommand.backgroundCustomLogLevel);
|
||||
StreamGobbler STDERR = new StreamGobbler(mExecutionCommand.mPid + "-stderr", mProcess.getErrorStream(), mExecutionCommand.resultData.stderr, mExecutionCommand.backgroundCustomLogLevel);
|
||||
|
||||
// start gobbling
|
||||
STDOUT.start();
|
||||
@@ -196,9 +196,9 @@ public final class AppShell {
|
||||
|
||||
// Process result
|
||||
if (exitCode == 0)
|
||||
Logger.logDebug(LOG_TAG, "The \"" + mExecutionCommand.getCommandIdAndLabelLogString() + "\" AppShell with pid " + pid + " exited normally");
|
||||
Logger.logDebug(LOG_TAG, "The \"" + mExecutionCommand.getCommandIdAndLabelLogString() + "\" AppShell with pid " + mExecutionCommand.mPid + " exited normally");
|
||||
else
|
||||
Logger.logDebug(LOG_TAG, "The \"" + mExecutionCommand.getCommandIdAndLabelLogString() + "\" AppShell with pid " + pid + " exited with code: " + exitCode);
|
||||
Logger.logDebug(LOG_TAG, "The \"" + mExecutionCommand.getCommandIdAndLabelLogString() + "\" AppShell with pid " + mExecutionCommand.mPid + " exited with code: " + exitCode);
|
||||
|
||||
// If the execution command has already failed, like SIGKILL was sent, then don't continue
|
||||
if (mExecutionCommand.isStateFailed()) {
|
||||
|
@@ -44,6 +44,9 @@ public class TermuxTerminalSessionClientBase implements TerminalSessionClient {
|
||||
public void onTerminalCursorStateChange(boolean state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTerminalShellPid(@NonNull TerminalSession session, int pid) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user