commit 04a194c013e6566d4e00a022528e9ff667865662
parent ee4cdc8d6e8b1463f726178a86b5a575eff8c510
Author: bakkeby <bakkeby@gmail.com>
Date: Mon, 12 Jul 2021 09:25:52 +0200
newterm: dwm swallow compatibility
There is a compatibility issue between the dwm swallow patch and the
newterm patch for st.
The swallow patch identifies the terminal client to substitute by
traversing the process tree checking if the new window is a descendant
of a terminal client.
The newterm patch for st spawns a new terminal that is a descendant of
the parent st process.
This can lead to situations where the swallow patch ends up replacing
the wrong terminal window.
Changed the forking mechanism to do a double fork and letting the
first one die. This is a technique commonly used by daemons to spawn
new orphan processes.
Diffstat:
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/patch/newterm.c b/patch/newterm.c
@@ -7,9 +7,19 @@ newterm(const Arg* a)
die("fork failed: %s\n", strerror(errno));
break;
case 0:
- res = chdir(getcwd_by_pid(pid));
- execlp("st", "./st", NULL);
- break;
+ switch (fork()) {
+ case -1:
+ die("fork failed: %s\n", strerror(errno));
+ break;
+ case 0:
+ res = chdir(getcwd_by_pid(pid));
+ execlp("st", "./st", NULL);
+ break;
+ default:
+ exit(0);
+ }
+ default:
+ wait(NULL);
}
}