Exemple #1
0
static int
udev_handle_device(void *ctx)
{
	struct udev_device *device;
	const char *subsystem, *ifname, *action;

	device = udev_monitor_receive_device(monitor);
	if (device == NULL) {
		syslog(LOG_ERR, "libudev: received NULL device");
		return -1;
	}

	subsystem = udev_device_get_subsystem(device);
	ifname = udev_device_get_sysname(device);
	action = udev_device_get_action(device);

	/* udev filter documentation says "usually" so double check */
	if (strcmp(subsystem, "net") == 0) {
		syslog(LOG_DEBUG, "%s: libudev: %s", ifname, action);
		if (strcmp(action, "add") == 0 || strcmp(action, "move") == 0)
			dhcpcd.handle_interface(ctx, 1, ifname);
		else if (strcmp(action, "remove") == 0)
			dhcpcd.handle_interface(ctx, -1, ifname);
	}

	udev_device_unref(device);
	return 1;
}
Exemple #2
0
void CALSADeviceMonitor::FDEventCallback(int id, int fd, short revents, void *data)
{
  struct udev_monitor *udevMonitor = (struct udev_monitor *)data;
  bool audioDevicesChanged = false;
  struct udev_device *device;

  while ((device = udev_monitor_receive_device(udevMonitor)) != NULL)
  {
    const char* action = udev_device_get_action(device);
    const char* soundInitialized = udev_device_get_property_value(device, "SOUND_INITIALIZED");

    if (!action || !soundInitialized)
      continue;

    /* cardX devices emit a "change" event when ready (i.e. all subdevices added) */
    if (strcmp(action, "change") == 0)
    {
      CLog::Log(LOGDEBUG, "CALSADeviceMonitor - ALSA card added (\"%s\", \"%s\")", udev_device_get_syspath(device), udev_device_get_devpath(device));
      audioDevicesChanged = true;
    }
    else if (strcmp(action, "remove") == 0)
    {
      CLog::Log(LOGDEBUG, "CALSADeviceMonitor - ALSA card removed");
      audioDevicesChanged = true;
    }

    udev_device_unref(device);
  }

  if (audioDevicesChanged)
  {
    CServiceBroker::GetActiveAE()->DeviceChange();
  }
}
Exemple #3
0
void Storage::checkDevice(int fd) {
    PowerManagerLock* powerLock = PowerManager::getNewLock(this);
    powerLock->activate();
    qDebug() << Q_FUNC_INFO << "FD: "<< fd;

    struct udev_device *dev;
    dev = udev_monitor_receive_device(udev_monitor);
    if (dev)
    {
        QString device = udev_device_get_devnode(dev);
        QString path = udev_device_get_devpath(dev);
        QString action = udev_device_get_action(dev);
        QString devtype = udev_device_get_devtype(dev);
        QString sysname("/dev/");
        sysname += QString(udev_device_get_sysname(dev));
        QString parent = udev_device_get_devpath( udev_device_get_parent (dev));
        if (sysname.contains(QRegExp("mmcblk[0-9]\\d*"))  || sysname.contains(QRegExp("mmcblk[0-9]")))
        {
            qDebug() << "Got " << path << ":" << action;
            qDebug() << "    Got Device";
            qDebug() << "    Node: " <<  udev_device_get_devnode(dev);
            qDebug() << "    Subsystem: "<< udev_device_get_subsystem(dev);
            qDebug() << "    Devtype: " << devtype;
            qDebug() << "    Action: " << action;
            qDebug() << "    Sysname: " << sysname;
            qDebug() << "    sysnum: " << udev_device_get_sysnum (dev);
            qDebug() << "    parent: " << parent;

            processRemovableUdevEvents(devtype, path, sysname, action);
        }
        udev_device_unref(dev);
    }
    delete powerLock;
}
static void monitor_cb(
        pa_mainloop_api*a,
        pa_io_event* e,
        int fd,
        pa_io_event_flags_t events,
        void *userdata) {

    struct userdata *u = userdata;
    struct udev_device *dev;

    pa_assert(a);

    if (!(dev = udev_monitor_receive_device(u->monitor))) {
        pa_log("Failed to get udev device object from monitor.");
        goto fail;
    }

    if (!path_get_card_id(udev_device_get_devpath(dev))) {
        udev_device_unref(dev);
        return;
    }

    process_device(u, dev);
    udev_device_unref(dev);
    return;

fail:
    a->io_free(u->udev_io);
    u->udev_io = NULL;
}
Exemple #5
0
Fichier : udev.c Projet : etix/vlc
static void *Run (void *data)
{
    services_discovery_t *sd = data;
    services_discovery_sys_t *p_sys = sd->p_sys;
    struct udev_monitor *mon = p_sys->monitor;

    int fd = udev_monitor_get_fd (mon);
    struct pollfd ufd = { .fd = fd, .events = POLLIN, };

    for (;;)
    {
        while (poll (&ufd, 1, -1) == -1)
            if (errno != EINTR)
                break;

        int canc = vlc_savecancel ();
        struct udev_device *dev = udev_monitor_receive_device (mon);
        if (dev == NULL)
            continue;

        const char *action = udev_device_get_action (dev);
        if (!strcmp (action, "add"))
            AddDevice (sd, dev);
        else if (!strcmp (action, "remove"))
            RemoveDevice (sd, dev);
        else if (!strcmp (action, "change"))
        {
            RemoveDevice (sd, dev);
            AddDevice (sd, dev);
        }
        udev_device_unref (dev);
        vlc_restorecancel (canc);
    }
    return NULL;
}
    void DeviceManager::processHotplugEvents()
    {
        udev_device * device;

        device = udev_monitor_receive_device(hotplugMonitor);

        if (device)
        {
            if (string(udev_device_get_action(device)) == "remove")
            {
                map <string, Device *>::iterator it;

                for (it = devices.begin(); it != devices.end(); it++)
                {
                    if (it->second->getNode() == udev_device_get_devnode(device))
                    {
                        Device * dev = it->second;

                        remove(dev);

                        delete dev;

                        break;
                    }
                }
            }
            else
            {
                add(new DeviceHard(udev_device_get_devnode(device)));
            }

            udev_device_unref(device);
        }
    }
