//Search for all optical drives
void pup_cd_drive_get_all(PupVMMonitor *monitor)
{
	GDir *block_dir;
	GError *error = NULL;
	g_debug("Init time scanning");
	block_dir = g_dir_open("/sys/block", 0, &error);
	if (error)
	{
		g_critical("Couldn't open /sys/block: %s", error->message);
		g_clear_error(&error);
	}
	
	struct udev *udev_ctx = udev_new();
	gchar *one_sysname;
	while ((one_sysname = (gchar *) g_dir_read_name(block_dir)))
	{
		struct udev_device *dev = udev_device_new_from_subsystem_sysname
			(udev_ctx, "block", one_sysname);
		if (dev)
		{
			g_debug("Testing %s", one_sysname);
			if (pup_drive_test_optical(dev))
			{
				g_debug("Success, now adding to monitor");
				pup_cd_drive_new_from_udev_device(monitor, dev);
			}

			udev_device_unref(dev);
		}
	}
	udev_unref(udev_ctx);
	g_dir_close(block_dir);
}
Ejemplo n.º 2
0
int linux_udev_start_event_monitor(void)
{
	int r;

	assert(udev_ctx == NULL);
	udev_ctx = udev_new();
	if (!udev_ctx) {
		usbi_err(NULL, "could not create udev context");
		return LIBUSB_ERROR_OTHER;
	}

	udev_monitor = udev_monitor_new_from_netlink(udev_ctx, "udev");
	if (!udev_monitor) {
		usbi_err(NULL, "could not initialize udev monitor");
		goto err_free_ctx;
	}

	r = udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", 0);
	if (r) {
		usbi_err(NULL, "could not initialize udev monitor filter for \"usb\" subsystem");
		goto err_free_monitor;
	}

	if (udev_monitor_enable_receiving(udev_monitor)) {
		usbi_err(NULL, "failed to enable the udev monitor");
		goto err_free_monitor;
	}

	udev_monitor_fd = udev_monitor_get_fd(udev_monitor);

	/* Some older versions of udev are not non-blocking by default,
	 * so make sure this is set */
	r = fcntl(udev_monitor_fd, F_GETFL);
	if (r == -1) {
		usbi_err(NULL, "getting udev monitor fd flags (%d)", errno);
		goto err_free_monitor;
	}
	r = fcntl(udev_monitor_fd, F_SETFL, r | O_NONBLOCK);
	if (r) {
		usbi_err(NULL, "setting udev monitor fd flags (%d)", errno);
		goto err_free_monitor;
	}

	r = pthread_create(&linux_event_thread, NULL, linux_udev_event_thread_main, NULL);
	if (r) {
		usbi_err(NULL, "creating hotplug event thread (%d)", r);
		goto err_free_monitor;
	}

	return LIBUSB_SUCCESS;

err_free_monitor:
	udev_monitor_unref(udev_monitor);
	udev_monitor = NULL;
	udev_monitor_fd = -1;
err_free_ctx:
	udev_unref(udev_ctx);
	udev_ctx = NULL;
	return LIBUSB_ERROR_OTHER;
}
Ejemplo n.º 3
0
rw_udev_handle_t*
rw_udev_handle_init(void *userdata, rw_udev_cb_t cb)
{
  rw_udev_handle_t *handle;
  
  handle = RW_MALLOC0(sizeof(*handle));
  
  RW_SKLIST_PARAMS_DECL(pci_list1_,
                        rw_pci_device_t,
                        pci,
                        rw_pci_address_cmp,
                        element);
  RW_SKLIST_INIT(&(handle->dev_list),&pci_list1_);
  
  handle->udev = udev_new();
  if (!handle->udev) {
    goto free_and_ret;
  }

  if (cb){
    rw_udev_register_cb(handle, userdata, cb);
  }
ret:
  return handle;
  
free_and_ret:
  if (handle->udev){
    udev_unref(handle->udev);
    handle->udev = NULL;
  }

  RW_FREE(handle);
  handle = NULL;
  goto ret;
}
Ejemplo n.º 4
0
UdevNotifier::UdevNotifier(QString const & subsystem, QObject * parent/* = nullptr*/)
    : QObject(parent)
    , d(new Impl)
{
    d->udev = udev_new();
    d->monitor = udev_monitor_new_from_netlink(d->udev, "udev");
    if (nullptr == d->monitor)
    {
        qWarning() << QStringLiteral("UdevNotifier: unable to initialize udev_monitor, monitoring will be disabled");
        return;
    }

    int ret = udev_monitor_filter_add_match_subsystem_devtype(d->monitor, subsystem.toUtf8().constData(), nullptr);
    if (0 != ret)
        qWarning() << QStringLiteral("UdevNotifier: unable to add match subsystem, monitor will receive all devices");

    ret = udev_monitor_enable_receiving(d->monitor);
    if (0 != ret)
    {
        qWarning() << QStringLiteral("UdevNotifier: unable to enable receiving(%1), monitoring will be disabled").arg(ret);
        return;
    }

    d->notifier.reset(new QSocketNotifier(udev_monitor_get_fd(d->monitor), QSocketNotifier::Read));
    connect(d->notifier.data(), &QSocketNotifier::activated, this, &UdevNotifier::eventReady);
    d->notifier->setEnabled(true);
}
Ejemplo n.º 5
0
/* add or remove a ACL for a given uid from all matching devices */
static void apply_acl_to_devices(uid_t uid, int add)
{
	struct udev *udev;
	struct udev_enumerate *enumerate;
	struct udev_list_entry *list_entry;

	/* iterate over all devices tagged with ACL_SET */
	udev = udev_new();
	enumerate = udev_enumerate_new(udev);
	udev_enumerate_add_match_tag(enumerate, "udev-acl");
	udev_enumerate_scan_devices(enumerate);
	udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) {
		struct udev_device *device;
		const char *node;

		device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
						      udev_list_entry_get_name(list_entry));
		if (device == NULL)
			continue;
		node = udev_device_get_devnode(device);
		if (node == NULL) {
			udev_device_unref(device);
			continue;
		}
		set_facl(node, uid, add);
		udev_device_unref(device);
	}
	udev_enumerate_unref(enumerate);
	udev_unref(udev);
}
Ejemplo n.º 6
0
static int vlc_sd_probe_Open (vlc_object_t *obj)
{
    vlc_probe_t *probe = (vlc_probe_t *)obj;

    struct udev *udev = udev_new ();
    if (udev == NULL)
        return VLC_PROBE_CONTINUE;

    struct udev_monitor *mon = udev_monitor_new_from_netlink (udev, "udev");
    if (mon != NULL)
    {
        vlc_sd_probe_Add (probe, "v4l{longname=\"Video capture\"}",
                          N_("Video capture"), SD_CAT_DEVICES);
#ifdef HAVE_ALSA
        if (!module_exists ("pulselist"))
            vlc_sd_probe_Add (probe, "alsa{longname=\"Audio capture\"}",
                              N_("Audio capture"), SD_CAT_DEVICES);
#endif
        vlc_sd_probe_Add (probe, "disc{longname=\"Discs\"}", N_("Discs"),
                          SD_CAT_DEVICES);
        udev_monitor_unref (mon);
    }
    udev_unref (udev);
    return VLC_PROBE_CONTINUE;
}
Ejemplo n.º 7
0
char *
loader_get_device_name_for_fd(int fd)
{
   char *device_name = NULL;
#ifdef HAVE_LIBUDEV
   struct udev *udev;
   struct udev_device *device;
   const char *const_device_name;
   UDEV_SYMBOL(struct udev *, udev_new, (void));
   UDEV_SYMBOL(const char *, udev_device_get_devnode,
               (struct udev_device *));
   UDEV_SYMBOL(struct udev_device *, udev_device_unref,
               (struct udev_device *));
   UDEV_SYMBOL(struct udev *, udev_unref, (struct udev *));

   udev = udev_new();
   device = udev_device_new_from_fd(udev, fd);
   if (device == NULL)
      return NULL;

   const_device_name = udev_device_get_devnode(device);
   if (!const_device_name)
      goto out;
   device_name = strdup(const_device_name);

out:
   udev_device_unref(device);
   udev_unref(udev);
#endif
   return device_name;
}
Ejemplo n.º 8
0
END_TEST

