# /etc/init.d/net-online weird errors

## Akaihiryuu

If the net-online script tries to run during the boot process, it basically just spams really weird errors and hangs indefinitely (preventing the rc scripts from completing).  Syslog is not logging the error so I can't reproduce it exactly, but it is saying invalid argument in line 59 and 60 (alternating) in /etc/init.d/net-online.  These lines are

read x < /sys/class/net/$dev/carrier [ $x -eq 1 ] && : $((carriers += 1))

read x < /sys/class/net/$dev/operstate [ "$x" = up ] && : $((configured += 1))

If I have need="net-online" in ANY service in conf.d, this happens.  And it will hang forever until I put it in maintenance mode, take that line out of the entry in conf.d, and restart it again.  The only thing I can figure is at that point in the boot process, the entries in /sys/class/net/eth1 are not there.  (I have net-online set to depend only on net-eth1.)

If I wait until everything is running, and THEN run net-online, it works fine.  Something is terribly terribly broken in the startup scripts, anyone have any idea what it could be?  I'm wanting to have services depend on net-online for a reason.  If openrc is really this broken, I may just have to switch to systemd even though I don't like it.

----------

## Ant P.

You somehow have a broken initscript. Those should be four lines, not two:

```
      read x < /sys/class/net/$dev/carrier

      [ $x -eq 1 ] && : $((carriers += 1))

      read x < /sys/class/net/$dev/operstate

      [ "$x" = up ] && : $((configured += 1))
```

----------

## Akaihiryuu

 *Ant P. wrote:*   

> You somehow have a broken initscript. Those should be four lines, not two:
> 
> ```
>       read x < /sys/class/net/$dev/carrier
> 
> ...

 

It actually is 4 lines, it ended up being a copy/paste problem when I pasted it here.  That's what I have.

----------

## guitou

Hello, looking at net-online script, I think you should try and manually run some bash commands from get_interfaces function:

```

        for ifname in /sys/class/net/*; do

                read iftype < ${ifname}/type

                [ "$iftype" = "1" ] && printf "%s " ${ifname##*/}

        done

```

And for each dev listed, you may then check values of /sys/class/net/$dev/carrier and /sys/class/net/$dev/operstate

This should help you identify which device gets in the loop while not yet initialized/configured (dummy?)

++

Gi)

----------

## Akaihiryuu

 *guitou wrote:*   

> Hello, looking at net-online script, I think you should try and manually run some bash commands from get_interfaces function:
> 
> ```
> 
>         for ifname in /sys/class/net/*; do
> ...

 

By the time I can actually access the system, they are all there.  It's something that must not be getting initialized during boot time.

----------

## Hu

You could temporarily patch the script to have set -x before the relevant commands and set +x after them, so that bash prints each command before executing it.  That would show you which commands and paths provoke the error message.  As an example of the output you can get:

```
(set -x; for a in /dev/null; do read < "$a"; done )

+ for a in /dev/null

+ read

```

----------

## guitou

Hello.

My bad, except from a typo in /etc/conf.d/net-online, only eth1 should be checked indeed.

Then, as you said, matter is probably that /sys/classes/net/eth1 is not yet populated. Ans as to try and figure out why, if it does always happen, maybe you just have services with need="net-online" at a lower run level than net.eth1. Otherwise if it happened just once or is happening sometimes, it might rather be a physical connection issue (broken cable, switch, ISP...).

++

Gi)

----------

