[LTP] [PATCH 2/2] pty04: Fix cleanup
Martin Doucha
mdoucha@suse.cz
Thu May 19 14:10:56 CEST 2022
If pty04 gets executed with -i0 argument, the sk file descriptor will
stay zero and cleanup() will close stdin, which can result in the parent
shell logging out. Initialize global file descriptors to -1 and only
clean up those that were left open by the test.
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
testcases/kernel/pty/pty04.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/testcases/kernel/pty/pty04.c b/testcases/kernel/pty/pty04.c
index 00b714c82..c2510d8fe 100644
--- a/testcases/kernel/pty/pty04.c
+++ b/testcases/kernel/pty/pty04.c
@@ -92,7 +92,7 @@ static struct ldisc_info ldiscs[] = {
{N_SLCAN, "N_SLCAN", CAN_MTU},
};
-static int ptmx, pts, sk, mtu, no_check;
+static int ptmx = -1, pts = -1, sk = -1, mtu, no_check;
static int set_ldisc(int tty, const struct ldisc_info *ldisc)
{
@@ -455,9 +455,14 @@ static void do_test(unsigned int n)
static void cleanup(void)
{
- ioctl(pts, TIOCVHANGUP);
- ioctl(ptmx, TIOCVHANGUP);
- close(sk);
+ if (pts >= 0)
+ ioctl(pts, TIOCVHANGUP);
+
+ if (ptmx >= 0)
+ ioctl(ptmx, TIOCVHANGUP);
+
+ if (sk >= 0)
+ close(sk);
tst_reap_children();
}
--
2.36.0
More information about the ltp
mailing list