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