Exemple #7
0
static monome_t *monitor_attach(detector_state_t *state) {
	struct udev_device *ud;
	struct pollfd fds[1];

	fds[0].fd = udev_monitor_get_fd(state->um);
	fds[0].events = POLLIN;

	do {
		if( poll(fds, 1, -1) < 0 )
			switch( errno ) {
			case EINVAL:
				perror("error in poll()");
				exit(1);

			case EINTR:
			case EAGAIN:
				continue;
			}

		ud = udev_monitor_receive_device(state->um);

		/* check if this was an add event.
		   "add"[0] == 'a' */
		if( *(udev_device_get_action(ud)) == 'a' )
			spawn_server(state->exec_path, udev_device_get_devnode(ud));

		udev_device_unref(ud);
	} while( 1 );
}
  void LinuxDeviceManager::udevReceiveDevice()
  {
    struct udev_device *dev = udev_monitor_receive_device(_umon);

    if (!dev) {
      return;
    }

    const char *action_cstr = udev_device_get_action(dev);

    if (!action_cstr) {
      log->warn("BUG? Device event witout action value.");
      udev_device_unref(dev);
      return;
    }

    if (strcmp(action_cstr, "add") == 0) {
      processDeviceInsertion(dev);
    }
    else if (strcmp(action_cstr, "remove") == 0) {
      processDeviceRemoval(dev);
    }
    else {
      log->warn("BUG? Unknown device action value \"{}\"", action_cstr);
    }

    udev_device_unref(dev);
    return;
  }
static gboolean hotplug_event(GIOChannel *source, GIOCondition condition,
			      gpointer data)
{
	struct udev_device *dev;
	dev_t udev_devnum;
	struct stat s;
	const char *hotplug;

	dev = udev_monitor_receive_device(uevent_monitor);
	if (!dev)
		goto out;

	udev_devnum = udev_device_get_devnum(dev);
	fstat(drm_fd, &s);

	hotplug = udev_device_get_property_value(dev, "HOTPLUG");

	if (memcmp(&s.st_rdev, &udev_devnum, sizeof(dev_t)) == 0 &&
	    hotplug && atoi(hotplug) == 1)
		update_display(true);

	udev_device_unref(dev);
out:
	return TRUE;
}
UdevDevice UdevMonitor::receiveDeviceEvent(void)
	{
	/* Wait for and receive a device event: */
	udev_device* result=udev_monitor_receive_device(monitor);
	
	/* Return an event object (which might be invalid in case of error or non-blocking event socket): */
	return UdevDevice(result);
	}
