chiark / gitweb /
tree-wide: remove Lennart's copyright lines
[elogind.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 /// Additional includes needed by elogind
11 #include "musl_missing.h"
12
13 int main(int argc, char *argv[]) {
14
15         static const union sockaddr_union sa = {
16                 .un.sun_family = AF_UNIX,
17                 .un.sun_path = "/run/systemd/cgroups-agent",
18         };
19
20         _cleanup_close_ int fd = -1;
21         ssize_t n;
22         size_t l;
23
24         if (argc != 2) {
25                 log_error("Incorrect number of arguments.");
26                 return EXIT_FAILURE;
27         }
28
29         elogind_set_program_name(argv[0]);
30         log_set_target(LOG_TARGET_AUTO);
31         log_parse_environment();
32         log_open();
33
34         fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
35         if (fd < 0) {
36                 log_debug_errno(errno, "Failed to allocate socket: %m");
37                 return EXIT_FAILURE;
38         }
39
40         l = strlen(argv[1]);
41
42         n = sendto(fd, argv[1], l, 0, &sa.sa, SOCKADDR_UN_LEN(sa.un));
43         if (n < 0) {
44                 log_debug_errno(errno, "Failed to send cgroups agent message: %m");
45                 return EXIT_FAILURE;
46         }
47
48         if ((size_t) n != l) {
49                 log_debug("Datagram size mismatch");
50                 return EXIT_FAILURE;
51         }
52
53         return EXIT_SUCCESS;
54 }