All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: stsp <stsp2@yandex.ru>
Cc: linux-serial@vger.kernel.org
Subject: Re: [regression] ENOTTY returned for tty fds
Date: Wed, 24 Jul 2024 08:51:34 +0200	[thread overview]
Message-ID: <2024072452-pegboard-undying-4245@gregkh> (raw)
In-Reply-To: <b6f4aa5c-10ba-411b-994b-6dbed2bf63db@yandex.ru>

On Sun, Jul 21, 2024 at 02:52:31PM +0300, stsp wrote:
> Hi!
> 
> I've noticed that one of my progs failed
> to work with serial ports. To distinguish
> between real serial ports and PTS nodes,
> it tried TIOCMBIC, checking errno for EINVAL.
> 
> Obviously that behaviour was changed
> and now ENOTTY is returned. Besides
> being backward-incompatible, I think this
> is also wrong because isatty() returns 1
> on such FDs.
> 
> Here's the test-case:
> socat PTY,link=/tmp/ttyS20,raw,echo=0,b9600
> PTY,link=/tmp/ttyS21,raw,echo=0,b9600
> 
> Then run this program:
> 
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <errno.h>
> #include <sys/ioctl.h>
> #include <unistd.h>
> 
> int main() {
>   int fd, err;
>   int data = TIOCM_DTR | TIOCM_RTS;
>   fd = open("/tmp/ttyS20", O_NONBLOCK);
>   if (fd == -1) {
>     perror("open()");
>     return 1;
>   }
>   err = ioctl(fd, TIOCMBIC, &data);
>   if (err && errno == ENOTTY && isatty(fd))
>     printf("Test FAILED: ENOTTY for tty fd\n");
>   return 0;
> }
> 
> 

What caused this change/regression?  And does any real-world programs
rely on this?  What exactly are you trying to determine with this ioctl
test?  Is there a different way to determine that?

thanks,

greg k-h

  reply	other threads:[~2024-07-24  6:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-21 11:52 [regression] ENOTTY returned for tty fds stsp
2024-07-24  6:51 ` Greg KH [this message]
2024-07-24  8:07   ` stsp
2024-07-24  9:08     ` Greg KH
2024-07-24  9:55       ` stsp
2024-07-24 10:15         ` Greg KH
2024-07-24 10:53           ` Herbert Xu
2024-07-24 10:58             ` Herbert Xu
2024-07-31 10:25               ` Greg KH
2024-07-31 16:12                 ` Johan Hovold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2024072452-pegboard-undying-4245@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=stsp2@yandex.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.