Skip to contentSkip to conversation

ioctl01: device check, enable

PATCH In review Petr Vorel 3 participants 13 messages Feb 7, 2023 – Feb 13, 2023

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

cover ioctl01: device check, enable

Hi,

NOTE: the same should be done for ioctl02, but it should be first converted to the new API.

Kind regards,
Petr

Petr Vorel (3):
ioctl01: Add default tty device
ioctl01: Check tty device
runtest/syscalls: Enable ioctl01

 runtest/syscalls                          |  2 +-
 testcases/kernel/syscalls/ioctl/ioctl01.c | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)
Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#1 lore raw

PATCH 1/3 ioctl01: Add default tty device

Saves user to specify it when run manually.

---
 testcases/kernel/syscalls/ioctl/ioctl01.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ioctl/ioctl01.c +4 -1
index 1be38e79d3..cb184aee40 100644
@@ -27,6 +27,7 @@
 #include "lapi/ioctl.h"
 
 #define	INVAL_IOCTL	9999999
+#define	DEFAULT_TTY_DEVICE	"/dev/tty0"
 
 static int fd, fd_file;
 static int bfd = -1;
@@ -70,7 +71,9 @@ static void verify_ioctl(unsigned int i)
 static void setup(void)
 {
 	if (!device)
-		tst_brk(TBROK, "You must specify a tty device with -D option");
+		device = DEFAULT_TTY_DEVICE;
+
+	tst_res(TINFO, "Using device '%s'", device);
 
 	fd = SAFE_OPEN(device, O_RDWR, 0777);
 	fd_file = SAFE_OPEN("x", O_CREAT, 0777);
Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] [PATCH 1/3] ioctl01: Add default tty device

Hi Petr,

Quoted 13 lines · Petr Vorel

Saves user to specify it when run manually.

---
 testcases/kernel/syscalls/ioctl/ioctl01.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ioctl/ioctl01.c +0 -0
index 1be38e79d3..cb184aee40 100644

testcases/kernel/syscalls/ioctl/ioctl01.c line 31

Quoted 5 lines
testcases/kernel/syscalls/ioctl/ioctl01.c +1 -0
@@ -27,6 +27,7 @@
 #include "lapi/ioctl.h"
 
 #define        INVAL_IOCTL     9999999
+#define        DEFAULT_TTY_DEVICE      "/dev/tty0"
 

Hidden the device path parameter is a good idea.

But maybe can we add a function to find available char devices instead of using the tty0 as default? In that function, we do the S_ISCHR() check and return the valid path of it. Then the rest test (e.g. ioctl02) can make use of it but not set the specified device as well. WDYT?

Quoted 19 lines
testcases/kernel/syscalls/ioctl/ioctl01.c +3 -1
 static int fd, fd_file;
 static int bfd = -1;
