ios_system icon indicating copy to clipboard operation
ios_system copied to clipboard

`ios_system` should wait for all commands in line

Open yury opened this issue 6 years ago • 10 comments

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 :)

yury avatar Dec 03 '18 10:12 yury

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.

holzschu avatar Dec 03 '18 11:12 holzschu

I think this is related issue blinksh/blink#637

yury avatar Dec 05 '18 09:12 yury

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

yury avatar Dec 06 '18 19:12 yury

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 avatar Dec 08 '18 14:12 holzschu

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.

holzschu avatar Dec 08 '18 20:12 holzschu

Good catch. Ignore my meta program thing :)

Will try it tomorrow

Thank you

yury avatar Dec 08 '18 21:12 yury

Works for me. Thank you!

yury avatar Dec 09 '18 10:12 yury

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 :)

yury avatar Dec 10 '18 08:12 yury

Hmmm.... that's odd.

holzschu avatar Dec 10 '18 10:12 holzschu

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

yury avatar Dec 10 '18 10:12 yury