In fact, looks like there are two bugs in the code: 1) per tty_ioctl's documentation, the TIOCSCTTY option requires an int argument, while none is provided here. Adding a zero solves the invalid argument problem (the only value mentioned is 1 and it is for root only) NOTE: because of the way the documentation is formatted, it is easy to treat the description for TIOCNOTTY - which says about a void argument - as the second part for TIOCSCTTY. 3) Once the invalid argument is resolved, we'll face the...