Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Lifeng Sun <lifongsun@gmail.com>
Cc: linux-kernel@vger.kernel.org, netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH] Applying inappropriate ioctl operation on socket should return ENOTTY
Date: Wed, 27 Apr 2011 08:55:09 +0200	[thread overview]
Message-ID: <1303887309.2699.58.camel@edumazet-laptop> (raw)
In-Reply-To: <20110427063730.GA20313@md5.ntu.edu.sg>

Le mercredi 27 avril 2011 à 14:37 +0800, Lifeng Sun a écrit :
> On 07:58 Wed 04/27/11 Apr, Eric Dumazet wrote:
> > Really ?
> > 
> > EINVAL is ok too : Request or argp is not valid.
> 
> I'm afraid not. SUSv4 specifies, say,
> 
>   int tcsetattr(int fildes, int optional_actions,
>          const struct termios *termios_p);
> 
>  ERROR:
>   [EINVAL]
>       The optional_actions argument is not a supported value, or an
>       attempt was made to change an attribute represented in the
>       termios structure to an unsupported value.
> 
>   [ENOTTY]
>       The file associated with fildes is not a terminal.
> 
> which means when we apply tcsetattr (implemented by ioctl) to _any_
> non-terminal file descriptor, it should set errno to ENOTTY rather
> than EINVAL.

Thats not so simple. This is a known and documented artifact.

In old days, ioctl() had a meaning for TTYS (mostly).



man isatty

ERRORS
       EBADF  fd is not a valid file descriptor.

       EINVAL fd refers to a file other than a terminal.  POSIX.1-2001 specifies the error ENOTTY for this case.


This is not because POSIX changes rules that we must change kernel and break applications.

Conformant applications use isatty(fd) and test result code being 1 or not 1

This way, they work with linux 1.0, 2.0, 2.2, 2.4, .... and other OSes as well.

  reply	other threads:[~2011-04-27  6:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1303882625-28115-1-git-send-email-lifongsun@gmail.com>
2011-04-27  5:58 ` [PATCH] Applying inappropriate ioctl operation on socket should return ENOTTY Eric Dumazet
2011-04-27  6:37   ` Lifeng Sun
2011-04-27  6:55     ` Eric Dumazet [this message]
2011-04-27  6:57     ` Eric Dumazet
2011-04-27  8:22       ` Lifeng Sun
2011-04-27  9:32   ` Lifeng Sun
2011-04-27  9:47   ` Alan Cox
2011-04-27 10:45     ` Eric Dumazet
2011-04-27 11:52       ` Alan Cox
2011-04-27 12:09 ` Alan Cox
2011-04-27 13:54   ` Lifeng Sun
2011-04-28  8:04   ` [PATCH 1/5] networking: inappropriate ioctl operation " Lifeng Sun
2011-05-02 22:41     ` David Miller
2011-04-28  8:49   ` [PATCH] Applying inappropriate ioctl operation on socket " Lifeng Sun

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=1303887309.2699.58.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=lifongsun@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox