holzschu / ios_system

Drop-in replacement for system() in iOS programs
BSD 3-Clause "New" or "Revised" License
898 stars 146 forks source link

`ios_system` should wait for all commands in line #73

Open yury opened 5 years ago

yury commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

I think this is related issue blinksh/blink#637

yury commented 5 years ago

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

holzschu commented 5 years ago

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 commented 5 years ago

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:

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 commented 5 years ago

Good catch. Ignore my meta program thing :)

Will try it tomorrow

Thank you

yury commented 5 years ago

Works for me. Thank you!

yury commented 5 years ago

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 commented 5 years ago

Hmmm.... that's odd.

yury commented 5 years ago

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