START_TEST(udev_create_empty_seat)
{
	struct libinput *li;
	struct libinput_event *event;
	struct udev *udev;
	int fd;

	udev = udev_new();
	ck_assert(udev != NULL);

	/* expect a libinput reference, but no events */
	li = libinput_create_from_udev(&simple_interface, NULL, udev, "seatdoesntexist");
	ck_assert(li != NULL);

	fd = libinput_get_fd(li);
	ck_assert_int_ge(fd, 0);

	libinput_dispatch(li);
	event = libinput_get_event(li);
	ck_assert(event == NULL);

	libinput_event_destroy(event);
	libinput_destroy(li);
	udev_unref(udev);
}
Ejemplo n.º 9
0
END_TEST

START_TEST(udev_create_seat0)
{
	struct libinput *li;
	struct libinput_event *event;
	struct udev *udev;
	int fd;

	udev = udev_new();
	ck_assert(udev != NULL);

	li = libinput_create_from_udev(&simple_interface, NULL, udev, "seat0");
	ck_assert(li != NULL);

	fd = libinput_get_fd(li);
	ck_assert_int_ge(fd, 0);

	/* expect at least one event */
	libinput_dispatch(li);
	event = libinput_get_event(li);
	ck_assert(event != NULL);

	libinput_event_destroy(event);
	libinput_destroy(li);
	udev_unref(udev);
}
Ejemplo n.º 10
0
static char *
drm_get_device_name(int fd)
{
   char *device_name = NULL;
#ifdef HAVE_LIBUDEV
   struct udev *udev;
   struct udev_device *device;
   struct stat buf;
   const char *tmp;

   udev = udev_new();
   if (fstat(fd, &buf) < 0) {
      _eglLog(_EGL_WARNING, "failed to stat fd %d", fd);
      goto out;
   }

   device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev);
   if (device == NULL) {
      _eglLog(_EGL_WARNING,
              "could not create udev device for fd %d", fd);
      goto out;
   }

   tmp = udev_device_get_devnode(device);
   if (!tmp)
      goto out;
   device_name = strdup(tmp);

