pty: using tcgetattr() to get attributes before re-setting it
PATCH 1/1 pty: using tcgetattr() to get attributes before re-setting it
To fix this error:
tst_test.c:1015: INFO: Timeout per run is 0h 50m 00s pty02.c:42: BROK: tcsetattr() failed: EINVAL
POSIX.1 General description:
Changes the attributes associated with a terminal. New attributes are specified with a termios control structure. Programs should always issue a tcgetattr() first, modify the desired fields, and then issue a tcsetattr(). tcsetattr() should never be issued using a termios structure that was not obtained using tcgetattr(). tcsetattr() should use only a termios structure that was obtained by tcgetattr().
--- testcases/kernel/pty/pty02.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
testcases/kernel/pty/pty02.c +6 -1
@@ -31,13 +31,18 @@static void do_test (void ) { -struct termios io = { .c_lflag =EXTPROC |ICANON }; +struct termios io;int ptmx, pts;char c ='A' ;int nbytes; ptmx =SAFE_OPEN ("/dev/ptmx" ,O_WRONLY ); +if (tcgetattr (ptmx, &io) !=0 ) +tst_brk (TBROK |TERRNO ,"tcgetattr() failed" ); + + io.c_lflag =EXTPROC |ICANON ; +if (tcsetattr (ptmx,TCSANOW , &io) !=0 )tst_brk (TBROK |TERRNO ,"tcsetattr() failed" );
Signature · 1 line
2.9.5
PATCH 1/1 pty: using tcgetattr() to get attributes before re-setting it
Hi Li,
We found other issues by running pty02:
1) The undefined EXTPROC flag led to complier error on RHEL5/6.
2) Based on the fix, reading pts blocked on RHEL6 because we didn't write newline('\n') to ptmx, but it worked well on RHEL7. I am not sure which kernel patch changed this behavior. According canonical mode description:
In canonical mode:
* Input is made available line by line. An input line is available when one of the line delimiters is typed (NL, EOL, EOL2; or EOF at the start of line). Except in the case of EOF, the line delimiter is included in the buffer returned by read(2).
3) Based on the fix, tcsetattr(3) cannot detect invalid EXTPROC flag on RHEL5/6.
Thanks,
Xiao Yang
Quoted 43 lines · Li Wang
To fix this error:
tst_test.c:1015: INFO: Timeout per run is 0h 50m 00s pty02.c:42: BROK:tcsetattr()failed: EINVALPOSIX.1 General description:
Changes the attributes associated with a terminal. New attributes are specified with a termios control structure. Programs should always issue atcgetattr()first, modify the desired fields, and then issue atcsetattr().tcsetattr()should never be issued using a termios structure that was not obtained usingtcgetattr().tcsetattr()should use only a termios structure that was obtained bytcgetattr().Signed-off-by Li Wang<[email protected]>Cc Eric Biggers<[email protected]>Cc Cyril Hrubis<[email protected]>--- testcases/kernel/pty/pty02.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)testcases/kernel/pty/pty02.c +6
-1@@ -31,13 +31,18 @@static void do_test (void ) { -struct termios io = { .c_lflag =EXTPROC |ICANON }; +struct termios io;int ptmx, pts;char c ='A' ;int nbytes; ptmx =SAFE_OPEN ("/dev/ptmx" ,O_WRONLY ); +if (tcgetattr (ptmx,&io) !=0 ) +tst_brk (TBROK |TERRNO ,"tcgetattr() failed" ); + + io.c_lflag =EXTPROC |ICANON ; +if (tcsetattr (ptmx,TCSANOW ,&io) !=0 )tst_brk (TBROK |TERRNO ,"tcsetattr() failed" );
PATCH 1/1 pty: using tcgetattr() to get attributes before re-setting it
Hi Xiao,
Quoted 19 lines · Xiao Yang
Hi Li,
We found other issues by running pty02:
1) The undefined EXTPROC flag led to complier error on RHEL5/6.
2) Based on the fix, reading pts blocked on RHEL6 because we didn't write newline('\n') to ptmx,
but it worked well on RHEL7. I am not sure which kernel patch changed
this behavior.
According canonical mode description:
In canonical mode:
* Input is made available line by line. An input line is available
when one of the line
delimiters is typed (NL, EOL, EOL2; or EOF at the start of
line). Except in the case of EOF,
the line delimiter is included in the buffer returned by read(2).
3) Based on the fix,
tcsetattr(3) cannot detect invalid EXTPROC flag on RHEL5/6.
AFAIK, values of the c_lflag field describe the control of various functions in struct termios,
but it not defined in POSIX and not supported under all Linux. So tcsetattr() cannot detect valid EXTPROC on RHEL5/6 is acceptable I think. Also, the ICANON has different behavior on some kind of UNIX OS too.
To solve these problem, maybe we have to define the EXTPROC in lapi, and skip this test on kernel without that support.
That's what I can think of, if anything wrong, plz correct me.
Thanks,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20180530/dd3bf31c/attachment.html>
PATCH 1/1 pty: using tcgetattr() to get attributes before re-setting it
Hi!
I'm looking into these patches now, so if I get it right we should:
* Add EXTPROC into lapi
* Get the termios value, or it with the requested flags, then apply tcsetattr()
* Exit the test with TCONF if we get EINVAL from tcsetattr()
Would that work for both of you?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 pty: using tcgetattr() to get attributes before re-setting it
Quoted 3 lines · Cyril Hrubis
Hi!
I'm looking into these patches now, so if I get it right we should:
Thanks for taking care of this.
Quoted 8 lines
* Add EXTPROC into lapi
* Get the termios value, or it with the requested flags, then applytcsetattr()
* Exit the test with TCONF if we get EINVAL fromtcsetattr()Would that work for both of you?
I think that's right.
But maybe we have to handle the ICANON nonuniform behavior too.
As YangXiao mentioned that, reading pts will be blocked on rhel6 forever if we don't give
newline('\n') to ptmx, but this issue not exist on rhel7.
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20180816/151d0126/attachment-0001.html>
PATCH 1/1 pty: using tcgetattr() to get attributes before re-setting it
Quoted 20 lines · Li Wang
Quoted 3 lines · Cyril Hrubis
Hi!
I'm looking into these patches now, so if I get it right we should:Thanks for taking care of this.
Quoted 8 lines
* Add EXTPROC into lapi
* Get the termios value, or it with the requested flags, then applytcsetattr()
* Exit the test with TCONF if we get EINVAL fromtcsetattr()Would that work for both of you?
Quoted 9 lines
I think that's right.
But maybe we have to handle the ICANON nonuniform behavior too.
As YangXiao mentioned that, reading pts will be blocked on rhel6 forever if we don't give
newline('\n') to ptmx, but this issue not exist on rhel7.
To avoid the block issue we can just add newline('\n') in the test forwardly, I have confirmed that
won't have any impact on the bug's reproducible in bad(< kernel-4.15) kernel.
I will resend a new patch to fix all these issues above.
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20180816/69b733b6/attachment.html>