Opened 11 years ago

Closed 4 years ago

#3417 closed bug (fixed)

tcsetpgrp() causes the shell "bsh" to hang infinitely while trying to set tty process group

Reported by: schily Owned by: axeld
Priority: normal Milestone: R1
Component: System/Kernel Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: yes Platform: All

Description

bsh forks and the child process calls tcsetpgrp() in order to set the TTY process group of the child to the child process. This is needed in order to redirect signals only to the child.

after bsh calls tcsetpgrp(), tcsetpgrp() calls ioctl() and hangs inside the ioctl.

Workaround: edit the Makefile for bsh and comment out the line with -DJOBCONTROL

Note that bsh worked without problems on Zeta.

bsh is inside the schily source consolidation at:

ftp://ftp.berlios.de/pub/schily/schily-dist/preliminary-2.tar.bz2

The named file is the first version that was ported to Haiku

Attachments (2)

0001-kernel-Don-t-send-SIGTTOU-if-calling-thread-is-block.patch (1.4 KB ) - added by simonsouth 4 years ago.
Don't send SIGTTOU if the calling thread is blocking it
tcsetpgrp-test.c (1.3 KB ) - added by simonsouth 4 years ago.
Short program that demonstrates the problem and the fix

Download all attachments as: .zip

Change History (8)

by simonsouth, 4 years ago

Don't send SIGTTOU if the calling thread is blocking it

comment:1 by simonsouth, 4 years ago

Has a Patch: set

comment:2 by simonsouth, 4 years ago

I've added a patch that should fix this problem.

When a member of a background process group tries to change the foreground process group of its controlling terminal, POSIX says SIGTTOU should be sent unless the process is ignoring it or the calling thread is blocking it. The existing code checked the former case but not the latter, which meant the calling thread could get stuck in a loop while the system call was continually restarted.

by simonsouth, 4 years ago

Attachment: tcsetpgrp-test.c added

Short program that demonstrates the problem and the fix

comment:3 by simonsouth, 4 years ago

I've also added a program that demonstrates the problem. Without the patch applied, the program will terminate normally when invoked directly but loop forever when invoked using either strace or the debugger (as it moves itself to a background process group). With the patch applied the program will terminate normally in both cases.

comment:4 by diver, 4 years ago

Component: - GeneralSystem/Kernel
Version: R1/pre-alpha1R1/Development

comment:5 by jessicah, 4 years ago

waddlesplash, looks good to merge to me :)

comment:6 by waddlesplash, 4 years ago

Resolution: fixed
Status: newclosed

Appplied in hrev49672. Thanks!

Note: See TracTickets for help on using tickets.