@@ -70,7 +71,9 @@ static void verify_ioctl(unsigned int i)
 static void setup(void)
 {
        if (!device)
-               tst_brk(TBROK, "You must specify a tty device with -D
 option");
+               device = DEFAULT_TTY_DEVICE;
+
+       tst_res(TINFO, "Using device '%s'", device);
 
        fd = SAFE_OPEN(device, O_RDWR, 0777);
        fd_file = SAFE_OPEN("x", O_CREAT, 0777);

--
2.39.1

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#3 lore raw

Re: [LTP] [PATCH 1/3] ioctl01: Add default tty device

Hi Li,

Quoted 8 lines
Quoted 1 line

+#define DEFAULT_TTY_DEVICE "/dev/tty0"

Hidden the device path parameter is a good idea.

But maybe can we add a function to find available char devices instead of using the tty0 as default? In that function, we do the S_ISCHR() check and return the valid path of it. Then the rest test (e.g. ioctl02) can make use of it but not set the specified device as well. WDYT?

FYI I'm using S_ISCHR() in other patches, which check if device can be used. Implementing search looks like a good idea. Are useful files any /dev/tty* (including /dev/tty, /dev/ttyACM0, /dev/ttyS0) or should I avoid any file or include other paths?

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#4 lore raw

Re: [LTP] [PATCH 1/3] ioctl01: Add default tty device

Quoted 11 lines

Hi Li,

Quoted 8 lines
Quoted 1 line

+#define DEFAULT_TTY_DEVICE "/dev/tty0"

Hidden the device path parameter is a good idea.

But maybe can we add a function to find available char devices instead of using the tty0 as default? In that function, we do the S_ISCHR() check and return the valid path of it. Then the rest test (e.g. ioctl02) can make use of it but not set the specified device as well. WDYT?

Quoted 4 lines

FYI I'm using S_ISCHR() in other patches, which check if device can be used. Implementing search looks like a good idea. Are useful files any /dev/tty* (including /dev/tty, /dev/ttyACM0, /dev/ttyS0) or should I avoid any file or include other paths?

I also wonder if we still want to keep -D parameter (i.e. allow tester to pass a file).

Kind regards,
Petr

Quoted 2 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH 1/3] ioctl01: Add default tty device

Quoted 15 lines · Petr Vorel
Quoted 8 lines

Hi Li,

Quoted 6 lines
Quoted 1 line

+#define DEFAULT_TTY_DEVICE "/dev/tty0"

Hidden the device path parameter is a good idea.

But maybe can we add a function to find available char devices instead of using the tty0 as default? In that function, we do the S_ISCHR()

check

Quoted 1 line
Quoted 1 line

and return the valid path of it. Then the rest test (e.g. ioctl02) can

make

Quoted 3 lines
Quoted 1 line

use of it but not set the specified device as well. WDYT?

FYI I'm using S_ISCHR() in other patches, which check if device can be

used.

Quoted 9 lines
Quoted 1 line

Implementing search looks like a good idea. Are useful files any

/dev/tty*

Quoted 2 lines

(including /dev/tty, /dev/ttyACM0, /dev/ttyS0) or should I avoid any file or include other paths?

I also wonder if we still want to keep -D parameter (i.e. allow tester to pass a
file).

I think there is no necessary keep "-D" parameter since this ioctl01 is to check errno of ioctl(2) syscall, it might meaningless to specify a different char device.

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#6 lore raw

Re: [LTP] [PATCH 1/3] ioctl01: Add default tty device

...

Quoted 8 lines
Quoted 3 lines

I also wonder if we still want to keep -D parameter (i.e. allow tester to pass a
file).

I think there is no necessary keep "-D" parameter since this ioctl01 is to check errno of ioctl(2) syscall, it might meaningless to specify a different char device.

Thx! That makes checking code slightly simpler.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Re: [LTP] [PATCH 1/3] ioctl01: Add default tty device

In reply to Petr Vorel
Quoted 9 lines · Petr Vorel

Hi Li,

Quoted 7 lines
Quoted 1 line

+#define DEFAULT_TTY_DEVICE "/dev/tty0"

Hidden the device path parameter is a good idea.

But maybe can we add a function to find available char devices instead of using the tty0 as default? In that function, we do the S_ISCHR() check and return the valid path of it. Then the rest test (e.g. ioctl02) can

Quoted 9 lines

make

Quoted 1 line

use of it but not set the specified device as well. WDYT?

FYI I'm using S_ISCHR() in other patches, which check if device can be used.
Implementing search looks like a good idea. Are useful files any /dev/tty* (including /dev/tty, /dev/ttyACM0, /dev/ttyS0) or should I avoid any file or include other paths?

It seems not all char devices can be used here. The /dev/tty*Num* should be the first choice.

I tried some of them and only /dev/tty0-N works well, maybe we can just make use of them to avoid no tty0 file failure should be enough. Because my only concern about the hard coding is that "/dev/tty0" is non-exist.

Quoted 5 lines

Kind regards,
Petr

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#8 lore raw

Re: [LTP] [PATCH 1/3] ioctl01: Add default tty device

...

Quoted 9 lines
Quoted 5 lines

FYI I'm using S_ISCHR() in other patches, which check if device can be used.
Implementing search looks like a good idea. Are useful files any /dev/tty* (including /dev/tty, /dev/ttyACM0, /dev/ttyS0) or should I avoid any file or include other paths?

It seems not all char devices can be used here. The /dev/tty*Num* should be the first choice.

+1

I'd also use /dev/tty (in case there is no tty0).

Quoted 4 lines

I tried some of them and only /dev/tty0-N works well, maybe we can just make use of them to avoid no tty0 file failure should be enough. Because my only concern about the hard coding is that "/dev/tty0" is non-exist.

FYI On my system ioctl01 fail on /dev/ttyS0-N (EIO instead of other expected errors). The rest /dev/tty, /dev/tty0-N, /dev/ttyACM0-N work. /dev/ttyACM0-N are just on one of my system, let's not use it.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

Re: [LTP] [PATCH 1/3] ioctl01: Add default tty device

In reply to Petr Vorel
Quoted 8 lines · Petr Vorel

Hi Li,

Quoted 5 lines
Quoted 1 line

+#define DEFAULT_TTY_DEVICE "/dev/tty0"

Hidden the device path parameter is a good idea.

But maybe can we add a function to find available char devices

instead

There is already something like this built into the kernel; you can create a PTY on demand with /dev/ptmx.

See the kernel/pty tests.

Quoted 8 lines
Quoted 3 lines

of using the tty0 as default? In that function, we do the S_ISCHR() check and return the valid path of it. Then the rest test (e.g. ioctl02) can make use of it but not set the specified device as well. WDYT?

FYI I'm using S_ISCHR() in other patches, which check if device can be used. Implementing search looks like a good idea. Are useful files any /dev/tty* (including /dev/tty, /dev/ttyACM0, /dev/ttyS0) or should I avoid any file or include other paths?

These are real serial devices except /dev/tty which could be a real device or a pty IIUC. Same goes for /dev/hvc[0-9] and possibly some others.

I'm going to put the patch set to changes requested because /dev/tty0 is the current virtual console. It seems the test just overwrites the permissions and starts sending ioctls to it.

I don't know if this is safe and probably it's no different from creating a pty.

Quoted 3 lines

Kind regards,
Petr

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#10 lore raw

Re: [LTP] [PATCH 1/3] ioctl01: Add default tty device

Quoted 9 lines
Quoted 5 lines · Petr Vorel

Hi Li,

Quoted 3 lines
Quoted 1 line

+#define DEFAULT_TTY_DEVICE "/dev/tty0"

Hidden the device path parameter is a good idea.

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

But maybe can we add a function to find available char devices

instead

There is already something like this built into the kernel; you can create a PTY on demand with /dev/ptmx.

See the kernel/pty tests.

Thanks for a tip! According to man ptmx(4) the file /dev/ptmx creates pseudoterminal (PTYs) in /dev/pts directory (e.g. /dev/pts/0).

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

of using the tty0 as default? In that function, we do the S_ISCHR() check and return the valid path of it. Then the rest test (e.g. ioctl02) can make use of it but not set the specified device as well. WDYT?

FYI I'm using S_ISCHR() in other patches, which check if device can be used. Implementing search looks like a good idea. Are useful files any /dev/tty* (including /dev/tty, /dev/ttyACM0, /dev/ttyS0) or should I avoid any file or include other paths?

BTW /dev/ttySN are UART serial port TTY (it was familiar to me, although I nowadays use /dev/ttyUSB0 :)).

