<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="+1"><tt>Hi everyone,<br>
<br>
The state of the art in determining ethernet link state, and taking any
action based on changes, seems to be to run a daemon that repeatedly
polls the network interface and using an ioctl (SIOCGMIIPHY,
SIOCETHTOOL) finds out if there is an ethernet link or not.<br>
<br>
It seems like it would be more deterministic, and less resource
intensive, to just have the network card device driver DO something (or
cause something to be done) when the link state changes.&nbsp; For an
embedded device with limited CPU I think while(1) polling is
sub-optimal.&nbsp; It also seems like it should not be too hard to get the
device driver to do something useful in addition to its printk()
message about the changed link state.<br>
<br>
How could I do this? I think system() is a bad idea because I'm not
sure a device driver should be starting other processes that may block
or something.&nbsp; Also system() requires unistd.h and the kernel
compile/build system doesn't seem to give drivers access to that sort
of normal libc functions.&nbsp; Anyway I welcome any ideas.<br>
<br>
For example the driver doesn't compile with the 2 lines I added (marked
with +), and also unistd.h is not found even though I #included it:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; if (!port-&gt;link) {<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; netif_carrier_off(dev);<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printk(KERN_INFO "%s: link down\n", dev-&gt;name);<br>
+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printk(KERN_INFO "%s: link down, running
/usr/bin/wanlinkdown\n", dev-&gt;name);<br>
+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; system("/usr/bin/wanlinkdown");<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return;<br>
&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
I'm not heart-broken that this doesn't work because I didn't like this
approach to begin with, but I'm still not sure exactly what would be
the best way to get a notification without polling.&nbsp; So far the only
"notification" is the KERN_INFO message that gets printed to the dmesg
log and also whatever is specified in syslog.conf (kern.info goes to *,
which includes the console). In addition to the notification I want it
to run a program or something so I get explicit real-time notification
of link state changes without constantly polling.<br>
<br>
Thanks,<br>
Jim<br>
</tt></font>
<pre class="moz-signature" cols="72">-- 
Jim Ockers, P.E., P.Eng. (<a class="moz-txt-link-abbreviated" href="mailto:ockers@ockers.net">ockers@ockers.net</a>)
Contact info: <a class="moz-txt-link-freetext" href="http://www.ockers.net/">http://www.ockers.net/</a>

</pre>
</body>
</html>