out:
   udev_device_unref(device);
   udev_unref(udev);

#endif
   return device_name;
}
Ejemplo n.º 11
0
int main(void) {
        _cleanup_manager_free_ Manager *manager = NULL;
        struct udev *udev;
        struct udev_device *loopback;

        assert_se(manager_new(&manager) >= 0);

        test_load_config(manager);

        udev = udev_new();
        assert_se(udev);

        loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
        assert_se(loopback);
        assert_se(udev_device_get_ifindex(loopback) == 1);

        test_network_get(manager, loopback);

        test_link(manager, loopback);

        assert_se(manager_udev_listen(manager) >= 0);
        assert_se(manager_udev_enumerate_links(manager) >= 0);
        assert_se(manager_rtnl_listen(manager) >= 0);

        udev_device_unref(loopback);
        udev_unref(udev);
}
Ejemplo n.º 12
0
char *batocomp(const bdaddr_t *ba)
{
	struct udev *udev;
	struct udev_hwdb *hwdb;
	struct udev_list_entry *head, *entry;
	char modalias[11], *comp = NULL;

	sprintf(modalias, "OUI:%2.2X%2.2X%2.2X", ba->b[5], ba->b[4], ba->b[3]);

	udev = udev_new();
	if (!udev)
		return NULL;

	hwdb = udev_hwdb_new(udev);
	if (!hwdb)
		goto done;

	head = udev_hwdb_get_properties_list_entry(hwdb, modalias, 0);

	udev_list_entry_foreach(entry, head) {
		const char *name = udev_list_entry_get_name(entry);

		if (name && !strcmp(name, "ID_OUI_FROM_DATABASE")) {
			comp = strdup(udev_list_entry_get_value(entry));
			break;
		}
	}

	hwdb = udev_hwdb_unref(hwdb);

done:
	udev = udev_unref(udev);

	return comp;
}
Ejemplo n.º 13
0
static int loopback_list_get(MountPoint **head) {
        _cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL;
        struct udev_list_entry *item = NULL, *first = NULL;
        _cleanup_udev_unref_ struct udev *udev = NULL;
        int r;

        assert(head);

        udev = udev_new();
        if (!udev)
                return -ENOMEM;

        e = udev_enumerate_new(udev);
        if (!e)
                return -ENOMEM;

        r = udev_enumerate_add_match_subsystem(e, "block");
        if (r < 0)
                return r;

        r = udev_enumerate_add_match_sysname(e, "loop*");
        if (r < 0)
                return r;

        r = udev_enumerate_add_match_sysattr(e, "loop/backing_file", NULL);
        if (r < 0)
                return r;

        r = udev_enumerate_scan_devices(e);
        if (r < 0)
                return r;

        first = udev_enumerate_get_list_entry(e);
        udev_list_entry_foreach(item, first) {
                MountPoint *lb;
                _cleanup_udev_device_unref_ struct udev_device *d;
                char *loop;
                const char *dn;

                d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item));
                if (!d)
                        return -ENOMEM;

                dn = udev_device_get_devnode(d);
                if (!dn)
                        continue;

                loop = strdup(dn);
                if (!loop)
                        return -ENOMEM;

                lb = new0(MountPoint, 1);
                if (!lb) {
                        free(loop);
                        return -ENOMEM;
                }

                lb->path = loop;
                LIST_PREPEND(mount_point, *head, lb);
        }
