| 311 | } |
| 312 | |
| 313 | public void close() throws IOException { |
| 314 | RootShell.log("Request to close shell!"); |
| 315 | |
| 316 | int count = 0; |
| 317 | while (isExecuting) { |
| 318 | RootShell.log("Waiting on shell to finish executing before closing..."); |
| 319 | count++; |
| 320 | |
| 321 | //fail safe |
| 322 | if (count > 10000) { |
| 323 | break; |
| 324 | } |
| 325 | |
| 326 | } |
| 327 | |
| 328 | synchronized (this.commands) { |
| 329 | /** |
| 330 | * instruct the two threads monitoring input and output |
| 331 | * of the shell to close. |
| 332 | */ |
| 333 | this.close = true; |
| 334 | this.notifyThreads(); |
| 335 | } |
| 336 | |
| 337 | RootShell.log("Shell Closed!"); |
| 338 | |
| 339 | if (this == Shell.rootShell) { |
| 340 | Shell.rootShell = null; |
| 341 | } else if (this == Shell.shell) { |
| 342 | Shell.shell = null; |
| 343 | } else if (this == Shell.customShell) { |
| 344 | Shell.customShell = null; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | public static void closeCustomShell() throws IOException { |
| 349 | RootShell.log("Request to close custom shell!"); |