Hi all...

Or I'm smoking too much or ifstatus and its usage are really broken...

First point: the -v flag makes the thing verbose, but it also inhibits the
return value to be correct.
See the (simplified) logic in handle():

    if not present
        return -1
    r = 0
    if verbose
        try methods and print message // NOTE: r is not changed
    else
        try methods 
        switch status
            up: r = 1
            down: r = 2
            other: r = -1

    return r;

So, if verbose is set, the return value r is not set, it is just 0 !!!.

Second point: logic in main, when called like ifstatus eth0 (I have not
looked into the multiple interfaces part):

    r = handle()
    if (r<0)
        return 1;
    else
        return r+1;

    return 0;

So, lets get the possible cases:
- if is not present:
        r = -1;
        as (r<0)
                return 1:
- if is present but does not support MII
        r = -1 (as previous ??, see the other: part in handle())
        as (r<0)
                return 1;

- if is down
        r = 2
        as (r>0)
                return 3;
- if is up
        r = 1
        as (r>0)
                return 2;


Now, look into network-functions::check_link_down (correctly indented, btw,
to see something). Comments in the code...

check_link_down()
{
        ...
    if [ -z "${MII_NOT_SUPPORTED}" -a -x /sbin/ifstatus ]; then
       for (( try=0; try<10; try++ )); do
          /sbin/ifstatus $1 > /dev/null 2>&1
          case $? in
             2) return 1;; # up, so return FALSE
             3) return 0;; # down so return TRUE
        # How about the no-MII supported case ??
        # 1) return 1;; # unsupported, so return it is up (FALSE)
        # but how you ditinguish 'that if does not exist, so suppose is down'
        # from 'that if does not support MII so suppose is up'
          esac
          sleep 1
       done
       return 0 # return TRUE, is down
    fi

    return 1 # return false, is up
}

Solution:
- set 4 return values for ifstatus:
        1 is not present
        2 is mii not supported
        3 is down
        4 is up
- logic for check_link_down, getting rid of MII_NOT_SUPPORTED (why is the loop
        needed ?)
    if [ -x /sbin/ifstatus ]; then
          /sbin/ifstatus $1 > /dev/null 2>&1
          case $? in
             1) return 0;; # not present, so TRUE (down)
             2) return 1;; # not supported, so FALSE (up)
             3) return 0;; # TRUE (down)
             4) return 1;; # FALSE (up)
          esac
    fi

    return 1 # return false, is up

???

Modified ifstatus.c and patch for network-functions attached. Work for me (TM).

TIA

-- 
J.A. Magallon <[EMAIL PROTECTED]>      \                 Software is like sex:
werewolf.able.es                         \           It's better when it's free
Mandrake Linux release 9.1 (Cooker) for i586
Linux 2.4.21-pre3-jam2 (gcc 3.2.1 (Mandrake Linux 9.1 3.2.1-2mdk))

Attachment: ifstatus.c.bz2
Description: application/bzip

Attachment: nf.diff.bz2
Description: application/bzip

Reply via email to