| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <sys/eventfd.h> |
| 4 |
|
| 5 |
#include "sd-daemon.h" |
| 6 |
|
| 7 |
#include "fd-util.h" |
| 8 |
#include "parse-util.h" |
| 9 |
#include "pidfd-util.h" |
| 10 |
#include "process-util.h" |
| 11 |
#include "strv.h" |
| 12 |
#include "tests.h" |
| 13 |
#include "time-util.h" |
| 14 |
|
| 15 |
int main(int argc, char *argv[]) { |
| 16 |
_cleanup_strv_free_ char **l = NULL; |
| 17 |
int r, n, i; |
| 18 |
usec_t duration = USEC_PER_SEC / 10; |
| 19 |
|
| 20 |
test_setup_logging(LOG_DEBUG); |
| 21 |
|
| 22 |
if (argc >= 2) { |
| 23 |
unsigned x; |
| 24 |
|
| 25 |
ASSERT_OK(safe_atou(argv[1], &x)); |
| 26 |
duration = x * USEC_PER_SEC; |
| 27 |
} |
| 28 |
|
| 29 |
n = sd_listen_fds_with_names(false, &l); |
| 30 |
if (n < 0) { |
| 31 |
log_error_errno(n, "Failed to get listening fds: %m"); |
| 32 |
return EXIT_FAILURE; |
| 33 |
} |
| 34 |
|
| 35 |
for (i = 0; i < n; i++) |
| 36 |
log_info("fd=%i name=%s", SD_LISTEN_FDS_START + i, l[i]); |
| 37 |
|
| 38 |
sd_notify(0, |
| 39 |
"STATUS=Starting up"); |
| 40 |
usleep_safe(duration); |
| 41 |
|
| 42 |
sd_notify(0, |
| 43 |
"STATUS=Running\n" |
| 44 |
"READY=1"); |
| 45 |
usleep_safe(duration); |
| 46 |
|
| 47 |
sd_notify(0, |
| 48 |
"STATUS=Reloading\n" |
| 49 |
"RELOADING=1"); |
| 50 |
usleep_safe(duration); |
| 51 |
|
| 52 |
sd_notify(0, |
| 53 |
"STATUS=Running\n" |
| 54 |
"READY=1"); |
| 55 |
usleep_safe(duration); |
| 56 |
|
| 57 |
sd_notify(0, |
| 58 |
"STATUS=Quitting\n" |
| 59 |
"STOPPING=1"); |
| 60 |
usleep_safe(duration); |
| 61 |
|
| 62 |
_cleanup_close_ int fd = eventfd(0, EFD_CLOEXEC); |
| 63 |
ASSERT_OK_ERRNO(fd); |
| 64 |
|
| 65 |
r = sd_pidfd_get_inode_id(fd, NULL); |
| 66 |
ASSERT_TRUE(IN_SET(r, -EOPNOTSUPP, -EBADF)); |
| 67 |
if (r == -EBADF) { |
| 68 |
safe_close(fd); |
| 69 |
ASSERT_OK_ERRNO(fd = pidfd_open(getpid_cached(), 0)); |
| 70 |
ASSERT_OK(sd_pidfd_get_inode_id(fd, NULL)); |
| 71 |
} |
| 72 |
|
| 73 |
return EXIT_SUCCESS; |
| 74 |
} |