summaryrefslogtreecommitdiffstats
path: root/src/libudev/test-udev-device-thread.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/libudev/test-udev-device-thread.c
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/libudev/test-udev-device-thread.c')
-rw-r--r--src/libudev/test-udev-device-thread.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/libudev/test-udev-device-thread.c b/src/libudev/test-udev-device-thread.c
new file mode 100644
index 0000000..c082fdc
--- /dev/null
+++ b/src/libudev/test-udev-device-thread.c
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libudev.h"
+
+#define handle_error_errno(error, msg) \
+ ({ \
+ errno = abs(error); \
+ perror(msg); \
+ EXIT_FAILURE; \
+ })
+
+static void* thread(void *p) {
+ struct udev_device **d = p;
+
+ *d = udev_device_unref(*d);
+
+ return NULL;
+}
+
+int main(int argc, char *argv[]) {
+ struct udev_device *loopback;
+ struct udev_list_entry *entry, *e;
+ pthread_t t;
+ int r;
+
+ loopback = udev_device_new_from_syspath(NULL, "/sys/class/net/lo");
+ if (!loopback)
+ return handle_error_errno(errno, "Failed to create loopback device object");
+
+ entry = udev_device_get_properties_list_entry(loopback);
+ udev_list_entry_foreach(e, entry)
+ printf("%s=%s\n", udev_list_entry_get_name(e), udev_list_entry_get_value(e));
+
+ r = pthread_create(&t, NULL, thread, &loopback);
+ if (r != 0)
+ return handle_error_errno(r, "Failed to create thread");
+
+ r = pthread_join(t, NULL);
+ if (r != 0)
+ return handle_error_errno(r, "Failed to wait thread finished");
+
+ if (loopback)
+ return handle_error_errno(r, "loopback device is not unref()ed");
+
+ return 0;
+}