Quoted 7 lines

These are real serial devices except /dev/tty which could be a real device or a pty IIUC. Same goes for /dev/hvc[0-9] and possibly some others.

I'm going to put the patch set to changes requested because /dev/tty0 is the current virtual console. It seems the test just overwrites the permissions and starts sending ioctls to it.

Sure.

Quoted 2 lines

I don't know if this is safe and probably it's no different from creating a pty.

Kernel doc [1] mentions more about the devices. I suppose it does not matter for ioctl01 purpose, which TTY device we use, so I'll use your suggestion.

Kind regards,
Petr

[1] https://www.kernel.org/doc/html/latest/admin-guide/devices.html

Quoted 2 lines
Quoted 2 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#11 lore raw

PATCH 2/3 ioctl01: Check tty device

In reply to Petr Vorel

tty device must be a char device.

---
 testcases/kernel/syscalls/ioctl/ioctl01.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
testcases/kernel/syscalls/ioctl/ioctl01.c +10 -0
index cb184aee40..5e121ae460 100644
@@ -25,6 +25,7 @@
 #include <termios.h>
 #include "tst_test.h"
 #include "lapi/ioctl.h"
+#include "tst_safe_macros.h"
 
 #define	INVAL_IOCTL	9999999
 #define	DEFAULT_TTY_DEVICE	"/dev/tty0"
@@ -70,11 +71,20 @@ static void verify_ioctl(unsigned int i)
 
 static void setup(void)
 {
+	struct stat st;
+
 	if (!device)
 		device = DEFAULT_TTY_DEVICE;
 
 	tst_res(TINFO, "Using device '%s'", device);
 
+	if (access(device, F_OK))
+		tst_brk(TCONF, "Device '%s' does not exist", device);
+
+	SAFE_STAT(device, &st);
+	if (!S_ISCHR(st.st_mode))
+		tst_brk(TCONF, "Device '%s' is not a char device", device);
+
 	fd = SAFE_OPEN(device, O_RDWR, 0777);
 	fd_file = SAFE_OPEN("x", O_CREAT, 0777);
 }
Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#12 lore raw

PATCH 3/3 runtest/syscalls: Enable ioctl01

In reply to Petr Vorel

ioctl01 needs tty device. We check that in 2 previous commits, thus it can be safely enabled by default.

NOTE: the same should be done for ioctl02, but it should be first converted to the new API.

---
 runtest/syscalls | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
runtest/syscalls +1 -1
index ae37a1192a..c4287c3e90 100644
@@ -543,8 +543,8 @@ getxattr05 getxattr05
 init_module01 init_module01
 init_module02 init_module02
 
+ioctl01 ioctl01
 #Needs tty device.
-#ioctl01 ioctl01 -D /dev/tty0
 #ioctl02 ioctl02 -D /dev/tty0
 
 # Introducing ioctl tests for all /dev/tty* devices
Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp