| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <pthread.h> |
| 4 |
|
| 5 |
#include "sd-device.h" |
| 6 |
|
| 7 |
#include "device-util.h" |
| 8 |
#include "tests.h" |
| 9 |
|
| 10 |
#define handle_error_errno(error, msg) \ |
| 11 |
({ \ |
| 12 |
errno = ABS(error); \ |
| 13 |
perror(msg); \ |
| 14 |
EXIT_FAILURE; \ |
| 15 |
}) |
| 16 |
|
| 17 |
static void* thread(void *p) { |
| 18 |
sd_device **d = p; |
| 19 |
|
| 20 |
*d = sd_device_unref(*d); |
| 21 |
|
| 22 |
return NULL; |
| 23 |
} |
| 24 |
|
| 25 |
int main(int argc, char *argv[]) { |
| 26 |
sd_device *loopback; |
| 27 |
pthread_t t; |
| 28 |
int r; |
| 29 |
|
| 30 |
r = sd_device_new_from_syspath(&loopback, "/sys/class/net/lo"); |
| 31 |
if (r == -ENODEV) |
| 32 |
return log_tests_skipped("Loopback device not found"); |
| 33 |
if (r < 0) |
| 34 |
return handle_error_errno(r, "Failed to create loopback device object"); |
| 35 |
|
| 36 |
FOREACH_DEVICE_PROPERTY(loopback, key, value) |
| 37 |
printf("%s=%s\n", key, value); |
| 38 |
|
| 39 |
r = pthread_create(&t, NULL, thread, &loopback); |
| 40 |
if (r != 0) |
| 41 |
return handle_error_errno(r, "Failed to create thread"); |
| 42 |
|
| 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"); |
| 49 |
|
| 50 |
return 0; |
| 51 |
} |