i cannot reproduce the problem here and i do not quite understand what 
your patch (with whitespace errors) should fix other than having the 
wrong interface configured.

- drkhsh

On Mon, Jul 28, 2025 at 05:24:11PM +0100, ryhpez wrote:
> this patch fixes a problem with the 'ifindex' function (in 
> 'components/wifi.c'). if the wireless interface was down when 'slstatus' 
> started, it wouldn’t detect it even after bringing the interface up later.
> I ran into this because I usually boot with all interfaces down and only 
> enable them when needed. After updating to v1.1, I noticed the SSID never 
> showed unless the interface was already up at launch.
> 
> the issue is that the code caches the interface name in 'ifr' (a static 
> 'struct ifreq' in 'ifindex') and skips calling 'ioctl(ifsock, SIOCGIFINDEX, 
> &ifr)' after the first time because of this check:
> `
> if (strcmp(ifr.ifr_name, interface) != 0) {
>     strcpy(ifr.ifr_name, interface);
>     if (ioctl(ifsock, SIOCGIFINDEX, &ifr) != 0) {
>         warn("ioctl 'SIOCGIFINDEX':");
>         return -1;
>     }
> }
> `
> since the interface name doesn’t change, it never retries 'ioctl' when the 
> interface comes up later, the patch changes this to always call 'ioctl', this 
> way, it detects the interface as soon as it’s available.
> 
> let me know if you want this included in the mainbranch or if I just add it 
> to the patches page in case the current behavior is intentional.
> ---
>  components/wifi.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/components/wifi.c b/components/wifi.c
> index 23af201..8639957 100644
> --- a/components/wifi.c
> +++ b/components/wifi.c
> @@ -108,12 +108,12 @@
>                       warn("socket 'AF_UNIX':");
>                       return -1;
>               }
> -             if (strcmp(ifr.ifr_name, interface) != 0) {
> +             if (strcmp(ifr.ifr_name, interface) != 0) { 
>                       strcpy(ifr.ifr_name, interface);
> -                     if (ioctl(ifsock, SIOCGIFINDEX, &ifr) != 0) {
> -                             warn("ioctl 'SIOCGIFINDEX':");
> -                             return -1;
> -                     }
> +             }
> +             if (ioctl(ifsock, SIOCGIFINDEX, &ifr) != 0) {
> +                     warn("ioctl 'SIOCGIFINDEX':");
> +                     return -1;
>               }
>               return ifr.ifr_ifindex;
>       }
> -- 
> 2.49.0
> 
> 

Reply via email to