]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
cb3e926a | 2 | |
772e0a76 | 3 | #include <errno.h> |
cb3e926a | 4 | #include <pthread.h> |
cb3e926a YW |
5 | #include <stdio.h> |
6 | #include <stdlib.h> | |
7 | ||
8 | #include "libudev.h" | |
9 | ||
772e0a76 YW |
10 | #define handle_error_errno(error, msg) \ |
11 | ({ \ | |
12 | errno = abs(error); \ | |
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 YW |
31 | loopback = udev_device_new_from_syspath(NULL, "/sys/class/net/lo"); |
32 | if (!loopback) | |
33 | return handle_error_errno(errno, "Failed to create loopback device object"); | |
cb3e926a | 34 | |
772e0a76 YW |
35 | entry = udev_device_get_properties_list_entry(loopback); |
36 | udev_list_entry_foreach(e, entry) | |
37 | printf("%s=%s\n", udev_list_entry_get_name(e), udev_list_entry_get_value(e)); | |
cb3e926a | 38 | |
772e0a76 YW |
39 | r = pthread_create(&t, NULL, thread, &loopback); |
40 | if (r != 0) | |
41 | return handle_error_errno(r, "Failed to create thread"); | |
cb3e926a | 42 | |
772e0a76 YW |
43 | r = pthread_join(t, NULL); |
44 | if (r != 0) | |
45 | return handle_error_errno(r, "Failed to wait thread finished"); | |
46 | ||
47 | if (loopback) | |
48 | return handle_error_errno(r, "loopback device is not unref()ed"); | |
cb3e926a YW |
49 | |
50 | return 0; | |
51 | } |