static gboolean udev_read_cb (GIOChannel *source, GIOCondition condition, gpointer user_data) { OdccmDeviceManagerPrivate *priv = ODCCM_DEVICE_MANAGER_GET_PRIVATE (user_data); #define UEVENT_BUFFER_SIZE 2048 gchar buf[UEVENT_BUFFER_SIZE*2]; GIOStatus status; GError *error = NULL; guint buflen = 0; size_t bufpos; gboolean is_net = FALSE, is_ppp = FALSE, added = FALSE; gchar iface[10]; gchar udi[UEVENT_BUFFER_SIZE]; status = g_io_channel_read_chars(priv->udev_chann, &buf, sizeof(buf), &buflen, &error); if (status != G_IO_STATUS_NORMAL) { g_warning("%s: error reading event: %s",G_STRFUNC,error->message); g_error_free(error); error = NULL; } bufpos = strlen(buf) + 1; while (bufpos < (size_t)buflen) { int keylen; char *key; char *tmpptr; key = &buf[bufpos]; keylen = strlen(key); if (keylen == 0) break; if (strncmp("SUBSYSTEM=net",key,13)==0) is_net = TRUE; if (strncmp("INTERFACE=ppp",key,13)==0){ is_ppp = TRUE; tmpptr = strchr(key,'='); strncpy(iface,tmpptr+1,10); } if (strncmp("ACTION=remove",key,13)==0) added = FALSE; if (strncmp("ACTION=add",key,13)==0) added = TRUE; if (strncmp("DEVPATH",key,7)==0) { tmpptr = strchr(key,'='); strncpy(udi,tmpptr+1,UEVENT_BUFFER_SIZE); } bufpos += keylen + 1; } if (is_net == TRUE && is_ppp == TRUE) { if (added == TRUE) { udev_device_added(user_data,iface,udi); } else { udev_device_removed(user_data,iface,udi); } } return TRUE; }
static void handle_uevent (GUdevClient *client, const char *action, GUdevDevice *device, gpointer user_data) { SCPluginIfupdown *self = SC_PLUGIN_IFUPDOWN (user_data); const char *subsys; g_return_if_fail (action != NULL); /* A bit paranoid */ subsys = g_udev_device_get_subsystem (device); g_return_if_fail (subsys != NULL); g_return_if_fail (strcmp (subsys, "net") == 0); if (!strcmp (action, "add")) udev_device_added (self, device); else if (!strcmp (action, "remove")) udev_device_removed (self, device); }