Network_get_device in init script returns empty string?

I'm trying to use network_get_device in an init script, but during boot, it returns empty string for the interface I specified in /etc/config/network. Since it works fine after boot, I guess it's probably because during boot, it's still too early and the interface hasn't been fully created yet. I wonder if there is an elegant solution to wait for it without simply retrying the function in a loop for example?

I tried ubus wait_for as suggested by @hnyman, but in my test, it was still empty even if network.interface.<name> appeared in ubus. In my case network_get_device only returns something more than 10 seconds after wait_for returns.

Any help is much appreciated.

I don't know if it will be helpful, but in a similar situation (also with @hnyman's advice afair) I ended up with the loop invoking network_flush_cache: https://github.com/stangri/source.openwrt.melmac.net/blob/ed4d51a671f0a91b392eb27a9c006227bd6ec893/pbr/files/etc/init.d/pbr#L593-L600

2 Likes

Seems that's the only viable way right now. Thanks.