Commit 5eb5f946 authored by Alessandro Rubini's avatar Alessandro Rubini

rvlan: use "operstate" rather than "carrier" for device status.

The problem with /sys/net/*/carrier, is that the file may be missing.
For example, if the fiber is unplugged.  "operstate" is always there,
and it is either "up" or "down".  If it is ifconfig'd up but without fiber,
the operstate is properly down, so we can use it with no further ado.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 2103d008
......@@ -473,21 +473,22 @@ int rvlan_prepare_poll(void)
int rvlan_initial_check(void)
{
struct rvlan_dev *dev;
char path[256];
char path[64], upbuf[16];
FILE *f;
int ret, up;
int ret, up = 1;
for (dev = devs; dev; dev = dev->next) {
if (verbose)
printf("Check %s: ", dev->name);
sprintf(path, "/sys/class/net/%s/carrier", dev->name);
sprintf(path, "/sys/class/net/%s/operstate", dev->name);
f = fopen(path, "r");
if (!f) {
fprintf(stderr, "%s: %s: %s\n", prgname, path,
strerror(errno));
return -1;
}
ret = fscanf(f, "%i", &up);
ret = fscanf(f, "%s", upbuf);
up = (upbuf[0] == 'u');
fclose(f);
if (ret != 1) {
/* Hmmm... read() may return -EINVAL if down */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment