chiark / gitweb /
9d98f83508dc805e90b2aa261ba701cb3226a149
[elogind.git] / src / cgroups-agent / cgroups-agent.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2010 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <stdlib.h>
23
24 #include "sd-bus.h"
25 #include "bus-util.h"
26 #include "musl_missing.h"
27 #include "log.h"
28
29 int main(int argc, char *argv[]) {
30         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
31         int r;
32
33         if (argc != 2) {
34                 log_error("Incorrect number of arguments.");
35                 return EXIT_FAILURE;
36         }
37
38         elogind_set_program_name(argv[0]);
39         log_set_target(LOG_TARGET_AUTO);
40         log_parse_environment();
41         log_open();
42
43 #if 0
44         /* We send this event to the private D-Bus socket and then the
45          * system instance will forward this to the system bus. We do
46          * this to avoid an activation loop when we start dbus when we
47          * are called when the dbus service is shut down. */
48
49         r = bus_connect_system_systemd(&bus);
50 #else
51         /* Unlike in systemd where this has to use a private socket,
52            since elogind doesn't associate control groups with services
53            and doesn't manage the dbus service, we can just use the
54            system bus.  */
55         r = sd_bus_open_system(&bus);
56 #endif // 0
57
58         if (r < 0) {
59 #if 0
60                 /* If we couldn't connect we assume this was triggered
61                  * while systemd got restarted/transitioned from
62                  * initrd to the system, so let's ignore this */
63                 log_debug_errno(r, "Failed to get D-Bus connection: %m");
64 #else
65                 /* If dbus isn't running or responding, there is nothing
66                  * we can do about it. */
67                 log_debug_errno(r, "Failed to open system bus: %m");
68 #endif // 0
69                 return EXIT_FAILURE;
70         }
71
72         r = sd_bus_emit_signal(bus,
73                                "/org/freedesktop/elogind/agent",
74                                "org.freedesktop.elogind.Agent",
75                                "Released",
76                                "s", argv[1]);
77         if (r < 0) {
78 #if 0
79                 log_debug_errno(r, "Failed to send signal message on private connection: %m");
80 #else
81                 log_debug_errno(r, "Failed to send signal message: %m");
82 #endif // 0
83                 return EXIT_FAILURE;
84         }
85
86         return EXIT_SUCCESS;
87 }