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

ios_system should wait for all commands in line #73

Open
yury opened this issue Dec 3, 2018 · 10 comments
Open

ios_system should wait for all commands in line #73

yury opened this issue Dec 3, 2018 · 10 comments

Comments

@yury
Copy link
Contributor

yury commented Dec 3, 2018

Example:

echo 'nice' | ssh host

Currently ios_system exits after first command (echo nice) and start second command (ssh host).
But we already show blink> prompt :)

@holzschu
Copy link
Owner

holzschu commented Dec 3, 2018

Indeed. I see where the problem comes from, but the solution is not obvious. Commands should wait for all commands they have started (either with pipe or fork/exec/system), but not for the others. Making sure the command is not blocked by a command in another terminal is the tricky bit.

I'm going to think about it.

@yury
Copy link
Contributor Author

yury commented Dec 5, 2018

I think this is related issue blinksh/blink#637

@yury
Copy link
Contributor Author

yury commented Dec 6, 2018

May by whole ios_system should be as meta program...

@holzschu
Copy link
Owner

holzschu commented Dec 8, 2018

The two issues were not related, but I have committed a fix for blinksh/blink#637

I'm not sure what you mean by meta program; would you have a pointer to some documentation?

@holzschu
Copy link
Owner

holzschu commented Dec 8, 2018

Fix committed for this issue (f10015f).
It was a bug I introduced with a recent change (introduction of pthread_detach at line 1390 of ios_system.m). We've now reverted to the previous behaviour:

  • wait for the first command in the pipe to terminate (with pthread_join)
  • then wait for the last command in the pipe to terminate (with pthread_join too)
    Which works for these commands, and for multiple pipes too.

The mistake I made was that once a thread has been detached, it cannot be joined again. Now, we don't detach the last command in the pipe, so we can join it later.

@yury
Copy link
Contributor Author

yury commented Dec 8, 2018

Good catch. Ignore my meta program thing :)

Will try it tomorrow

Thank you

@yury
Copy link
Contributor Author

yury commented Dec 9, 2018

Works for me. Thank you!

@yury yury closed this as completed Dec 9, 2018
@yury yury reopened this Dec 10, 2018
@yury
Copy link
Contributor Author

yury commented Dec 10, 2018

echo nice | ssh office cat somehow try to run office cat as command.
ssh is using getopts to parse args, how can I use getopts from ios_system?

If I add sleep(1); before parsing args it works as expected :)

@holzschu
Copy link
Owner

Hmmm.... that's odd.

@yury
Copy link
Contributor Author

yury commented Dec 10, 2018

For a test, I copied getopts from ios_system and make all vars with thread_ prefix. And it works.

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

No branches or pull requests

2 participants