Exemple #11
0
static void udev_input_handle_hotplug(udev_input_t *udev)
{
   bool is_keyboard, is_mouse, is_touchpad;
   struct udev_device *dev  = udev_monitor_receive_device(udev->monitor);
   device_handle_cb cb      = NULL;
   const char *devtype      = NULL;
   const char *val_keyboard = NULL;
   const char *val_mouse    = NULL;
   const char *val_touchpad = NULL;
   const char *action       = NULL;
   const char *devnode      = NULL;

   if (!dev)
      return;

   val_keyboard  = udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD");
   val_mouse     = udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
   val_touchpad  = udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD");
   action        = udev_device_get_action(dev);
   devnode       = udev_device_get_devnode(dev);

   is_keyboard   = val_keyboard && !strcmp(val_keyboard, "1") && devnode;
   is_mouse      = val_mouse && !strcmp(val_mouse, "1") && devnode;
   is_touchpad   = val_touchpad && !strcmp(val_touchpad, "1") && devnode;

   if (!is_keyboard && !is_mouse && !is_touchpad)
      goto end;

   if (is_keyboard)
   {
      cb = udev_handle_keyboard;
      devtype = "keyboard";
   }
   else if (is_touchpad)
   {
      cb = udev_handle_touchpad;
      devtype = "touchpad";
   }
   else if (is_mouse)
   {
      cb = udev_handle_mouse;
      devtype = "mouse";
   }

   if (!strcmp(action, "add"))
   {
      RARCH_LOG("[udev]: Hotplug add %s: %s.\n", devtype, devnode);
      add_device(udev, devnode, cb);
   }
   else if (!strcmp(action, "remove"))
   {
      RARCH_LOG("[udev]: Hotplug remove %s: %s.\n", devtype, devnode);
      udev_input_remove_device(udev, devnode);
   }

end:
   udev_device_unref(dev);
}
Exemple #12
0
static void udev_input_handle_hotplug(udev_input_t *udev)
{
   const char *devtype      = NULL;
   const char *val_keyboard = NULL;
   const char *val_mouse    = NULL;
   const char *val_touchpad = NULL;
   const char *action       = NULL;
   const char *devnode      = NULL;
   struct udev_device *dev  = udev_monitor_receive_device(udev->monitor);

   if (!dev)
      return;

   val_keyboard  = udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD");
   val_mouse     = udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
   val_touchpad  = udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD");
   action        = udev_device_get_action(dev);
   devnode       = udev_device_get_devnode(dev);

   if (val_keyboard && string_is_equal_fast(val_keyboard, "1", 1) && devnode)
      devtype = "keyboard";

   if (val_mouse && string_is_equal_fast(val_mouse, "1", 1) && devnode)
      devtype = "mouse";

   if (val_touchpad && string_is_equal_fast(val_touchpad, "1", 1) && devnode)
      devtype = "touchpad";

   if (!devtype)
      goto end;

   if (string_is_equal_fast(action, "add", 3))
   {
      device_handle_cb cb      = NULL;
      if (string_is_equal_fast(devtype, "keyboard", 8))
         cb = udev_handle_keyboard;
      else if (string_is_equal_fast(devtype, "touchpad", 8))
         cb = udev_handle_touchpad;
      else if (string_is_equal_fast(devtype, "mouse", 5))
         cb = udev_handle_mouse;

      RARCH_LOG("[udev]: Hotplug add %s: %s.\n", devtype, devnode);
      udev_input_add_device(udev, devnode, cb);
   }
   else if (string_is_equal_fast(action, "remove", 6))
   {
      RARCH_LOG("[udev]: Hotplug remove %s: %s.\n", devtype, devnode);
      udev_input_remove_device(udev, devnode);
   }

end:
   udev_device_unref(dev);
}
void joystick_linux::monitor_joysticks(udev *p_udev) {

	udev_device *dev = NULL;
	udev_monitor *mon = udev_monitor_new_from_netlink(p_udev, "udev");
	udev_monitor_filter_add_match_subsystem_devtype(mon, "input", NULL);
	udev_monitor_enable_receiving(mon);
	int fd = udev_monitor_get_fd(mon);

	while (!exit_udev) {

		fd_set fds;
		struct timeval tv;
		int ret;

		FD_ZERO(&fds);
		FD_SET(fd, &fds);
		tv.tv_sec = 0;
		tv.tv_usec = 0;

		ret = select(fd+1, &fds, NULL, NULL, &tv);

		/* Check if our file descriptor has received data. */
		if (ret > 0 && FD_ISSET(fd, &fds)) {
			/* Make the call to receive the device.
			   select() ensured that this will not block. */
			dev = udev_monitor_receive_device(mon);

			if (dev && udev_device_get_devnode(dev) != 0) {

				joy_mutex->lock();
				String action = udev_device_get_action(dev);
				const char* devnode = udev_device_get_devnode(dev);
				if (devnode) {

					String devnode_str = devnode;
					if (devnode_str.find(ignore_str) == -1) {

						if (action == "add")
							open_joystick(devnode);
						else if (String(action) == "remove")
							close_joystick(get_joy_from_path(devnode));
					}
				}

				udev_device_unref(dev);
				joy_mutex->unlock();
			}
		}
		usleep(50000);
	}
	//printf("exit udev\n");
	udev_monitor_unref(mon);
}
Exemple #14
0
int
main(int argc, char *argv[]) {
    struct udev *udev;
    // struct udev_enumerate *enumerate;
//    struct udev_list_entry *devices, *device;
    udev_monitor = NULL;

    struct udev_device *udev_device;
    const char *action;


    udev = udev_new();
    if (!udev) {
        printf("udev_new failed\n");
        return 0;
    }
    udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
    if (!udev_monitor) {
        printf("udev_monitor_new_from_netlink failed\n");
        return 0;
    }

    udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input", NULL);

    if (udev_monitor_enable_receiving(udev_monitor)) {
        printf("config/udev: failed to bind the udev monitor\n");
        return 0;
    }


    int udev_fd = udev_monitor_get_fd(udev_monitor);

    select_for_read(udev_fd);

    udev_device = udev_monitor_receive_device(udev_monitor);
    if (!udev_device) {
        printf("udev_monitor_receive_device failed\n");
        return 0;
    }
    action = udev_device_get_action(udev_device);
    printf("udev action %s\n", action);
    if (action) {
        if (!strcmp(action, "add") || !strcmp(action, "change")) {
            printf("device_removed(udev_device); device_added(udev_device);\n");
        }
        else if (!strcmp(action, "remove")) {
            printf("device_removed(udev_device);\n");
	}
    }
    udev_device_unref(udev_device);

    return 0;
}
Exemple #15
0
bool
UdevSubsystem::on_udev_data(GIOChannel* channel, GIOCondition condition)
{
  if (condition == G_IO_OUT)
  {
    log_error("data can be written");
  }
  else if (condition == G_IO_PRI)
  {
    log_error("data can be read");
  }
  else if (condition == G_IO_ERR)
  {
    log_error("data error");
  }
  else if (condition != G_IO_IN)
  {
    log_error("unknown condition: " << condition);
  }
  else
  {
    log_info("trying to read data from udev");

    log_info("trying to read data from udev monitor");
    struct udev_device* device = udev_monitor_receive_device(m_monitor);
    log_info("got data from udev monitor");

    if (!device)
    {
      // seem to be normal, do we get this when the given device is filtered out?
      log_debug("udev device couldn't be read: " << device);
    }
    else
    {
      const char* action = udev_device_get_action(device);

      if (g_logger.get_log_level() >= Logger::kDebug)
      {
        print_info(device);
      }

      if (action && strcmp(action, "add") == 0)
      {
        m_process_match_cb(device);
      }

      udev_device_unref(device);
    }
  }

  return true;
}
Exemple #16
0
void linux_udev_hotplug_poll(void)
{
	struct udev_device* udev_dev;

	usbi_mutex_static_lock(&linux_hotplug_lock);
	do {
		udev_dev = udev_monitor_receive_device(udev_monitor);
		if (udev_dev) {
			usbi_dbg("Handling hotplug event from hotplug_poll");
			udev_hotplug_event(udev_dev);
		}
	} while (udev_dev);
	usbi_mutex_static_unlock(&linux_hotplug_lock);
}
Exemple #17
0
static int manager_udev_fn(sd_event_source *source,
			   int fd,
			   uint32_t mask,
			   void *data)
{
	_cleanup_udev_device_ struct udev_device *d = NULL;
	struct manager *m = data;
	const char *action, *ifname;
	unsigned int ifindex;
	struct link *l;

	d = udev_monitor_receive_device(m->udev_mon);
	if (!d)
		return 0;

	ifindex = ifindex_from_udev_device(d);
	if (!ifindex)
		return 0;

	l = manager_find_link(m, ifindex);

	action = udev_device_get_action(d);
	if (action && !strcmp(action, "remove")) {
		if (l)
			link_free(l);
	} else if (l) {
		ifname = udev_device_get_property_value(d, "INTERFACE");
		if (action && !strcmp(action, "move")) {
			if (ifname)
				link_renamed(l, ifname);
		}

#ifdef RELY_UDEV
		if (udev_device_has_tag(d, "miracle") && !lazy_managed)
			link_set_managed(l, true);
		else
			link_set_managed(l, false);
#else
		if ((!interface_name || !strcmp(interface_name, ifname)) && !lazy_managed) {
			link_set_managed(l, true);
		} else {
			log_debug("ignored device: %s", ifname);
		}
#endif
	} else {
		manager_add_udev_link(m, d);
	}

	return 0;
}
void QDeviceDiscovery::handleUDevNotification()
{
    if (!m_udevMonitor)
        return;

    struct udev_device *dev;
    QString devNode;

    dev = udev_monitor_receive_device(m_udevMonitor);
    if (!dev)
        goto cleanup;

    const char *action;
    action = udev_device_get_action(dev);
    if (!action)
        goto cleanup;

    const char *str;
    str = udev_device_get_devnode(dev);
    if (!str)
        goto cleanup;

    const char *subsystem;
    devNode = QString::fromUtf8(str);
    if (devNode.startsWith(QLatin1String(QT_EVDEV_DEVICE)))
        subsystem = "input";
    else if (devNode.startsWith(QLatin1String(QT_DRM_DEVICE)))
        subsystem = "drm";
    else goto cleanup;

    // if we cannot determine a type, walk up the device tree
    if (!checkDeviceType(dev)) {
        // does not increase the refcount
        dev = udev_device_get_parent_with_subsystem_devtype(dev, subsystem, 0);
        if (!dev)
            goto cleanup;

        if (!checkDeviceType(dev))
            goto cleanup;
    }

    if (qstrcmp(action, "add") == 0)
        emit deviceDetected(devNode);

    if (qstrcmp(action, "remove") == 0)
        emit deviceRemoved(devNode);

cleanup:
    udev_device_unref(dev);
}
Exemple #19
0
int usbmain(){
    // Load the uinput module (if it's not loaded already)
    if(system("modprobe uinput") != 0)
        ckb_warn("Failed to load uinput module\n");

    // Create the udev object
    if(!(udev = udev_new())){
        ckb_fatal("Failed to initialize udev\n");
        return -1;
    }

    // Enumerate all currently connected devices
    udev_enum();

    // Done scanning. Enter a loop to poll for device updates
    struct udev_monitor* monitor = udev_monitor_new_from_netlink(udev, "udev");
    udev_monitor_filter_add_match_subsystem_devtype(monitor, "usb", 0);
    udev_monitor_enable_receiving(monitor);
    // Get an fd for the monitor
    int fd = udev_monitor_get_fd(monitor);
    fd_set fds;
    while(udev){
        FD_ZERO(&fds);
        FD_SET(fd, &fds);
        // Block until an event is read
        if(select(fd + 1, &fds, 0, 0, 0) > 0 && FD_ISSET(fd, &fds)){
            struct udev_device* dev = udev_monitor_receive_device(monitor);
            if(!dev)
                continue;
            const char* action = udev_device_get_action(dev);
            if(!action){
                udev_device_unref(dev);
                continue;
            }
            // Add/remove device
            if(!strcmp(action, "add")){
                int res = usb_add_device(dev);
                if(res == 0)
                    continue;
                // If the device matched but the handle wasn't opened correctly, re-enumerate (this sometimes solves the problem)
                if(res == -1)
                    udev_enum();
            } else if(!strcmp(action, "remove"))
                usb_rm_device(dev);
            udev_device_unref(dev);
        }
    }
    udev_monitor_unref(monitor);
    return 0;
}
Exemple #20
0
bool CUDevProvider::PumpDriveChangeEvents(IStorageEventsCallback *callback)
{
  bool changed = false;

  fd_set readfds;
  FD_ZERO(&readfds);
  FD_SET(udev_monitor_get_fd(m_udevMon), &readfds);

  // non-blocking, check the file descriptor for received data
  struct timeval tv = {0};
  int count = select(udev_monitor_get_fd(m_udevMon) + 1, &readfds, NULL, NULL, &tv);
  if (count < 0)
    return false;

  if (FD_ISSET(udev_monitor_get_fd(m_udevMon), &readfds))
  {
		struct udev_device *dev = udev_monitor_receive_device(m_udevMon);
    if (!dev)
      return false;

    const char *action  = udev_device_get_action(dev);
    const char *devtype = udev_device_get_devtype(dev);
    if (action)
    {
      const char *label = udev_device_get_property_value(dev, "ID_FS_LABEL");
      const char *mountpoint = get_mountpoint(udev_device_get_devnode(dev));
      if (!label)
        label = URIUtils::GetFileName(mountpoint);

      if (!strcmp(action, "add") && !strcmp(devtype, "partition"))
      {
        CLog::Log(LOGNOTICE, "UDev: Added %s", mountpoint);
        if (callback)
          callback->OnStorageAdded(label, mountpoint);
        changed = true;
      }
      if (!strcmp(action, "remove") && !strcmp(devtype, "partition"))
      {
        CLog::Log(LOGNOTICE, "UDev: Removed %s", mountpoint);
        if (callback)
          callback->OnStorageSafelyRemoved(label);
        changed = true;
      }
    }
    udev_device_unref(dev);
  }

  return changed;
}
Exemple #21
0
int main ()
{
	udev = udev_new();
	if(!udev) {
		fprintf(stderr, "Can't create udev.\n");
		exit(EXIT_FAILURE);
	}

	mon = udev_monitor_new_from_netlink(udev, "udev");
	udev_monitor_filter_add_match_subsystem_devtype(mon, "block", NULL);
	udev_monitor_enable_receiving(mon);

	while(1)
	{
		if (mon != NULL)
			FD_SET(udev_monitor_get_fd(mon), &readfds);
		select(udev_monitor_get_fd(mon) + 1, &readfds, NULL, NULL, NULL);

		if ((mon != NULL) && FD_ISSET(udev_monitor_get_fd(mon), &readfds)) 
		{
			dev = udev_monitor_receive_device(mon);
			if(dev) {
				device = (char *) udev_device_get_sysname(dev);
			}
		}

		devnum = udev_device_get_devnum(dev);
		major = major(devnum);
		minor = minor(devnum);
		action = udev_device_get_action(dev);
		printf("Processing device %s %d:%d\n", action, major, minor);

		struct udev_list_entry * props = udev_device_get_properties_list_entry(dev);
		while(props != NULL)
		{
			printf("%s = %s\n", udev_list_entry_get_name(props), udev_list_entry_get_value(props));
			props = udev_list_entry_get_next (props);
		}

		props = udev_device_get_sysattr_list_entry(dev);
		while(props != NULL)
		{
			printf("%s = %s\n", udev_list_entry_get_name(props), udev_device_get_sysattr_value(dev, udev_list_entry_get_name(props)));
			props = udev_list_entry_get_next (props);
		}
	}

  	return 0;
}
Exemple #22
0
static int udev_handle(int fd) {
  struct udev_device *dev = udev_monitor_receive_device(udev_mon);
  const char *action = udev_device_get_action(dev);
  if (action != NULL) {
    if (autoadd && strcmp("add", action) == 0) {
      const char *devnode = udev_device_get_devnode(dev);
      int id;
      if (devnode != NULL && sscanf(devnode, "/dev/input/event%d", &id) == 1) {
        evdev_create(devnode, defaultMapfile);
      }
    }
    udev_device_unref(dev);
  }
  return LOOP_OK;
}
Exemple #23
0
int udev_handle_events(struct udev_handle *uh)
{
	struct udev_device *device;

	if (!uh || !uh->udev_ctx | !uh->udev_monitor)
		return -1;

	device = udev_monitor_receive_device(uh->udev_monitor);
	if (device == NULL)
	{
		return -1;
	}
	usb_dongle_detect(device);
	udev_device_unref(device);
	return 0;
}
Exemple #24
0
static gboolean monitor_watch(GIOChannel *source, GIOCondition condition,
							gpointer data)
{
	struct udev_device *udevice;

	udevice = udev_monitor_receive_device(monitor);
	if (!udevice)
		return TRUE;

	if (!g_strcmp0(udev_device_get_action(udevice), "add"))
		device_added(udevice);

	udev_device_unref(udevice);

	return TRUE;
}
int l3_listen(struct l3_parity *par, bool daemon, struct l3_location *loc)
{
	struct udev_device *udev_dev;
	const char *parity_status;
	char *err_msg;
	int ret;

again:
	ret = select(par->fd + 1, &par->fdset, NULL, NULL, NULL);
	/* Number of bits set is returned, must be >= 1 */
	if (ret <= 0) {
		return ret;
	}

	assert(FD_ISSET(par->fd, &par->fdset));

	udev_dev = udev_monitor_receive_device(par->uevent_monitor);
	if (!udev_dev)
		return -1;

	parity_status = udev_device_get_property_value(udev_dev, I915_L3_PARITY_UEVENT);
	if (strncmp(parity_status, "1", 1))
		goto again;

	loc->slice = atoi(udev_device_get_property_value(udev_dev, "SLICE"));
	loc->row = atoi(udev_device_get_property_value(udev_dev, "ROW"));
	loc->bank = atoi(udev_device_get_property_value(udev_dev, "BANK"));
	loc->subbank = atoi(udev_device_get_property_value(udev_dev, "SUBBANK"));

	udev_device_unref(udev_dev);

	asprintf(&err_msg, "Parity error detected on: %d,%d,%d,%d. "
			"Try to run intel_l3_parity -r %d -b %d -s %d -w %d -d",
			loc->slice, loc->row, loc->bank, loc->subbank,
			loc->row, loc->bank, loc->subbank, loc->slice);
	if (daemon) {
		syslog(LOG_INFO, "%s\n", err_msg);
		goto again;
	}

	fprintf(stderr, "%s\n", err_msg);

	free(err_msg);

	return 0;
}
Exemple #26
0
void UdevDeviceNotifier::socketActivated()
{
    static const char *keyboardDevice[] = {
        "ID_INPUT_KEYBOARD",
        "ID_INPUT_KEY"
    };

    static const char *pointerDevice[] = {
        "ID_INPUT_MOUSE",
        "ID_INPUT_TOUCHPAD",
        "ID_INPUT_TABLET"
    };

    struct udev_device *dev = udev_monitor_receive_device(m_monitor);
    if (!dev) {
        return;
    }

    const char *action = udev_device_get_action(dev);
    if (!action || qstrcmp(action, "add") != 0) {
        udev_device_unref(dev);
        return;
    }

    // Skip devices with empty name
    if (!udev_device_get_property_value(dev, "NAME")) {
        udev_device_unref(dev);
        return;
    }

    for (unsigned i = 0; i < sizeof(keyboardDevice) / sizeof(keyboardDevice[0]); ++i) {
        if (qstrcmp(udev_device_get_property_value(dev, keyboardDevice[i]), "1") == 0) {
            Q_EMIT newKeyboardDevice();
            break;
        }
    }

    for (unsigned i = 0; i < sizeof(pointerDevice) / sizeof(pointerDevice[0]); ++i) {
        if (qstrcmp(udev_device_get_property_value(dev, pointerDevice[i]), "1") == 0) {
            Q_EMIT newPointerDevice();
            break;
        }
    }

    udev_device_unref(dev);
}
static void udev_hotplug_event(void)
{
	struct udev_device* udev_dev;
	const char* udev_action;
	const char* sys_name = NULL;
	uint8_t busnum = 0, devaddr = 0;
	int detached;
	int r;

	if (NULL == udev_monitor) {
		return;
	}

	do {
		udev_dev = udev_monitor_receive_device(udev_monitor);
		if (!udev_dev) {
			usbi_err(NULL, "failed to read data from udev monitor socket.");
			return;
		}

		udev_action = udev_device_get_action(udev_dev);
		if (!udev_action) {
			break;
		}

		detached = !strncmp(udev_action, "remove", 6);

		r = udev_device_info(NULL, detached, udev_dev, &busnum, &devaddr, &sys_name);
		if (LIBUSB_SUCCESS != r) {
			break;
		}

		usbi_dbg("udev hotplug event. action: %s.", udev_action);

		if (strncmp(udev_action, "add", 3) == 0) {
			linux_hotplug_enumerate(busnum, devaddr, sys_name);
		} else if (detached) {
			linux_hotplug_disconnected(busnum, devaddr, sys_name);
		} else {
			usbi_err(NULL, "ignoring udev action %s", udev_action);
		}
	} while (0);

	udev_device_unref(udev_dev);
}
static int manager_dispatch_link_udev(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
        Manager *m = userdata;
        struct udev_monitor *monitor = m->udev_monitor;
        struct udev_device *device;
        int r;

        device = udev_monitor_receive_device(monitor);
        if (!device)
                return -ENOMEM;

        r = manager_process_link(m, device);
        if (r < 0)
                return r;

        udev_device_unref(device);

        return 0;
}
Exemple #29
0
rw_status_t
rw_udev_recv_device(rw_udev_handle_t *handle)
{
  struct udev_device *dev;
  
  dev = udev_monitor_receive_device(handle->mon);
  if (dev) {
    printf("Got Device\n");
    printf("   Node: %s\n", udev_device_get_devnode(dev));
    printf("   Subsystem: %s\n", udev_device_get_subsystem(dev));
    printf("   Devtype: %s\n", udev_device_get_devtype(dev));
    
    printf("   Action: %s\n", udev_device_get_action(dev));
    udev_device_unref(dev);
  }
  
  return RW_STATUS_SUCCESS;
}
Exemple #30
0
int main (int argc, char* argv[])
{
	struct udev *udev;
	struct udev_device *dev;
	struct udev_monitor *mon;
	int fd;

	/* Create the udev object */
	udev = udev_new();
	if (!udev) {
		printf("Can't create udev\n");
		exit(1);
	}

	/* Set up a monitor to monitor power_supply devices */
	mon = udev_monitor_new_from_netlink(udev, "udev");
	udev_monitor_filter_add_match_subsystem_devtype(mon, "power_supply", NULL);
	udev_monitor_enable_receiving(mon);
	printf("[INFO] Monitoring...\n");

	while (1) {
		dev = udev_monitor_receive_device(mon);
			if (dev) {
				
				if(strcmp(udev_device_get_sysname(dev), "ADP1") == 0) {
					printf("\n  [DEBUG] Found ADP1\n");
					
					if(strcmp(udev_device_get_sysattr_value(dev, "online"), "1") == 0) {
						printf("\n  [INFO] AC Adapter State: Online\n");
						changeBrightness(937);
					}
					
					else if (strcmp(udev_device_get_sysattr_value(dev, "online"), "1") < 0) {
						printf("\n  [INFO] AC Adapter State: Offline\n");
						changeBrightness(92);
					}
				}
			}
		udev_device_unref(dev);
		sleep(2);
		}
	udev_unref(udev);
	return 0;
}