]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |
2 | ||
3 | #include <stdlib.h> | |
4 | #include <sys/socket.h> | |
5 | ||
6 | #include "fd-util.h" | |
7 | #include "log.h" | |
8 | #include "socket-util.h" | |
9 | ||
10 | int main(int argc, char *argv[]) { | |
11 | ||
12 | static const union sockaddr_union sa = { | |
13 | .un.sun_family = AF_UNIX, | |
14 | .un.sun_path = "/run/systemd/cgroups-agent", | |
15 | }; | |
16 | ||
17 | _cleanup_close_ int fd = -1; | |
18 | ssize_t n; | |
19 | size_t l; | |
20 | ||
21 | if (argc != 2) { | |
22 | log_error("Incorrect number of arguments."); | |
23 | return EXIT_FAILURE; | |
24 | } | |
25 | ||
26 | log_setup_service(); | |
27 | ||
28 | fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); | |
29 | if (fd < 0) { | |
30 | log_debug_errno(errno, "Failed to allocate socket: %m"); | |
31 | return EXIT_FAILURE; | |
32 | } | |
33 | ||
34 | l = strlen(argv[1]); | |
35 | ||
36 | n = sendto(fd, argv[1], l, 0, &sa.sa, SOCKADDR_UN_LEN(sa.un)); | |
37 | if (n < 0) { | |
38 | log_debug_errno(errno, "Failed to send cgroups agent message: %m"); | |
39 | return EXIT_FAILURE; | |
40 | } | |
41 | ||
42 | if ((size_t) n != l) { | |
43 | log_debug("Datagram size mismatch"); | |
44 | return EXIT_FAILURE; | |
45 | } | |
46 | ||
47 | return EXIT_SUCCESS; | |
48 | } |