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 Fri, 19 Jun 2009, Sverre Froyen wrote:

> There have been a couple of reports about wiconfig -D failing on USB devices
> with the error given in the subject.  See
>
> http://mail-index.netbsd.org/tech-net/2008/03/17/msg000294.html
>
> The problem is not a failed ioctl call but rather that an already set errno is
> caught after the while loop in wi_apscan.  Initializing errno before the loop
> avoids the problem:
>
> diff -u -r1.42 wiconfig.c
> --- wiconfig.c  19 Apr 2009 01:52:09 -0000      1.42
> +++ wiconfig.c  20 Jun 2009 00:01:19 -0000
> @@ -201,6 +201,7 @@
>
>         printf("scanning ...");
>         fflush(stdout);
> +       errno = 0;
>         while (ioctl(s, SIOCGWAVELAN, &ifr) == -1) {
>                 retries--;
>                 if (retries >= 0) {
>
>
> Strangly, errno gets set by the printf("scanning...") statement just before
> the loop.

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

*** wiconfig.c.orig     Thu Apr 23 19:20:46 2009
--- wiconfig.c  Sat Jun 20 10:43:39 2009
***************
*** 203,220 ****
        fflush(stdout);
        while (ioctl(s, SIOCGWAVELAN, &ifr) == -1) {
                retries--;
!               if (retries >= 0) {
!                       printf("."); fflush(stdout);
!                       sleep(1);
!               } else
!                       break;
!               errno = 0;
!       }

!       if (errno) {
!               set_if_flags(s, iface, flags);
!               close(s);
!               err(1, "ioctl");
        }

        naps = *(int *)wreq.wi_val;
--- 203,217 ----
        fflush(stdout);
        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);
        }

        naps = *(int *)wreq.wi_val;

?

iain


Home | Main Index | Thread Index | Old Index