Skip to content

Commit

Permalink
Fix for AESH-460, lxc container issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdenise committed Mar 7, 2018
1 parent cd23650 commit c09689f
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.aesh.readline.terminal.impl;

import java.io.File;
import org.aesh.terminal.Attributes;
import org.aesh.utils.Config;
import org.aesh.utils.ExecHelper;
Expand Down Expand Up @@ -48,6 +49,9 @@ public class ExecPty implements Pty {

private final String name;

private final boolean validTTYFile;
private static final String NOT_A_TTY = "not a tty";

public static Pty current() throws IOException {
try {
LOGGER.log(Level.FINE,"getting pty: "+OSUtils.TTY_COMMAND);
Expand All @@ -66,6 +70,13 @@ public static Pty current() throws IOException {

protected ExecPty(String name) {
this.name = name;
/*
There are some contexts (eg lxc container) in which tty returns 'not a tty' without
error. This file shouldn't exist on the file system but in case it exists
concider tty file invalid.
*/
validTTYFile = new File(name).exists() && !NOT_A_TTY.equals(name);
LOGGER.log(Level.FINE, "tty file " + name + " valid? " + validTTYFile);
}

@Override
Expand All @@ -89,6 +100,9 @@ public OutputStream getMasterOutput() {
@Override
public InputStream getSlaveInput() throws IOException {
try {
if (!validTTYFile) {
return System.in;
}
return new FileInputStream(getName());
} catch (FileNotFoundException fnfe) {
// When the tty file is not accessible to the current user,
Expand All @@ -100,6 +114,9 @@ public InputStream getSlaveInput() throws IOException {
@Override
public OutputStream getSlaveOutput() throws IOException {
try {
if (!validTTYFile) {
return System.out;
}
return new FileOutputStream(getName());
} catch (FileNotFoundException fnfe) {
// When the tty file is not accessible to the current user,
Expand Down

0 comments on commit c09689f

Please sign in to comment.