]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/cgroups-agent/cgroups-agent.c
Merge pull request #7388 from keszybz/doc-tweak
[thirdparty/systemd.git] / src / cgroups-agent / cgroups-agent.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2010 Lennart Poettering
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include <stdlib.h>
21 #include <sys/socket.h>
22
23 #include "fd-util.h"
24 #include "log.h"
25 #include "socket-util.h"
26
27 int main(int argc, char *argv[]) {
28
29 static const union sockaddr_union sa = {
30 .un.sun_family = AF_UNIX,
31 .un.sun_path = "/run/systemd/cgroups-agent",
32 };
33
34 _cleanup_close_ int fd = -1;
35 ssize_t n;
36 size_t l;
37
38 if (argc != 2) {
39 log_error("Incorrect number of arguments.");
40 return EXIT_FAILURE;
41 }
42
43 log_set_target(LOG_TARGET_AUTO);
44 log_parse_environment();
45 log_open();
46
47 fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
48 if (fd < 0) {
49 log_debug_errno(errno, "Failed to allocate socket: %m");
50 return EXIT_FAILURE;
51 }
52
53 l = strlen(argv[1]);
54
55 n = sendto(fd, argv[1], l, 0, &sa.sa, SOCKADDR_UN_LEN(sa.un));
56 if (n < 0) {
57 log_debug_errno(errno, "Failed to send cgroups agent message: %m");
58 return EXIT_FAILURE;
59 }
60
61 if ((size_t) n != l) {
62 log_debug("Datagram size mismatch");
63 return EXIT_FAILURE;
64 }
65
66 return EXIT_SUCCESS;
67 }