tech-net archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: scanning ...wiconfig: ioctl: No such file or directory
On Tue, 23 Jun 2009, David Laight wrote:
> On Sat, Jun 20, 2009 at 10:56:17AM +0100, Iain Hibbert wrote:
> >
> > Good catch, though imo its unclean to use errno in this way as it only
> > indicates what error occurred, not the presence of an error. Although the
> > change is bigger, is it better to do
> >
> ...
> > while (ioctl(s, SIOCGWAVELAN, &ifr) == -1) {
> > retries--;
> > ! if (retries < 0) {
> > ! set_if_flags(s, iface, flags);
> > ! close(s);
> > ! err(1, "ioctl");
> > ! }
> >
> > ! printf(".");
> > ! fflush(stdout);
> > ! sleep(1);
> > }
>
> That is still (ate least IMHO) buggy sine the err() call needs to
> be made before the set_if_flags() and close() since either could,
> at least potentially, change errno.
I vaguely did think of that but since err() exits and does not return, if
either of set_if_flags() or close() caused an error the worst that would
happen in this case would be that the wrong error was reported..
In fact the whole loop is probably bogus anyway, I don't think
SIOCGWAVELAN will fail unless the device does not support it, in which
case its not really worth retrying.. I didn't look into that at any depth
though and I could be mistaken.
> I've also just had a wicked thought that a signal handler might
> also run and change errno!
luckily this program doesn't use any signal handlers :)
> I wonder how that affects the checking of errno for some libc functions!
thats another reason to not examine the value of errno to detect an error
iain
Home |
Main Index |
Thread Index |
Old Index