o add DVB variables to kernel, and drop shell script rule
o add watershed extra
- o replace list.h with ccan list.h which is gpl-v2-or-later version
o get all distros to agree on a default set of rules
o rework rules to a match-action list, instead of a rules array
o log warning if the kernel uses CONFIG_SYSFS_DEPRECATED*=y,
#include <sys/types.h>
#include <sys/stat.h>
-#include "../../udev/lib/list.h"
+#include "../../udev/list.h"
#define TMPFILE UDEV_PREFIX "/dev/.udev/collect"
#define BUFSIZE 16
udev_sysfs.c \
udev_utils.c \
udev_utils_file.c \
- lib/list.h \
+ list.h \
lib/libudev.h \
lib/libudev-private.h \
lib/libudev.c \
libudev-device.c \
libudev-enumerate.c \
libudev-ctrl.c \
- libudev-monitor.c \
- list.h
+ libudev-monitor.c
libudev_la_LDFLAGS = \
-version-info $(LIBUDEV_LT_CURRENT):$(LIBUDEV_LT_REVISION):$(LIBUDEV_LT_AGE) \
udev_set_userdata
udev_get_sys_path
udev_get_dev_path
-udev_list_get_next
-udev_list_get_name
-udev_list_get_value
+udev_list_entry_get_next
+udev_list_entry_get_name
+udev_list_entry_get_value
udev_device_new_from_syspath
udev_device_new_from_devnum
udev_device_get_parent
const char *sysname;
char *devnode;
char *subsystem;
- struct list_head devlink_list;
- struct list_head properties_list;
+ struct list_node devlink_list;
+ struct list_node properties_list;
char *action;
int event_timeout;
char *driver;
int num_fake_partitions;
int devlink_priority;
int ignore_remove;
- struct list_head attr_list;
+ struct list_node attr_list;
int info_loaded;
};
memset(udev_device, 0x00, sizeof(struct udev_device));
udev_device->refcount = 1;
udev_device->udev = udev;
- INIT_LIST_HEAD(&udev_device->devlink_list);
- INIT_LIST_HEAD(&udev_device->properties_list);
- INIT_LIST_HEAD(&udev_device->attr_list);
+ list_init(&udev_device->devlink_list);
+ list_init(&udev_device->properties_list);
+ list_init(&udev_device->attr_list);
info(udev_device->udev, "udev_device: %p created\n", udev_device);
return udev_device;
}
while (list != NULL) {
struct udev_device *device_loop;
- device_loop = udev_device_new_from_syspath(udev, udev_list_get_name(list));
+ device_loop = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list));
if (device_loop != NULL) {
if (udev_device_get_devnum(device_loop) == devnum) {
device = device_loop;
}
udev_device_unref(device_loop);
}
- list = udev_list_get_next(list);
+ list = udev_list_entry_get_next(list);
}
udev_enumerate_unref(enumerate);
return device;
*
* Retrieve the list of device links pointing to the device file of
* the udev device. The next list entry can be retrieved with
- * udev_list_next(), which returns #NULL if no more entries exist.
+ * udev_list_entry_next(), which returns #NULL if no more entries exist.
* The devlink path can be retrieved from the list entry by
- * udev_list_get_name(). The path is an absolute path, and starts with
+ * udev_list_entry_get_name(). The path is an absolute path, and starts with
* the device directory.
*
* Returns: the first entry of the device node link list
* @udev_device: udev device
*
* Retrieve the list of key/value device properties of the udev
- * device. The next list entry can be retrieved with udev_list_next(),
+ * device. The next list entry can be retrieved with udev_list_entry_next(),
* which returns #NULL if no more entries exist. The property name
* can be retrieved from the list entry by udev_list_get_name(),
* the property value by udev_list_get_value().
/* look for possibly already cached result */
list = list_get_entry(&udev_device->attr_list);
while (list != NULL) {
- if (strcmp(udev_list_get_name(list), attr) == 0) {
- info(udev_device->udev, "got '%s' (%s) from cache\n", attr, udev_list_get_value(list));
- return udev_list_get_value(list);
+ if (strcmp(udev_list_entry_get_name(list), attr) == 0) {
+ info(udev_device->udev, "got '%s' (%s) from cache\n", attr, udev_list_entry_get_value(list));
+ return udev_list_entry_get_value(list);
}
- list = udev_list_get_next(list);
+ list = udev_list_entry_get_next(list);
}
util_strlcpy(path, udev_device_get_syspath(udev_device), sizeof(path));
if (pos != NULL) {
pos = &pos[1];
info(udev_device->udev, "cache '%s' with link value '%s'\n", attr, pos);
- list = list_insert(udev_device->udev, &udev_device->attr_list, attr, pos, 0);
- val = udev_list_get_value(list);
+ list = list_insert_entry(udev_device->udev, &udev_device->attr_list, attr, pos, 0);
+ val = udev_list_entry_get_value(list);
}
}
goto out;
value[size] = '\0';
util_remove_trailing_chars(value, '\n');
info(udev_device->udev, "'%s' has attribute value '%s'\n", path, value);
- list = list_insert(udev_device->udev, &udev_device->attr_list, attr, value, 0);
- val = udev_list_get_value(list);
+ list = list_insert_entry(udev_device->udev, &udev_device->attr_list, attr, value, 0);
+ val = udev_list_entry_get_value(list);
out:
return val;
}
int device_add_devlink(struct udev_device *udev_device, const char *devlink)
{
- if (list_insert(udev_device->udev, &udev_device->devlink_list, devlink, NULL, 0) == NULL)
+ if (list_insert_entry(udev_device->udev, &udev_device->devlink_list, devlink, NULL, 0) == NULL)
return -ENOMEM;
return 0;
}
int device_add_property(struct udev_device *udev_device, const char *key, const char *value)
{
- if (list_insert(udev_device->udev, &udev_device->properties_list, key, value, 0) == NULL)
+ if (list_insert_entry(udev_device->udev, &udev_device->properties_list, key, value, 0) == NULL)
return -ENOMEM;
return 0;
}
struct udev_enumerate {
struct udev *udev;
int refcount;
- struct list_head devices_list;
+ struct list_node devices_list;
};
struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate)
static int devices_scan_subsystem(struct udev *udev,
const char *basedir, const char *subsystem, const char *subdir,
- struct list_head *device_list)
+ struct list_node *device_list)
{
char path[UTIL_PATH_SIZE];
DIR *dir;
util_strlcat(syspath, "/", sizeof(syspath));
util_strlcat(syspath, dent->d_name, sizeof(syspath));
util_resolve_sys_link(udev, syspath, sizeof(syspath));
- list_insert(udev, device_list, syspath, NULL, 1);
+ list_insert_entry(udev, device_list, syspath, NULL, 1);
}
closedir(dir);
return 0;
static int devices_scan_subsystems(struct udev *udev,
const char *basedir, const char *subsystem, const char *subdir,
- struct list_head *device_list)
+ struct list_node *device_list)
{
char path[UTIL_PATH_SIZE];
DIR *dir;
memset(udev_enumerate, 0x00, (sizeof(struct udev_enumerate)));
udev_enumerate->refcount = 1;
udev_enumerate->udev = udev;
- INIT_LIST_HEAD(&udev_enumerate->devices_list);
+ list_init(&udev_enumerate->devices_list);
/* if we have /sys/subsystem/, forget all the old stuff */
util_strlcpy(base, udev_get_sys_path(udev), sizeof(base));
/* sort delayed devices to the end of the list */
list = list_get_entry(&udev_enumerate->devices_list);
while (list != NULL) {
- if (devices_delay(udev, udev_list_get_name(list)))
- list_move_to_end(list, &udev_enumerate->devices_list);
- list = udev_list_get_next(list);
+ if (devices_delay(udev, udev_list_entry_get_name(list)))
+ list_move_entry_to_end(list, &udev_enumerate->devices_list);
+ list = udev_list_entry_get_next(list);
}
return udev_enumerate;
}
--- /dev/null
+/*
+ * libudev - interface to udev device information
+ *
+ * Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+
+#include "libudev.h"
+#include "libudev-private.h"
+
+struct udev_list {
+ struct udev *udev;
+ struct list_node node;
+ struct list_node *list;
+ char *name;
+ char *value;
+};
+
+static struct udev_list *node_to_entry(struct list_node *node)
+{
+ char *list;
+
+ list = (char *)node;
+ list -= offsetof(struct udev_list, node);
+ return (struct udev_list *)list;
+}
+
+void list_init(struct list_node *list)
+{
+ list->next = list;
+ list->prev = list;
+}
+
+static int list_empty(struct list_node *list)
+{
+ return list->next == list;
+}
+
+#if 0
+static void list_add(struct list_node *new, struct list_node *list)
+{
+ struct list_node *next = list->next;
+
+ next->prev = new;
+ new->next = next;
+ new->prev = list;
+ list->next = new;
+}
+#endif
+
+static void list_add_to_end(struct list_node *new, struct list_node *list)
+{
+ struct list_node *prev = list->prev;
+
+ list->prev = new;
+ new->next = list;
+ new->prev = prev;
+ prev->next = new;
+}
+
+static void list_del(struct list_node *entry)
+{
+ struct list_node *prev = entry->prev;
+ struct list_node *next = entry->next;
+
+ next->prev = prev;
+ prev->next = next;
+}
+
+#define list_for_each_entry(pos, list) \
+ for (pos = node_to_entry((list)->next); \
+ &pos->node != (list); \
+ pos = node_to_entry(pos->node.next))
+
+#define list_for_each_entry_safe(pos, tmp, list) \
+ for (pos = node_to_entry((list)->next), \
+ tmp = node_to_entry(pos->node.next); \
+ &pos->node != (list); \
+ pos = tmp, tmp = node_to_entry(tmp->node.next))
+
+struct udev_list *list_insert_entry(struct udev *udev, struct list_node *list,
+ const char *name, const char *value, int sort)
+{
+ struct udev_list *list_loop;
+ struct udev_list *list_new;
+
+ /* avoid duplicate entries */
+ list_for_each_entry(list_loop, list) {
+ if (strcmp(list_loop->name, name) == 0) {
+ dbg(udev, "'%s' is already in the list\n", name);
+ return list_loop;
+ }
+ }
+
+ if (sort) {
+ list_for_each_entry(list_loop, list) {
+ if (strcmp(list_loop->name, name) > 0)
+ break;
+ }
+ }
+
+ list_new = malloc(sizeof(struct udev_list));
+ if (list_new == NULL)
+ return NULL;
+ memset(list_new, 0x00, sizeof(struct udev_list));
+ list_new->udev = udev;
+ list_new->list = list;
+ list_new->name = strdup(name);
+ if (list_new->name == NULL) {
+ free(list_new);
+ return NULL;
+ }
+ if (value != NULL) {
+ list_new->value = strdup(value);
+ if (list_new->value == NULL) {
+ free(list_new);
+ return NULL;
+ }
+ }
+ dbg(udev, "adding '%s=%s'\n", list_new->name, list_new->value);
+ list_add_to_end(&list_new->node, &list_loop->node);
+ return list_new;
+}
+
+void list_move_entry_to_end(struct udev_list *list_entry, struct list_node *list)
+{
+ list_del(&list_entry->node);
+ list_add_to_end(&list_entry->node, list);
+}
+
+void list_cleanup(struct udev *udev, struct list_node *list)
+{
+ struct udev_list *list_loop;
+ struct udev_list *list_tmp;
+
+ list_for_each_entry_safe(list_loop, list_tmp, list) {
+ list_del(&list_loop->node);
+ free(list_loop->name);
+ free(list_loop->value);
+ free(list_loop);
+ }
+}
+
+struct udev_list *list_get_entry(struct list_node *list)
+{
+ if (list_empty(list))
+ return NULL;
+ return node_to_entry(list->next);
+}
+
+struct udev_list *udev_list_entry_get_next(struct udev_list *list_entry)
+{
+ struct list_node *next;
+
+ next = list_entry->node.next;
+ /* empty list or no more emtries */
+ if (next == list_entry->list)
+ return NULL;
+ return node_to_entry(next);
+}
+
+const char *udev_list_entry_get_name(struct udev_list *list_entry)
+{
+ if (list_entry == NULL)
+ return NULL;
+ return list_entry->name;
+}
+
+const char *udev_list_entry_get_value(struct udev_list *list_entry)
+{
+ if (list_entry == NULL)
+ return NULL;
+ return list_entry->value;
+}
#include <syslog.h>
#include "libudev.h"
-#include "list.h"
#ifdef USE_LOG
#ifdef USE_DEBUG
extern int udev_ctrl_get_set_max_childs(struct udev_ctrl_msg *ctrl_msg);
/* libudev-list */
-extern struct udev_list *list_insert(struct udev *udev, struct list_head *name_list,
- const char *name, const char *value, int sort);
-extern struct udev_list *list_get_entry(struct list_head *list);
-extern void list_move_to_end(struct udev_list *list_entry, struct list_head *list);
-extern void list_cleanup(struct udev *udev, struct list_head *name_list);
+struct list_node {
+ struct list_node *next, *prev;
+};
+extern void list_init(struct list_node *list);
+extern struct udev_list *list_insert_entry(struct udev *udev, struct list_node *name_list,
+ const char *name, const char *value, int sort);
+extern struct udev_list *list_get_entry(struct list_node *list);
+extern void list_move_entry_to_end(struct udev_list *list_entry, struct list_node *list);
+extern void list_cleanup(struct udev *udev, struct list_node *name_list);
/* libudev-utils */
#define UTIL_PATH_SIZE 1024
#define UTIL_LINE_SIZE 2048
#define UTIL_NAME_SIZE 512
-struct util_name_entry {
- struct list_head node;
- char *name;
- char *value;
- int *i;
-};
extern ssize_t util_get_sys_subsystem(struct udev *udev, const char *syspath, char *subsystem, size_t size);
extern ssize_t util_get_sys_driver(struct udev *udev, const char *syspath, char *driver, size_t size);
extern int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size);
extern void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode);
/* list iteration */
-extern struct udev_list *udev_list_get_next(struct udev_list *list_entry);
-extern const char *udev_list_get_name(struct udev_list *list_entry);
-extern const char *udev_list_get_value(struct udev_list *list_entry);
+extern struct udev_list *udev_list_entry_get_next(struct udev_list *list_entry);
+extern const char *udev_list_entry_get_name(struct udev_list *list_entry);
+extern const char *udev_list_entry_get_value(struct udev_list *list_entry);
/* sys devices */
extern struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath);
count = 0;
list = udev_device_get_devlinks_list(device);
while (list != NULL) {
- printf("link: '%s'\n", udev_list_get_name(list));
+ printf("link: '%s'\n", udev_list_entry_get_name(list));
count++;
- list = udev_list_get_next(list);
+ list = udev_list_entry_get_next(list);
}
printf("found %i links\n", count);
count = 0;
list = udev_device_get_properties_list(device);
while (list != NULL) {
- printf("property: '%s=%s'\n", udev_list_get_name(list), udev_list_get_value(list));
+ printf("property: '%s=%s'\n", udev_list_entry_get_name(list), udev_list_entry_get_value(list));
count++;
- list = udev_list_get_next(list);
+ list = udev_list_entry_get_next(list);
}
printf("found %i properties\n", count);
while (list != NULL) {
struct udev_device *device;
- device = udev_device_new_from_syspath(udev, udev_list_get_name(list));
+ device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list));
if (device != NULL) {
printf("device: '%s' (%s) '%s'\n",
udev_device_get_syspath(device),
udev_device_unref(device);
count++;
}
- list = udev_list_get_next(list);
+ list = udev_list_entry_get_next(list);
}
udev_enumerate_unref(enumerate);
printf("found %i devices\n\n", count);
#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1
#include "lib/libudev.h"
#include "lib/libudev-private.h"
-#include "lib/list.h"
+#include "list.h"
#define ALLOWED_CHARS "#+-.:=@_"
#define ALLOWED_CHARS_FILE ALLOWED_CHARS "/"
list = udev_device_get_devlinks_list(device);
while (list != NULL) {
len = strlen(udev_get_dev_path(udev_device_get_udev(device)));
- printf("S: %s\n", &udev_list_get_name(list)[len+1]);
- list = udev_list_get_next(list);
+ printf("S: %s\n", &udev_list_entry_get_name(list)[len+1]);
+ list = udev_list_entry_get_next(list);
}
list = udev_device_get_properties_list(device);
while (list != NULL) {
- printf("E: %s=%s\n", udev_list_get_name(list), udev_list_get_value(list));
- list = udev_list_get_next(list);
+ printf("E: %s=%s\n", udev_list_entry_get_name(list), udev_list_entry_get_value(list));
+ list = udev_list_entry_get_next(list);
}
printf("\n");
while (list != NULL) {
struct udev_device *device;
- device = udev_device_new_from_syspath(udev, udev_list_get_name(list));
+ device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list));
if (device != NULL) {
if (udev_device_get_devnode(device) != NULL)
print_record(device);
udev_device_unref(device);
}
- list = udev_list_get_next(list);
+ list = udev_list_entry_get_next(list);
}
udev_enumerate_unref(enumerate);
return 0;
list = udev_device_get_devlinks_list(device);
while (list != NULL) {
if (root) {
- printf("%s", udev_list_get_name(list));
+ printf("%s", udev_list_entry_get_name(list));
} else {
size_t len;
len = strlen(udev_get_dev_path(udev_device_get_udev(device)));
- printf("%s", &udev_list_get_name(list)[len+1]);
+ printf("%s", &udev_list_entry_get_name(list)[len+1]);
}
- list = udev_list_get_next(list);
+ list = udev_list_entry_get_next(list);
if (list != NULL)
printf(" ");
}
case QUERY_ENV:
list = udev_device_get_properties_list(device);
while (list != NULL) {
- printf("%s=%s\n", udev_list_get_name(list), udev_list_get_value(list));
- list = udev_list_get_next(list);
+ printf("%s=%s\n", udev_list_entry_get_name(list), udev_list_entry_get_value(list));
+ list = udev_list_entry_get_next(list);
}
break;
case QUERY_ALL:
list = udev_device_get_properties_list(device);
while (list != NULL) {
- printf("%s=%s\n", udev_list_get_name(list), udev_list_get_value(list));
- list = udev_list_get_next(list);
+ printf("%s=%s\n", udev_list_entry_get_name(list), udev_list_entry_get_value(list));
+ list = udev_list_entry_get_next(list);
}
printf("\n");
}
list = udev_device_get_properties_list(device);
while (list != NULL) {
- printf("%s=%s\n", udev_list_get_name(list), udev_list_get_value(list));
- list = udev_list_get_next(list);
+ printf("%s=%s\n", udev_list_entry_get_name(list), udev_list_entry_get_value(list));
+ list = udev_list_entry_get_next(list);
}
printf("\n");
}