@@ -82,14 +82,17 @@ private static FileDescriptor wrapFileDescriptor(int fileDescriptor) {
82
82
/** Callback which gets notified when a session finishes or changes title. */
83
83
final SessionChangedCallback mChangeCallback ;
84
84
85
- /** The pid of the shell process or -1 if not running. */
85
+ /** The pid of the shell process. 0 if not started and -1 if finished running. */
86
86
int mShellPid ;
87
- int mShellExitStatus = -1 ;
87
+
88
+ /** The exit status of the shell process. Only valid if ${@link #mShellPid} is -1. */
89
+ int mShellExitStatus ;
90
+
88
91
/**
89
92
* The file descriptor referencing the master half of a pseudo-terminal pair, resulting from calling
90
93
* {@link JNI#createSubprocess(String, String, String[], String[], int[])}.
91
94
*/
92
- final int mTerminalFileDescriptor ;
95
+ private int mTerminalFileDescriptor ;
93
96
94
97
/** Set by the application for user identification of session, not by terminal. */
95
98
public String mSessionName ;
@@ -128,20 +131,26 @@ public void handleMessage(Message msg) {
128
131
}
129
132
};
130
133
134
+ private final String mShellPath ;
135
+ private final String mCwd ;
136
+ private final String [] mArgs ;
137
+ private final String [] mEnv ;
138
+
131
139
public TerminalSession (String shellPath , String cwd , String [] args , String [] env , SessionChangedCallback changeCallback ) {
132
140
mChangeCallback = changeCallback ;
133
141
134
- int [] processId = new int [1 ];
135
- mTerminalFileDescriptor = JNI .createSubprocess (shellPath , cwd , args , env , processId );
136
- mShellPid = processId [0 ];
142
+ this .mShellPath = shellPath ;
143
+ this .mCwd = cwd ;
144
+ this .mArgs = args ;
145
+ this .mEnv = env ;
137
146
}
138
147
139
148
/** Inform the attached pty of the new size and reflow or initialize the emulator. */
140
149
public void updateSize (int columns , int rows ) {
141
- JNI .setPtyWindowSize (mTerminalFileDescriptor , rows , columns );
142
150
if (mEmulator == null ) {
143
151
initializeEmulator (columns , rows );
144
152
} else {
153
+ JNI .setPtyWindowSize (mTerminalFileDescriptor , rows , columns );
145
154
mEmulator .resize (columns , rows );
146
155
}
147
156
}
@@ -161,6 +170,11 @@ public String getTitle() {
161
170
*/
162
171
public void initializeEmulator (int columns , int rows ) {
163
172
mEmulator = new TerminalEmulator (this , columns , rows , /* transcript= */ 5000 );
173
+
174
+ int [] processId = new int [1 ];
175
+ mTerminalFileDescriptor = JNI .createSubprocess (mShellPath , mCwd , mArgs , mEnv , processId , rows , columns );
176
+ mShellPid = processId [0 ];
177
+
164
178
final FileDescriptor terminalFileDescriptorWrapped = wrapFileDescriptor (mTerminalFileDescriptor );
165
179
166
180
new Thread ("TermSessionInputReader[pid=" + mShellPid + "]" ) {
@@ -204,7 +218,7 @@ public void run() {
204
218
/** Write data to the shell process. */
205
219
@ Override
206
220
public void write (byte [] data , int offset , int count ) {
207
- mTerminalToProcessIOQueue .write (data , offset , count );
221
+ if ( mShellPid > 0 ) mTerminalToProcessIOQueue .write (data , offset , count );
208
222
}
209
223
210
224
/** Write the Unicode code point to the terminal encoded in UTF-8. */
0 commit comments