I compiled the following program as static binaries both on Ubuntu 26.04
and Ubuntu 25.04.

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/tty.h>

int main(int argc, char *argv[]) {
    struct winsize w;
    int fd;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <device>\n", argv[0]);
        return 1;
    }

    // Open the specified device
    fd = open(argv[1], O_RDONLY);
    if (fd < 0) {
        perror("Failed to open device");
        return 1;
    }

    // Use ioctl to check if the device is a TTY
    printf("Check for TTY via ioctl(TIOCGWINSZ)\n");
    if (ioctl(fd, TIOCGWINSZ, &w) == -1) {
        // If ioctl fails, it's not a tty
        printf("%s is NOT a terminal (tty) or error occurred", argv[1]);
    } else {
        // If ioctl succeeds, it's a tty
        printf("%s is a terminal (tty).\n", argv[1]);
    }

    printf("\nCheck for TTY via isatty()\n");
    // Use isatty() to check if the file descriptor refers to a terminal
    if (isatty(fd)) {
        printf("%s is a terminal (tty).\n", argv[1]);
    } else {
        printf("%s is NOT a terminal (tty).\n", argv[1]);
    }

    // Close the device
    close(fd);
    return 0;
}

The result differs:

Check for TTY via ioctl(TIOCGWINSZ)
/dev/pts/0 is a terminal (tty).

Check for TTY via isatty()
/dev/pts/0 is a terminal (tty).
./check_tty_2604 /dev/pts/0
Check for TTY via ioctl(TIOCGWINSZ)
/dev/pts/0 is a terminal (tty).

Check for TTY via isatty()
/dev/pts/0 is NOT a terminal (tty).

So the proble seems to be in function isatty() which is implemente in
glibc.


glibc 2.41 and 2.42 show the following difference:

2.41:
__tcgetattr (int fd, struct termios *termios_p)
retval = INLINE_SYSCALL (ioctl, 3, fd, TCGETS, &k_termios);

2.42:
__tcgetattr (int fd, struct termios *termios_p)
long int retval = INLINE_SYSCALL_CALL (ioctl, fd, TCGETS2, &k_termios);

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2133188

Title:
  Illegal instruction in memset under qemu-user for riscv64

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/2133188/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to