chiark / gitweb /
tree-wide: drop license boilerplate
[elogind.git] / src / cgroups-agent / cgroups-agent.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3   This file is part of systemd.
4
5   Copyright 2010 Lennart Poettering
6 ***/
7
8 #include <stdlib.h>
9 #include <sys/socket.h>
10
11 #include "fd-util.h"
12 #include "log.h"
13 #include "socket-util.h"
14
15 /// Additional includes needed by elogind
16 #include "musl_missing.h"
17
18 int main(int argc, char *argv[]) {
19
20         static const union sockaddr_union sa = {
21                 .un.sun_family = AF_UNIX,
22                 .un.sun_path = "/run/systemd/cgroups-agent",
23         };
24
25         _cleanup_close_ int fd = -1;
26         ssize_t n;
27         size_t l;
28
29         if (argc != 2) {
30                 log_error("Incorrect number of arguments.");
31                 return EXIT_FAILURE;
32         }
33
34         elogind_set_program_name(argv[0]);
35         log_set_target(LOG_TARGET_AUTO);
36         log_parse_environment();
37         log_open();
38
39         fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
40         if (fd < 0) {
41                 log_debug_errno(errno, "Failed to allocate socket: %m");
42                 return EXIT_FAILURE;
43         }
44
45         l = strlen(argv[1]);
46
47         n = sendto(fd, argv[1], l, 0, &sa.sa, SOCKADDR_UN_LEN(sa.un));
48         if (n < 0) {
49                 log_debug_errno(errno, "Failed to send cgroups agent message: %m");
50                 return EXIT_FAILURE;
51         }
52
53         if ((size_t) n != l) {
54                 log_debug("Datagram size mismatch");
55                 return EXIT_FAILURE;
56         }
57
58         return EXIT_SUCCESS;
59 }