From dabb708a8cab6746fc912d95f0024c4c0b5b8d10 Mon Sep 17 00:00:00 2001 From: Nick Patavalis Date: Sat, 20 Jan 2018 13:19:51 +0200 Subject: [PATCH] Explicitly unlock tty_fd before exiting Call flock(fd, LOCK_UN) explicitly for managed file at term_exitfunc(). This should, normally, not be necessary. Normally, exiting the program should take care of unlocking the file. Unfortuntelly, it has been observed that, on some systems, exiting or closing an flock(2)'ed tty fd has peculiar side effects (like not reseting the modem-control lines, even if HUPCL is set). --- term.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/term.c b/term.c index aea1a64..e905ba6 100644 --- a/term.c +++ b/term.c @@ -35,6 +35,9 @@ #include #include #include +#ifdef USE_FLOCK +#include +#endif /* glibc for MIPS has its own bits/termios.h which does not define * CMSPAR, so we use the value from the generic bits/termios.h @@ -407,6 +410,17 @@ term_exitfunc (void) fprintf(stderr, "%s: reset failed for dev %s: %s\r\n", __FUNCTION__, tname, strerror(errno)); } +#ifdef USE_FLOCK + /* Explicitly unlock the file. If the file is not in fact + flock(2)'ed, no harm is done. This should normally not + be necessary. Normally, exiting the program should take + care of unlocking the file. Unfortuntelly, it has been + observed that, on some systems, exiting or closing an + flock(2)'ed tty fd has peculiar side effects (like not + reseting the modem-control lines, even if HUPCL is + set). */ + flock(term.fd[i], LOCK_UN); +#endif term.fd[i] = -1; } } while (0);