Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make stdin a psuedoterminal when isatty is set #1265

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JakeSiFive
Copy link
Contributor

Sometimes programs check isatty(STDIN_FILENO) in addition to stderr and stdout to determine if they're using a terminal or not. We should support that case as well as we can. We'd need to perform some surgery on shim-wake to support the case where stdin is a file input but it ALSO has input. So for now we treat setting stdin to a file to be just that and not a pseudo-terminal.

if (stdin_fd == -1) {
fprintf(stderr, "open: %s: %s\n", argv[1], strerror(errno));
return 127;
// Because we want to be able to read in both file descirptors and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: descirptors

Comment on lines +157 to +159
if (stdin_fd == -1) {
fprintf(stderr, "open: %s: %s\n", argv[1], strerror(errno));
return 127;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this if after the if/else in case atoi fails for some reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atoi does not tell you if it fails so we can't catch the error :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just meant something like

if (stdin_file[0] == '#') {
    stdin_fd = atoi(stdin_file + 1);
  } else {
    stdin_fd = open(stdin_file, O_RDONLY);
}

if (stdin_fd == -1) {
      fprintf(stderr, "open: %s: %s\n", argv[1], strerror(errno));
      return 127;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's incorrect for the atoi case. The dup/dup2 below will fail if something is wrong with atoi....maybe the reality is that we should not being using atoi because its a terrible interface lol.

@@ -829,9 +829,17 @@ static void launch(JobTable *jobtable) {
jobtable->imp->pipes[stdout_stream[0]] = entry;
jobtable->imp->pipes[stderr_stream[0]] = entry;
clock_gettime(CLOCK_REALTIME, &entry->job->start);
std::string stdin_file_str = "/dev/null";
int stdin_stream[2];
Copy link
Contributor

@V-FEXrt V-FEXrt May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not going to block, but I really think this should be explicit via a tuple data in wakelang.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean exactly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned in chat but something like

data StdInOption =
  DevNull
  Interactive
  File (filename)


def job = 
  makeExecPlan ......
  | setPlanStdinOption DevNull
  | runJob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants