Hi John,
> Right now, writing a program that acquires a particular terminal as a
> controlling terminal is not easy and I think Gnulib is the right place for
> improvement.
By the use-case that you gave
> write programs that interface with serial devices, such as the NeuG libre
random number generator, GNSS receivers, and embedded GNU/Linux boards. Even
though these aren't human interface devices, some of the semantics of a
controlling terminal are still useful. In particular I'd like SIGHUP semantics
for when a sensor is disconnected or when the device on the other end of a USB
serial adapter is dead. Also, a terminal can only be the controlling terminal
for one session at a time, so this has the perk of being a mutual exclusion
mechanism too.
and the difficulty to do this portably, I agree that Gnulib is a good place
for such code.
Since none of the Gnulib maintainers is very much an expert regarding ttys,
the best way forward would be:
- You have already gone through the investigation on various platforms;
you could synthesize the code for the desired function.
- We would also need some kind of unit tests. Even if they cannot run
automatically, i.e. if they are interactive, it would be the necessary
step to determine whether the code does the expected thing on each
platform (from FreeBSD to Haiku).
- Then you could submit it for inclusion in Gnulib, and once you have
assigned the copyright for it to the FSF [1], we could review and include
it.
> ‣ The login_tty() function is in the LSB and present on most systems
> mentioned above, but it has a couple inappropriate quirks. It calls setsid()
> on behalf of the caller, but if doing the implicit open() then the caller
> needs to do that itself first, and it also clobbers the standard file
> descriptors needlessly.
I agree that what you describe is a subset of what login_tty() does.
> It would be nice if Gnulib had some ctrlterm(int fd) function or the like
I would vote for a function name that has 'tty' in it, like login_tty
or fork_pty. ("tty" if fd refers to the slave, "pty" if it refers to
the master.)
Bruno
[1] https://www.gnu.org/prep/maintain/html_node/Copyright-Papers.html