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