summaryrefslogtreecommitdiff
path: root/src/libudev
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-11-16 11:44:17 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-11-20 14:38:35 +0900
commit5ea78a39e5894297d59ea75b30e250d24bbfc6aa (patch)
tree585f73773786df0c3cbd13fd62d3516bee26a674 /src/libudev
parent170e4380b60cd7911fe72d62ca78445c917967cb (diff)
downloadsystemd-5ea78a39e5894297d59ea75b30e250d24bbfc6aa.tar.gz
libudev-list: move libudev-list related definitions to libudev-list-internal.h
This also rename libudev-private.h to libudev-util.h, and cleanups several unnecessary headers from udev.h and libudev-util.h
Diffstat (limited to 'src/libudev')
-rw-r--r--src/libudev/libudev-device-internal.h2
-rw-r--r--src/libudev/libudev-device.c2
-rw-r--r--src/libudev/libudev-hwdb.c4
-rw-r--r--src/libudev/libudev-list-internal.h24
-rw-r--r--src/libudev/libudev-list.c67
-rw-r--r--src/libudev/libudev-monitor.c5
-rw-r--r--src/libudev/libudev-private.h67
-rw-r--r--src/libudev/libudev-queue.c3
-rw-r--r--src/libudev/libudev-util.c6
-rw-r--r--src/libudev/libudev-util.h24
-rw-r--r--src/libudev/libudev.c1
-rw-r--r--src/libudev/meson.build11
12 files changed, 90 insertions, 126 deletions
diff --git a/src/libudev/libudev-device-internal.h b/src/libudev/libudev-device-internal.h
index 73db709e93..8a6e5a48f6 100644
--- a/src/libudev/libudev-device-internal.h
+++ b/src/libudev/libudev-device-internal.h
@@ -4,7 +4,7 @@
#include "libudev.h"
#include "sd-device.h"
-#include "libudev-private.h"
+#include "libudev-list-internal.h"
/**
* udev_device:
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c
index b6ccef7d8e..37828b2f09 100644
--- a/src/libudev/libudev-device.c
+++ b/src/libudev/libudev-device.c
@@ -23,8 +23,8 @@
#include "device-private.h"
#include "device-util.h"
#include "libudev-device-internal.h"
-#include "libudev-private.h"
#include "parse-util.h"
+#include "time-util.h"
/**
* SECTION:libudev-device
diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c
index efb76a3f02..33c042c02b 100644
--- a/src/libudev/libudev-hwdb.c
+++ b/src/libudev/libudev-hwdb.c
@@ -1,10 +1,12 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
+#include <errno.h>
+
#include "sd-hwdb.h"
#include "alloc-util.h"
#include "hwdb-util.h"
-#include "libudev-private.h"
+#include "libudev-list-internal.h"
/**
* SECTION:libudev-hwdb
diff --git a/src/libudev/libudev-list-internal.h b/src/libudev/libudev-list-internal.h
new file mode 100644
index 0000000000..1f75c37cb2
--- /dev/null
+++ b/src/libudev/libudev-list-internal.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#pragma once
+
+#include "libudev.h"
+
+struct udev_list_node {
+ struct udev_list_node *next, *prev;
+};
+
+struct udev_list {
+ struct udev *udev;
+ struct udev_list_node node;
+ struct udev_list_entry **entries;
+ unsigned entries_cur;
+ unsigned entries_max;
+ bool unique;
+};
+
+void udev_list_init(struct udev *udev, struct udev_list *list, bool unique);
+void udev_list_cleanup(struct udev_list *list);
+struct udev_list_entry *udev_list_get_entry(struct udev_list *list);
+struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *name, const char *value);
+int udev_list_entry_get_num(struct udev_list_entry *list_entry);
+void udev_list_entry_set_num(struct udev_list_entry *list_entry, int num);
diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c
index 03dcd43372..32b4127f99 100644
--- a/src/libudev/libudev-list.c
+++ b/src/libudev/libudev-list.c
@@ -6,7 +6,8 @@
#include <string.h>
#include "alloc-util.h"
-#include "libudev-private.h"
+#include "libudev-list-internal.h"
+#include "util.h"
/**
* SECTION:libudev-list
@@ -30,34 +31,25 @@ struct udev_list_entry {
};
/* the list's head points to itself if empty */
-void udev_list_node_init(struct udev_list_node *list)
-{
+static void udev_list_node_init(struct udev_list_node *list) {
list->next = list;
list->prev = list;
}
-int udev_list_node_is_empty(struct udev_list_node *list)
-{
+static int udev_list_node_is_empty(struct udev_list_node *list) {
return list->next == list;
}
static void udev_list_node_insert_between(struct udev_list_node *new,
struct udev_list_node *prev,
- struct udev_list_node *next)
-{
+ struct udev_list_node *next) {
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
}
-void udev_list_node_append(struct udev_list_node *new, struct udev_list_node *list)
-{
- udev_list_node_insert_between(new, list->prev, list);
-}
-
-void udev_list_node_remove(struct udev_list_node *entry)
-{
+static void udev_list_node_remove(struct udev_list_node *entry) {
struct udev_list_node *prev = entry->prev;
struct udev_list_node *next = entry->next;
@@ -69,13 +61,11 @@ void udev_list_node_remove(struct udev_list_node *entry)
}
/* return list entry which embeds this node */
-static inline struct udev_list_entry *list_node_to_entry(struct udev_list_node *node)
-{
+static inline struct udev_list_entry *list_node_to_entry(struct udev_list_node *node) {
return container_of(node, struct udev_list_entry, node);
}
-void udev_list_init(struct udev *udev, struct udev_list *list, bool unique)
-{
+void udev_list_init(struct udev *udev, struct udev_list *list, bool unique) {
memzero(list, sizeof(struct udev_list));
list->udev = udev;
list->unique = unique;
@@ -83,23 +73,20 @@ void udev_list_init(struct udev *udev, struct udev_list *list, bool unique)
}
/* insert entry into a list as the last element */
-static void udev_list_entry_append(struct udev_list_entry *new, struct udev_list *list)
-{
+static void udev_list_entry_append(struct udev_list_entry *new, struct udev_list *list) {
/* inserting before the list head make the node the last node in the list */
udev_list_node_insert_between(&new->node, list->node.prev, &list->node);
new->list = list;
}
/* insert entry into a list, before a given existing entry */
-static void udev_list_entry_insert_before(struct udev_list_entry *new, struct udev_list_entry *entry)
-{
+static void udev_list_entry_insert_before(struct udev_list_entry *new, struct udev_list_entry *entry) {
udev_list_node_insert_between(&new->node, entry->node.prev, &entry->node);
new->list = entry->list;
}
/* binary search in sorted array */
-static int list_search(struct udev_list *list, const char *name)
-{
+static int list_search(struct udev_list *list, const char *name) {
unsigned first, last;
first = 0;
@@ -200,8 +187,7 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
return entry;
}
-void udev_list_entry_delete(struct udev_list_entry *entry)
-{
+static void udev_list_entry_delete(struct udev_list_entry *entry) {
if (entry->list->entries != NULL) {
int i;
struct udev_list *list = entry->list;
@@ -221,8 +207,12 @@ void udev_list_entry_delete(struct udev_list_entry *entry)
free(entry);
}
-void udev_list_cleanup(struct udev_list *list)
-{
+#define udev_list_entry_foreach_safe(entry, tmp, first) \
+ for (entry = first, tmp = udev_list_entry_get_next(entry); \
+ entry; \
+ entry = tmp, tmp = udev_list_entry_get_next(tmp))
+
+void udev_list_cleanup(struct udev_list *list) {
struct udev_list_entry *entry_loop;
struct udev_list_entry *entry_tmp;
@@ -233,8 +223,7 @@ void udev_list_cleanup(struct udev_list *list)
udev_list_entry_delete(entry_loop);
}
-struct udev_list_entry *udev_list_get_entry(struct udev_list *list)
-{
+struct udev_list_entry *udev_list_get_entry(struct udev_list *list) {
if (udev_list_node_is_empty(&list->node))
return NULL;
return list_node_to_entry(list->node.next);
@@ -248,8 +237,7 @@ struct udev_list_entry *udev_list_get_entry(struct udev_list *list)
*
* Returns: udev_list_entry, #NULL if no more entries are available.
*/
-_public_ struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry)
-{
+_public_ struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry) {
struct udev_list_node *next;
if (list_entry == NULL)
@@ -270,8 +258,7 @@ _public_ struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry
*
* Returns: udev_list_entry, #NULL if no matching entry is found.
*/
-_public_ struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name)
-{
+_public_ struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name) {
int i;
if (list_entry == NULL)
@@ -294,8 +281,7 @@ _public_ struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_en
*
* Returns: the name string of this entry.
*/
-_public_ const char *udev_list_entry_get_name(struct udev_list_entry *list_entry)
-{
+_public_ const char *udev_list_entry_get_name(struct udev_list_entry *list_entry) {
if (list_entry == NULL)
return NULL;
return list_entry->name;
@@ -309,22 +295,19 @@ _public_ const char *udev_list_entry_get_name(struct udev_list_entry *list_entry
*
* Returns: the value string of this entry.
*/
-_public_ const char *udev_list_entry_get_value(struct udev_list_entry *list_entry)
-{
+_public_ const char *udev_list_entry_get_value(struct udev_list_entry *list_entry) {
if (list_entry == NULL)
return NULL;
return list_entry->value;
}
-int udev_list_entry_get_num(struct udev_list_entry *list_entry)
-{
+int udev_list_entry_get_num(struct udev_list_entry *list_entry) {
if (list_entry == NULL)
return -EINVAL;
return list_entry->num;
}
-void udev_list_entry_set_num(struct udev_list_entry *list_entry, int num)
-{
+void udev_list_entry_set_num(struct udev_list_entry *list_entry, int num) {
if (list_entry == NULL)
return;
list_entry->num = num;
diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c
index 5d64dab193..364ec09617 100644
--- a/src/libudev/libudev-monitor.c
+++ b/src/libudev/libudev-monitor.c
@@ -10,7 +10,6 @@
#include "device-private.h"
#include "device-util.h"
#include "libudev-device-internal.h"
-#include "libudev-private.h"
#include "string-util.h"
/**
@@ -65,7 +64,7 @@ static MonitorNetlinkGroup monitor_netlink_group_from_string(const char *name) {
**/
_public_ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name) {
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *m = NULL;
- _cleanup_(udev_monitor_unrefp) struct udev_monitor *udev_monitor = NULL;
+ struct udev_monitor *udev_monitor;
MonitorNetlinkGroup g;
int r;
@@ -93,7 +92,7 @@ _public_ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, c
.monitor = TAKE_PTR(m),
};
- return TAKE_PTR(udev_monitor);
+ return udev_monitor;
}
/**
diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h
deleted file mode 100644
index c79290dfe3..0000000000
--- a/src/libudev/libudev-private.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-#pragma once
-
-#include <signal.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-#include "libudev.h"
-
-#include "macro.h"
-#include "mkdir.h"
-#include "strxcpyx.h"
-#include "util.h"
-
-/* libudev-list.c */
-struct udev_list_node {
- struct udev_list_node *next, *prev;
-};
-struct udev_list {
- struct udev *udev;
- struct udev_list_node node;
- struct udev_list_entry **entries;
- unsigned entries_cur;
- unsigned entries_max;
- bool unique;
-};
-void udev_list_node_init(struct udev_list_node *list);
-int udev_list_node_is_empty(struct udev_list_node *list);
-void udev_list_node_append(struct udev_list_node *new, struct udev_list_node *list);
-void udev_list_node_remove(struct udev_list_node *entry);
-#define udev_list_node_foreach(node, list) \
- for (node = (list)->next; \
- node != list; \
- node = (node)->next)
-#define udev_list_node_foreach_safe(node, tmp, list) \
- for (node = (list)->next, tmp = (node)->next; \
- node != list; \
- node = tmp, tmp = (tmp)->next)
-void udev_list_init(struct udev *udev, struct udev_list *list, bool unique);
-void udev_list_cleanup(struct udev_list *list);
-struct udev_list_entry *udev_list_get_entry(struct udev_list *list);
-struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *name, const char *value);
-void udev_list_entry_delete(struct udev_list_entry *entry);
-int udev_list_entry_get_num(struct udev_list_entry *list_entry);
-void udev_list_entry_set_num(struct udev_list_entry *list_entry, int num);
-#define udev_list_entry_foreach_safe(entry, tmp, first) \
- for (entry = first, tmp = udev_list_entry_get_next(entry); \
- entry != NULL; \
- entry = tmp, tmp = udev_list_entry_get_next(tmp))
-
-/* libudev-util.c */
-#define UTIL_PATH_SIZE 1024
-#define UTIL_NAME_SIZE 512
-#define UTIL_LINE_SIZE 16384
-#define UDEV_ALLOWED_CHARS_INPUT "/ $%?,"
-size_t util_path_encode(const char *src, char *dest, size_t size);
-int util_replace_whitespace(const char *str, char *to, size_t len);
-int util_replace_chars(char *str, const char *white);
-int util_resolve_subsys_kernel(const char *string, char *result, size_t maxsize, int read_value);
-
-/* Cleanup functions */
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev*, udev_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_device*, udev_device_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_enumerate*, udev_enumerate_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_monitor*, udev_monitor_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_hwdb*, udev_hwdb_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_queue*, udev_queue_unref);
diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c
index 832f3b3da5..4ccb3f8736 100644
--- a/src/libudev/libudev-queue.c
+++ b/src/libudev/libudev-queue.c
@@ -9,10 +9,11 @@
#include <sys/inotify.h>
#include <unistd.h>
+#include "libudev.h"
+
#include "alloc-util.h"
#include "fd-util.h"
#include "io-util.h"
-#include "libudev-private.h"
/**
* SECTION:libudev-queue
diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c
index df5223e5a9..8007463581 100644
--- a/src/libudev/libudev-util.c
+++ b/src/libudev/libudev-util.c
@@ -7,11 +7,9 @@
#include <string.h>
#include <unistd.h>
-#include "libudev.h"
-
-#include "MurmurHash2.h"
#include "device-nodes.h"
-#include "libudev-private.h"
+#include "libudev-util.h"
+#include "strxcpyx.h"
#include "utf8.h"
/**
diff --git a/src/libudev/libudev-util.h b/src/libudev/libudev-util.h
new file mode 100644
index 0000000000..fb5558da88
--- /dev/null
+++ b/src/libudev/libudev-util.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#pragma once
+
+#include "libudev.h"
+
+#include "macro.h"
+
+/* libudev-util.c */
+#define UTIL_PATH_SIZE 1024
+#define UTIL_NAME_SIZE 512
+#define UTIL_LINE_SIZE 16384
+#define UDEV_ALLOWED_CHARS_INPUT "/ $%?,"
+size_t util_path_encode(const char *src, char *dest, size_t size);
+int util_replace_whitespace(const char *str, char *to, size_t len);
+int util_replace_chars(char *str, const char *white);
+int util_resolve_subsys_kernel(const char *string, char *result, size_t maxsize, int read_value);
+
+/* Cleanup functions */
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev*, udev_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_device*, udev_device_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_enumerate*, udev_enumerate_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_monitor*, udev_monitor_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_hwdb*, udev_hwdb_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_queue*, udev_queue_unref);
diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c
index 4554b922e3..4c26231f86 100644
--- a/src/libudev/libudev.c
+++ b/src/libudev/libudev.c
@@ -11,7 +11,6 @@
#include "alloc-util.h"
#include "fd-util.h"
-#include "libudev-private.h"
#include "missing.h"
#include "string-util.h"
diff --git a/src/libudev/meson.build b/src/libudev/meson.build
index bd0d5389c9..8d86c34189 100644
--- a/src/libudev/meson.build
+++ b/src/libudev/meson.build
@@ -1,16 +1,17 @@
# SPDX-License-Identifier: LGPL-2.1+
libudev_sources = files('''
- libudev-private.h
- libudev-device-internal.h
libudev.c
- libudev-list.c
- libudev-util.c
libudev-device.c
+ libudev-device-internal.h
libudev-enumerate.c
+ libudev-hwdb.c
+ libudev-list.c
+ libudev-list-internal.h
libudev-monitor.c
libudev-queue.c
- libudev-hwdb.c
+ libudev-util.c
+ libudev-util.h
'''.split())
############################################################