Bug 2214075 - statserial can loop
Summary: statserial can loop
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: statserial
Version: 39
Hardware: Unspecified
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Tim Waugh
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-06-11 16:51 UTC by Jaroslav Škarvada
Modified: 2023-08-16 08:10 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Jaroslav Škarvada 2023-06-11 16:51:12 UTC
There is incorrect optimization in the code that relies on the fact that the TIOCMGET ioctl cannot get value 0 in the arg. It seems this may happen e.g. with the tty0tty null modem emulator, where the "arg == old_status" check is always true (because old_status is explicitly initialized to 0) causing statserial to loops even with the "-n" argument. I will PR workaround patch.

Reproducible: Always

Steps to Reproduce:
1. modprobe tty0tty
2. statserial -n /dev/tnt0
3.
Actual Results:  
It loops until serial status is changed.

Expected Results:  
It returns the status of the serial port.

Incorrect code:
  unsigned int old_status = 0;  /* value of previous call */
  unsigned int arg;             /* value returned by ioctl */
...
  for (;;) {
    /* get modem status info */
    status = ioctl(fd, TIOCMGET, &arg);
...
    /* avoid unneccessary screen updates */
    if (arg == old_status)
    {
      sleep(1);
      continue;
    }
    old_status = arg;
...
For "arg" being "0" we have the loop.

Strace:
openat(AT_FDCWD, "/dev/tnt1", O_RDONLY) = 3
ioctl(3, TIOCMGET, [0])                 = 0
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=1, tv_nsec=0}, 0x7ffc316de900) = 0
ioctl(3, TIOCMGET, [0])                 = 0
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=1, tv_nsec=0}, 0x7ffc316de900) = 0
ioctl(3, TIOCMGET, [0])                 = 0
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=1, tv_nsec=0}, 0x7ffc316de900) = 0
...

Comment 1 Jaroslav Škarvada 2023-06-11 17:04:45 UTC
https://src.fedoraproject.org/rpms/statserial/pull-request/1

Comment 2 Fedora Release Engineering 2023-08-16 08:10:28 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 39 development cycle.
Changing version to 39.


Note You need to log in before you can comment on or make changes to this bug.