Message ID | 20220519121056.1181-2-mdoucha@suse.cz |
---|---|
State | Accepted |
Headers | show |
Series | [1/2] pty07: Resize console to the same size as before | expand |
Hi Martin, Li, Cyril, > 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. Reviewed-by: Petr Vorel <pvorel@suse.cz> Thanks a lot. As and obvious fix I'm going to merge it later today. BTW C API would deserve (after the release) TBROK on -i0, which is already implemented in shell API: df01 1 TBROK: Number of iterations (-i) must be > 0 Kind regards, Petr
On 20. 05. 22 11:01, Petr Vorel wrote: > BTW C API would deserve (after the release) TBROK on -i0, which is already > implemented in shell API: > df01 1 TBROK: Number of iterations (-i) must be > 0 I don't see why. Running pty07 with -i0 was actually quite helpful in debugging this issue. If a test fails when executed with -i0, it needs to be fixed.
> On 20. 05. 22 11:01, Petr Vorel wrote: > > BTW C API would deserve (after the release) TBROK on -i0, which is already > > implemented in shell API: > > df01 1 TBROK: Number of iterations (-i) must be > 0 > I don't see why. Running pty07 with -i0 was actually quite helpful in > debugging this issue. If a test fails when executed with -i0, it needs > to be fixed. Do you mean that -i0 is useful to test only setup and cleanup in C API? If we agree we want this (not against it if it's useful), shell API should be unified with it (my concern was that both APIs should behave the same on the same getopt option). Kind regards, Petr
Hi! > > I don't see why. Running pty07 with -i0 was actually quite helpful in > > debugging this issue. If a test fails when executed with -i0, it needs > > to be fixed. > Do you mean that -i0 is useful to test only setup and cleanup in C API? > If we agree we want this (not against it if it's useful), shell API should > be unified with it (my concern was that both APIs should behave the same on > the same getopt option). It never occured to me that -i0 can be used to test that setup and cleanup are coded properly but it makes a lot of sense.
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
> Hi! > > > I don't see why. Running pty07 with -i0 was actually quite helpful in > > > debugging this issue. If a test fails when executed with -i0, it needs > > > to be fixed. > > Do you mean that -i0 is useful to test only setup and cleanup in C API? > > If we agree we want this (not against it if it's useful), shell API should > > be unified with it (my concern was that both APIs should behave the same on > > the same getopt option). > It never occured to me that -i0 can be used to test that setup and > cleanup are coded properly but it makes a lot of sense. OK, I might send a patch for shell implementing it, but it has a lower priority (there are other patches which should make it to get into the release than this). Kind regards, Petr
Hi all, merged this one, thanks Martin! Kind regards, Petr
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(); }
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(-)