udev: String substitutions can be done in ENV, too
[systemd_ALT.git] / src / cgroups-agent / cgroups-agent.c
blob16c5a2a6934280e4a2182c9d52d8eafbc3e9489e
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include <stdlib.h>
5 #include "fd-util.h"
6 #include "log.h"
7 #include "socket-util.h"
9 int main(int argc, char *argv[]) {
11 static const union sockaddr_union sa = {
12 .un.sun_family = AF_UNIX,
13 .un.sun_path = "/run/systemd/cgroups-agent",
16 _cleanup_close_ int fd = -EBADF;
17 ssize_t n;
18 size_t l;
19 int r;
21 r = make_null_stdio();
22 if (r < 0) {
23 log_error_errno(r, "Failed to connect stdin/stdout/stderr with /dev/null: %m");
24 return EXIT_FAILURE;
27 if (argc != 2) {
28 log_error("Incorrect number of arguments.");
29 return EXIT_FAILURE;
32 log_setup();
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;
40 l = strlen(argv[1]);
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;
48 if ((size_t) n != l) {
49 log_debug("Datagram size mismatch");
50 return EXIT_FAILURE;
53 return EXIT_SUCCESS;