]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/cgroups-agent/cgroups-agent.c
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / src / cgroups-agent / cgroups-agent.c
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_set_target(LOG_TARGET_AUTO);
27 log_parse_environment();
28 log_open();
29
30 fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
31 if (fd < 0) {
32 log_debug_errno(errno, "Failed to allocate socket: %m");
33 return EXIT_FAILURE;
34 }
35
36 l = strlen(argv[1]);
37
38 n = sendto(fd, argv[1], l, 0, &sa.sa, SOCKADDR_UN_LEN(sa.un));
39 if (n < 0) {
40 log_debug_errno(errno, "Failed to send cgroups agent message: %m");
41 return EXIT_FAILURE;
42 }
43
44 if ((size_t) n != l) {
45 log_debug("Datagram size mismatch");
46 return EXIT_FAILURE;
47 }
48
49 return EXIT_SUCCESS;
50 }