]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
cb3e926a YW |
2 | |
3 | #include <pthread.h> | |
cb3e926a | 4 | #include <stdio.h> |
cb3e926a YW |
5 | |
6 | #include "libudev.h" | |
1cf40697 | 7 | |
a412a1b9 | 8 | #include "tests.h" |
cb3e926a | 9 | |
772e0a76 YW |
10 | #define handle_error_errno(error, msg) \ |
11 | ({ \ | |
f989d285 | 12 | errno = ABS(error); \ |
772e0a76 YW |
13 | perror(msg); \ |
14 | EXIT_FAILURE; \ | |
15 | }) | |
cb3e926a YW |
16 | |
17 | static void* thread(void *p) { | |
18 | struct udev_device **d = p; | |
19 | ||
772e0a76 | 20 | *d = udev_device_unref(*d); |
cb3e926a YW |
21 | |
22 | return NULL; | |
23 | } | |
24 | ||
25 | int main(int argc, char *argv[]) { | |
26 | struct udev_device *loopback; | |
772e0a76 | 27 | struct udev_list_entry *entry, *e; |
cb3e926a | 28 | pthread_t t; |
772e0a76 | 29 | int r; |
cb3e926a | 30 | |
772e0a76 | 31 | loopback = udev_device_new_from_syspath(NULL, "/sys/class/net/lo"); |
a412a1b9 DDM |
32 | if (!loopback) { |
33 | if (errno == ENODEV) | |
34 | return log_tests_skipped_errno(errno, "Loopback device not found"); | |
35 | ||
772e0a76 | 36 | return handle_error_errno(errno, "Failed to create loopback device object"); |
a412a1b9 | 37 | } |
cb3e926a | 38 | |
772e0a76 YW |
39 | entry = udev_device_get_properties_list_entry(loopback); |
40 | udev_list_entry_foreach(e, entry) | |
41 | printf("%s=%s\n", udev_list_entry_get_name(e), udev_list_entry_get_value(e)); | |
cb3e926a | 42 | |
772e0a76 YW |
43 | r = pthread_create(&t, NULL, thread, &loopback); |
44 | if (r != 0) | |
45 | return handle_error_errno(r, "Failed to create thread"); | |
cb3e926a | 46 | |
772e0a76 YW |
47 | r = pthread_join(t, NULL); |
48 | if (r != 0) | |
49 | return handle_error_errno(r, "Failed to wait thread finished"); | |
50 | ||
51 | if (loopback) | |
52 | return handle_error_errno(r, "loopback device is not unref()ed"); | |
cb3e926a YW |
53 | |
54 | return 0; | |
55 | } |