Skip to content

Commit e16931c

Browse files
committed
ssh: add execution timeout option
1 parent 8aea8a4 commit e16931c

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

app/src/main/java/app/trigger/SshDoorSetup.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class SshDoorSetup implements Setup {
3434
public String register_url;
3535
public String ssids;
3636

37+
public int timeout; // milliseconds
38+
3739
public SshDoorSetup(int id, String name) {
3840
this.id = id;
3941
this.name = name;
@@ -55,6 +57,7 @@ public SshDoorSetup(int id, String name) {
5557
this.disabled_image = null;
5658
this.register_url = "";
5759
this.ssids = "";
60+
this.timeout = 5000;
5861
}
5962

6063
@Override

app/src/main/java/app/trigger/ssh/SshRequestHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public void run() {
155155
session.execCommand(command);
156156

157157
// read stdout (drop stderr)
158-
int bytes_read = read(session, buffer, 0, buffer.length);
158+
int bytes_read = read(session, buffer, 0, buffer.length, setup.timeout);
159159
String output = new String(buffer, 0, bytes_read);
160160

161161
Integer ret = session.getExitStatus();
@@ -217,7 +217,7 @@ public void connectionLost(Throwable reason) {
217217
Log.d(TAG, "connectionLost");
218218
}
219219

220-
private static int read(Session session, byte[] buffer, int start, int len) throws IOException {
220+
private static int read(Session session, byte[] buffer, int start, int len, int timeout_ms) throws IOException {
221221
int bytesRead = 0;
222222

223223
if (session == null)
@@ -226,7 +226,7 @@ private static int read(Session session, byte[] buffer, int start, int len) thro
226226
InputStream stdout = session.getStdout();
227227
InputStream stderr = session.getStderr();
228228

229-
int newConditions = session.waitForCondition(conditions, 5000);
229+
int newConditions = session.waitForCondition(conditions, timeout_ms);
230230

231231
if ((newConditions & ChannelCondition.STDOUT_DATA) != 0) {
232232
bytesRead = stdout.read(buffer, start, len);

app/src/main/res/xml/setup.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@
212212
android:persistent="false"
213213
android:inputType="textNoSuggestions" />
214214

215+
<EditTextPreference
216+
android:key="timeout"
217+
android:title="Command Timeout (ms)"
218+
android:persistent="false"
219+
android:inputType="textNoSuggestions"
220+
android:digits="0123456789" />
221+
215222
<EditTextPreference
216223
android:key="ssids"
217224
android:title="@string/setup_ssids"

0 commit comments

Comments
 (0)