Ejemplo n.º 14
0
static int sixaxis_init(void)
{
	GIOChannel *channel;

	DBG("");

	ctx = udev_new();
	if (!ctx)
		return -EIO;

	monitor = udev_monitor_new_from_netlink(ctx, "udev");
	if (!monitor) {
		udev_unref(ctx);
		ctx = NULL;

		return -EIO;
	}

	/* Listen for newly connected hidraw interfaces */
	udev_monitor_filter_add_match_subsystem_devtype(monitor, "hidraw",
									NULL);
	udev_monitor_enable_receiving(monitor);

	channel = g_io_channel_unix_new(udev_monitor_get_fd(monitor));
	watch_id = g_io_add_watch(channel, G_IO_IN, monitor_watch, NULL);
	g_io_channel_unref(channel);

	return 0;
}
Ejemplo n.º 15
0
udev_handler::udev_handler() {
  udev = udev_new();
  if (udev == nullptr) throw - 11;

  monitor = nullptr;
  monitor_thread = nullptr;
}
Ejemplo n.º 16
0
static virDrvOpenStatus
udevInterfaceOpen(virConnectPtr conn,
                  virConnectAuthPtr auth ATTRIBUTE_UNUSED,
                  unsigned int flags)
{
    struct udev_iface_driver *driverState = NULL;

    virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);

    if (VIR_ALLOC(driverState) < 0)
        goto cleanup;

    driverState->udev = udev_new();
    if (!driverState->udev) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("failed to create udev context"));
        goto cleanup;
    }

    conn->interfacePrivateData = driverState;

    return VIR_DRV_OPEN_SUCCESS;

 cleanup:
    VIR_FREE(driverState);

    return VIR_DRV_OPEN_ERROR;
}
Ejemplo n.º 17
0
int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_id) {
#if 0 /* NM_IGNORED */
        /* name is a pointer to memory in the udev_device struct, so must
           have the same scope */
        _cleanup_udev_device_unref_ struct udev_device *device = NULL;
#else /* NM_IGNORED */
        char name_buf[IF_NAMESIZE];
#endif /* NM_IGNORED */
        const char *name = NULL;
        uint64_t id;

#if 0 /* NM_IGNORED */
        if (detect_container() <= 0) {
                /* not in a container, udev will be around */
                _cleanup_udev_unref_ struct udev *udev;
                char ifindex_str[2 + DECIMAL_STR_MAX(int)];

                udev = udev_new();
                if (!udev)
                        return -ENOMEM;

                sprintf(ifindex_str, "n%d", ifindex);
                device = udev_device_new_from_device_id(udev, ifindex_str);
                if (device) {
                        if (udev_device_get_is_initialized(device) <= 0)
                                /* not yet ready */
                                return -EBUSY;

                        name = net_get_name(device);
                }
        }
Ejemplo n.º 18
0
int fs_on_read_only(const char *p) {
        struct stat st;
        struct udev *udev = NULL;
        struct udev_device *udev_device = NULL;
        bool b = false;
        const char *read_only;

        assert(p);

        if (stat(p, &st) < 0)
                return -errno;

        if (major(st.st_dev) == 0)
                return false;

        if (!(udev = udev_new()))
                return -ENOMEM;

        if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev)))
                goto finish;

        if ((read_only = udev_device_get_sysattr_value(udev_device, "ro")))
                if ((b = streq(read_only, "1")))
                        goto finish;

