site  contact  subhomenews

pup_event now detects cable plug/unplug

February 14, 2019 — BarryK

I have reported recent work with the minibase network utilities:

The 'ifmon' daemon detects "aliveness" of an ethernet interface. That is, if a cable is plugged-in, with a router or something at the other end, that is working, then there is a "carrier" on the cable. It doesn't mean that we have Internet connection or whatever, it just shows that the cable is connected and functioning.

The carrier would go down if the router is turned off, back up if turned on -- however, we observed the carrier going up and down a few times, over about 30 seconds, before staying up, which does complicate how we will respond to this information. Discussion here:

Putting aside minibase for awhile, being able to detect cable plug/unplug and router on/off, is very important to have as a basic feature in EasyOS, so that the network connection can be dynamically brought up/down in response. Rather than the current situation, where the ethernet connection is expected to be active at bootup, and there is no dynamic response afterward.

The utility 'pup_event_frontend_d' is launched at bootup and detects various conditions, such as whether X is up, whether there is a Internet connection. This is part of 'pup_event', described here:

'pup_event_frontend-d' is written in BaCon and is in the 'pup-tools' PET. I have enhanced the daemon to detect carrier up/down, and here are the latest binary packages:

These were compiled in oe-qky-src, my fork of OpenEmbedded:

The latest source for pup-tools is here;

'pup_event_frontend_d' uses a netlink socket to monitor events from the kernel. Extracting a tiny part of the code, there is a seconf socket added, to wait for 'NETLINK_ROUTE' events:


The code that receives the messages is very simple:

 IF pfd2.revents NE 0 THEN
len = recv(pfd2.fd, buf, size_buf, MSG_DONTWAIT)
IF len==-1 THEN END 4
IF netcnt EQ 0 THEN
'post to ipc clients, if any...
'also, let us be proactive, call a script directly...
IF FILEEXISTS("/usr/local/pup_event/netchg") THEN
SYSTEM "/usr/local/pup_event/netchg &"

This posts a "netchg_" IPC message to any clients that might be waiting on it. The pup_event IPC mechanism is explained here:

Not only does this daemon detect cable carrier up/down, it also detects a USB wifi dongle plugged/unplugged. The 'netcnt' variable is to take care of the rapid carrier up/down that occurs when the router is turned on -- there is an IPC generated on the first change, and any changes over the next 50 seconds are ignored.

I have not yet written a client daemon. Will probably name it something like 'netchgd' and it will start at bootup and await "netchg_" IPC messages. It will then examine /sys to determine exactly what has changed, 

Tags: easy