Add the programs ␀ and pack
[minish.git] / Devember / log11.txt
blob3af189147229678cb4c3fe95fc2275f668bc8912
1 Yesterday, i said today I would write
2 about the trickiness of changing the group of the child processes.
3 There are a two time constraints:
4 1. the child processes must change group before using execv(),
5    because minish-eval and minish-read do not know
6    whether the shell is in interactive mode
7    and the parent cannot change their group
8    after they have used execv().
9 2. the first child process must create its own process group
10    before the other child process can get into it;
11 From 3, we deduce that the child processes should change their group;
12 But, from 2, we deduce that
13 the second child must ensure that the first child already did it.
14 If the parent fork()s for the second time
15 after the first child changes its group,
16 then the second child does not need to check anything.
17 What surprised me is that the parent does not need to check
18 whether its first child changed its process group,
19 it can just change it for it.
20 If the child already used execv(), the parent gets an error;
21 so, both the parent and the child need to change the first child group.
23 minish design is broken.
24 minish-eval has its stdin connected to minish-read, via a pipe.
25 After minish-eval uses execv(), though,
26 I would like its stdin to be same it is for minish,
27 but there is no way to undo the call to dup2().
28 I could make minish-eval read the output of minish-read
29 from another file descriptor,
30 passing its bytes as arguments as I did for minish-once.
31 and close() it before execv()ing into the command to be executed.
32 I could even dup2() to a known file descriptor, for example 3,
33 but our system may be using it as a standard file descriptor;
34 minish does not use it and neither does minish-eval,
35 but this is no excuse to break it for the commands to be executed.
37 Enough for today.
39 Suggested reading:
40 https://en.wikipedia.org/wiki/Restrict