]> git.ipfire.org Git - thirdparty/shadow.git/commit
Fix vipw not resuming correctly when suspended 189/head
authorTodd C. Miller <Todd.Miller@sudo.ws>
Tue, 12 Nov 2019 02:08:10 +0000 (20:08 -0600)
committerSerge Hallyn <shallyn@cisco.com>
Tue, 12 Nov 2019 02:19:57 +0000 (20:19 -0600)
commit7eca1112fbd7a3eae6a6cbc6e52482a0a8326ff7
treeae0037283825536ab2a51a9a0741e9f58eaa189a
parentfe2a266c50f6b7d06d166d4cf4c3e929df15fd2c
Fix vipw not resuming correctly when suspended

Closes #185

If vipw is suspended (e.g. via control-Z) and then resumed, it often gets
immediately suspended. This is easier to reproduce on a multi-core system.

root@buster:~# /usr/sbin/vipw

[1]+  Stopped                 /usr/sbin/vipw
root@buster:~# fg
/usr/sbin/vipw

[1]+  Stopped                 /usr/sbin/vipw

root@buster:~# fg
[vipw resumes on the second fg]

The problem is that vipw forks a child process and calls waitpid() with the
WUNTRACED flag. When the child process (running the editor) is suspended, the
parent sends itself SIGSTOP to suspend the main vipw process. However, because
the main vipw is in the same process group as the editor which received the ^Z,
the kernel already sent the main vipw SIGTSTP.

If the main vipw receives SIGTSTP before the child, it will be suspended and
then, once resumed, will proceed to suspend itself again.

To fix this, run the child process in its own process group as the foreground
process group. That way, control-Z will only affect the child process and the
parent can use the existing logic to suspend the parent.
src/vipw.c