1 On day 09, I passed a file descriptor as an argv,
2 by splitting it into sizeof(int) bytes;
3 but if someone compiled minish and minish-once differently,
4 they could use integers of different size.
5 It is far-fetched and we may not care,
6 but it is interesting that there is no way to inherit a file descriptor
7 that lasts after execv() and does not rely on unreliable conventions.
8 I think the best way is to choose an arbitrary integer, like 113,
9 close() it hoping that close() fails because it was not open,
10 dup2() the file descriptor of the file you want to use to that integer,
11 and then execv() knowing that, in the new program,
12 your chosen integer is going to be
13 the file descriptor of the file you want to use.
15 I chose to avoid having minish-eval as a different program.
16 It is still a different process, though:
17 minish, fork()s, but then, instead of using execv(),
18 it calls a local eval() function.
19 minish-read remains a different program,
20 because I want it to be easily substituted:
21 I plan to implement another one for interactive use.
23 In script mode, minish used to dup2() the script file to stdin.
24 This is completely wrong:
25 if the script launches cat,
26 I do not want cat to read from the following lines of the script.
27 I fix that by using dup2() only in the child process
28 that will execv() into minish-read.
30 I re-enable the ignoring of SIGTTOU before calling tcsetpgrp().
31 I thought it was useless because minish should start in the foreground,
32 but this is true only for the first command:
33 after minish launches it, it put it in the foreground,
34 so when minish calls tcsetpgrp() again it is the background.
39 https://cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF
40 https://usenix.org/system/files/1311_05-08_mickens.pdf