finish:
        if (udev_device)
                udev_device_unref(udev_device);

        if (udev)
                udev_unref(udev);

        return b;
}
Ejemplo n.º 19
0
QTM_BEGIN_NAMESPACE

QUdevService::QUdevService()
{
    // NOTE: udev_new can fail, if we get a NULL pointer back, can't create udev
    context = udev_new();
}
Ejemplo n.º 20
0
void QNetworkInfoPrivate::connectNotify(const QMetaMethod &signal)
{
#if !defined(QT_NO_OFONO)
    if (QOfonoWrapper::isOfonoAvailable()) {
        if (!ofonoWrapper)
            ofonoWrapper = new QOfonoWrapper(this);
        QMetaMethod sourceSignal = proxyToSourceSignal(signal, ofonoWrapper);
        connect(ofonoWrapper, sourceSignal, this, signal, Qt::UniqueConnection);
    }
#endif

    static const QMetaMethod currentNetworkModeChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoPrivate::currentNetworkModeChanged);
    static const QMetaMethod networkNameChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoPrivate::networkNameChanged);
    static const QMetaMethod networkSignalStrengthChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoPrivate::networkSignalStrengthChanged);
    static const QMetaMethod networkStatusChangedSignal = QMetaMethod::fromSignal(&QNetworkInfoPrivate::networkStatusChanged);

    //    we always monitor "networkInterfaceCount" , as long as users connect any signals,
    //    with update to date network interface counts, we can compute network mode, strength,
    //    status, name properties in an efficient way
    if (!watchNetworkInterfaceCount) {
        QList<QNetworkInfo::NetworkMode> modes;
        modes << QNetworkInfo::WlanMode << QNetworkInfo::EthernetMode << QNetworkInfo::BluetoothMode;
        networkInterfaceCounts.clear();
        foreach (QNetworkInfo::NetworkMode mode, modes)
            networkInterfaceCounts[mode] = getNetworkInterfaceCount(mode);
#if !defined(QT_NO_UDEV)
        if (!udevHandle) {
            udevHandle = udev_new();
            udevMonitor = udev_monitor_new_from_netlink(udevHandle, "udev");
            udev_monitor_filter_add_match_subsystem_devtype(udevMonitor, "net", NULL);
            udev_monitor_enable_receiving(udevMonitor);
            udevNotifier = new QSocketNotifier(udev_monitor_get_fd(udevMonitor), QSocketNotifier::Read, this);
            connect(udevNotifier, SIGNAL(activated(int)), this, SLOT(onUdevChanged()));
        }
Ejemplo n.º 21
0
bool Renderer::connectEmotiv()
{
   /* Opens Emotiv if Emotiv is only HID Device attached */
  struct udev_device *dev;
  struct udev *udev;
  struct udev_list_entry *devices, *dev_list_entry;
  struct udev_enumerate *enumerate;
  udev = udev_new();
  enumerate = udev_enumerate_new(udev);
  udev_enumerate_add_match_subsystem(enumerate, "hidraw");
  udev_enumerate_scan_devices(enumerate);
  devices = udev_enumerate_get_list_entry(enumerate);
  udev_list_entry_foreach(dev_list_entry, devices) 
    {
      const char * path = udev_list_entry_get_name(dev_list_entry);
      dev = udev_device_new_from_syspath(udev,path);
    }
  emotiv_fd = open(udev_device_get_devnode(dev), O_RDONLY);
  if (emotiv_fd > 0) 
    {
      int res = read(emotiv_fd, emotivBuffer, 32);
      if(res < 0) {perror("read"); return false;}
      return true;
    }
  else 
    {
      perror("Unable to open device");
      return false;
    }
}
Ejemplo n.º 22
0
int linux_udev_start_event_monitor(void)
{
	int r;

	if (NULL == udev_ctx) {
		udev_ctx = udev_new();
		if (!udev_ctx) {
			return LIBUSB_ERROR_OTHER;
		}
	}

        udev_monitor = udev_monitor_new_from_netlink(udev_ctx, "udev");
        if (!udev_monitor) {
                usbi_err(NULL, "could not initialize udev monitor");
                return LIBUSB_ERROR_OTHER;
        }

        r = udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", 0);
        if (r) {
                usbi_err(NULL, "could not initialize udev monitor filter for \"usb\" subsystem");
                return LIBUSB_ERROR_OTHER;
        }

        if (udev_monitor_enable_receiving(udev_monitor)) {
                usbi_err(NULL, "failed to enable the udev monitor");
                return LIBUSB_ERROR_OTHER;
        }

        udev_monitor_fd = udev_monitor_get_fd(udev_monitor);

        pthread_create(&linux_event_thread, NULL, linux_udev_event_thread_main, NULL);

        return LIBUSB_SUCCESS;
}
Ejemplo n.º 23
0
Archivo: usb.c Proyecto: seec/TL866
int get_device_count()
{
    struct udev *udev = udev_new();
    if (!udev)
    {
        return -1;
    }

    struct udev_enumerate *enumerate;
    struct udev_list_entry *devices, *dev_list_entry;
    struct udev_device *dev;

    enumerate = udev_enumerate_new(udev);
    udev_enumerate_add_match_subsystem(enumerate, "usb");
    udev_enumerate_scan_devices(enumerate);
    devices = udev_enumerate_get_list_entry(enumerate);
    const char *path;
    int count = 0;
    udev_list_entry_foreach(dev_list_entry, devices)
    {

        path = udev_list_entry_get_name(dev_list_entry);
        dev = udev_device_new_from_syspath(udev, path);
        if(!dev)
            return -1;

        const char * vid = udev_device_get_sysattr_value(dev,"idVendor");
        const char * pid = udev_device_get_sysattr_value(dev,"idProduct");
        if((vid && pid) && (!strcmp(vid, "04d8") && (!strcmp(pid, "e11c"))))
            count++;
        udev_device_unref(dev);
    }
Ejemplo n.º 24
0
eErrorCode GetAdapterBus(DeviceHandle& Handle, String SysDevicePath)
{
    struct udev *udevObject;
    struct udev_device *udevDevice;

    udevObject = udev_new();
    if (nullptr == udevObject)
    {
        return(eErrorCode::Memory);
    }
    udevDevice = udev_device_new_from_syspath(udevObject, SysDevicePath.c_str());

    if (true == IsAtaDeviceBus(udevDevice))
    {
        Handle.Bus = eBusType::Ata;
    }
    else if (true == IsScsiDeviceBus(udevDevice))
    {
        Handle.Bus = eBusType::Scsi;
    }
    else
    {
        //! Adapter Property is not Ata or Scsi
        return(eErrorCode::FormatNotSupported);
    }

    udev_device_unref(udevDevice);
    udev_unref(udevObject);

    return(eErrorCode::None);
}
Ejemplo n.º 25
0
static inline int media_udev_open(struct udev **udev)
{
	*udev = udev_new();
	if (*udev == NULL)
		return -ENOMEM;
	return 0;
}
Ejemplo n.º 26
0
/**
 * Sets up callbacks for device hotplug events.
 */
ULONG HPRegisterForHotplugEvents(void)
{
	struct udev *udev;

	(void)pthread_mutex_init(&usbNotifierMutex, NULL);

	if (driverSize <= 0)
	{
		Log1(PCSC_LOG_INFO, "No bundle files in pcsc drivers directory: "
			PCSCLITE_HP_DROPDIR);
		Log1(PCSC_LOG_INFO, "Disabling USB support for pcscd");
		return 0;
	}

	/* Create the udev object */
	udev = udev_new();
	if (!udev)
	{
		Log1(PCSC_LOG_ERROR, "udev_new() failed");
		return 0;
	}

	HPRescanUsbBus(udev);

	(void)ThreadCreate(&usbNotifyThread, THREAD_ATTR_DETACHED,
		(PCSCLITE_THREAD_FUNCTION( )) HPEstablishUSBNotifications, udev);

	return 0;
} /* HPRegisterForHotplugEvents */
Ejemplo n.º 27
0
int
main(int argc, char **argv)
{
	int blight, connector_id;
	const char *path;
	struct udev *udev;
	struct udev_enumerate *e;
	struct udev_list_entry *entry;
	struct udev_device *drm_device;

	if (argc < 3) {
		printf("Please add connector_id and brightness values from 0-255\n");
		return 1;
	}

	connector_id = atoi(argv[1]);
	blight = atoi(argv[2]);

	udev = udev_new();
	if (udev == NULL) {
		printf("failed to initialize udev context\n");
		return 1;
	}

	e = udev_enumerate_new(udev);
	udev_enumerate_add_match_subsystem(e, "drm");
	udev_enumerate_add_match_sysname(e, "card[0-9]*");

	udev_enumerate_scan_devices(e);
	drm_device = NULL;
	udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
		path = udev_list_entry_get_name(entry);
		drm_device = udev_device_new_from_syspath(udev, path);
		break;
	}
Ejemplo n.º 28
0
int
wgbm_get_default_fd_for_pattern(const char *pattern)
{
    struct udev *ud;
    struct udev_enumerate *en;
    struct udev_list_entry *devices, *entry;
    const char *path, *filename;
    struct udev_device *device;
    int fd;

    ud = udev_new();
    en = udev_enumerate_new(ud);
    udev_enumerate_add_match_subsystem(en, "drm");
    udev_enumerate_add_match_sysname(en, pattern);
    udev_enumerate_scan_devices(en);
    devices = udev_enumerate_get_list_entry(en);

    udev_list_entry_foreach(entry, devices) {
        path = udev_list_entry_get_name(entry);
        device = udev_device_new_from_syspath(ud, path);
        filename = udev_device_get_devnode(device);
        fd = open(filename, O_RDWR | O_CLOEXEC);
        udev_device_unref(device);
        if (fd >= 0) {
            udev_enumerate_unref(en);
            udev_unref(ud);
            return fd;
        }
    }
Ejemplo n.º 29
0
int fs_on_read_only(const char *p) {
        struct stat st;
        _cleanup_udev_unref_ struct udev *udev = NULL;
        _cleanup_udev_device_unref_ struct udev_device *udev_device = NULL;
        const char *read_only;

        assert(p);

        if (stat(p, &st) < 0)
                return -errno;

        if (major(st.st_dev) == 0)
                return false;

        udev = udev_new();
        if (!udev)
                return -ENOMEM;

        udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev);
        if (!udev_device)
                return false;

        read_only = udev_device_get_sysattr_value(udev_device, "ro");
        if (read_only)
                return streq(read_only, "1");

        return false;
}
Ejemplo n.º 30
0
int main(void) {
        _cleanup_manager_free_ Manager *manager = NULL;
        struct udev *udev;
        struct udev_device *loopback;
        int r;

        test_deserialize_in_addr();
        test_deserialize_dhcp_routes();
        test_address_equality();

        assert_se(manager_new(&manager) >= 0);

        r = test_load_config(manager);
        if (r == -EPERM)
                return EXIT_TEST_SKIP;

        udev = udev_new();
        assert_se(udev);

        loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
        assert_se(loopback);
        assert_se(udev_device_get_ifindex(loopback) == 1);

        test_network_get(manager, loopback);

        assert_se(manager_rtnl_enumerate_links(manager) >= 0);

        udev_device_unref(loopback);
        udev_unref(udev);
}