]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/cgroups-agent/cgroups-agent.c
Merge pull request #23848 from yuwata/core-device-systemd-wants
[thirdparty/systemd.git] / src / cgroups-agent / cgroups-agent.c
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
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 int r;
20
21 r = rearrange_stdio(-1, -1, -1);
22 if (r < 0) {
23 log_error_errno(r, "Failed to connect stdin/stdout/stderr with /dev/null: %m");
24 return EXIT_FAILURE;
25 }
26
27 if (argc != 2) {
28 log_error("Incorrect number of arguments.");
29 return EXIT_FAILURE;
30 }
31
32 log_setup();
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 }