Skip to content

Commit

Permalink
DCA11Y-1145: handle empty SHELL
Browse files Browse the repository at this point in the history
  • Loading branch information
flipatlas committed Oct 11, 2024
1 parent 25a2d87 commit c9c4788
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -92,6 +93,24 @@ private String parseOutput(ByteArrayOutputStream stream) {
}

private String getCurrentShell() {
return System.getenv("SHELL");
String shell = System.getenv("SHELL");
if (shell == null || shell.isEmpty()) {
logger.debug("SHELL is not available in environment variables. Trying to get it from child process.");

ByteArrayOutputStream stdout = new ByteArrayOutputStream();
try {
execute(Arrays.asList("echo", "$SHELL"), stdout, stdout);
shell = parseOutput(stdout);
} catch (ProcessExecutionException e) {
throw new RuntimeException(e);
}

if (shell.isEmpty()) {
logger.debug("SHELL was not available in child process. Falling back to bin/sh");
shell = "/bin/sh";
}
}

return shell;
}
}

0 comments on commit c9c4788

Please sign in to comment.