chiark / gitweb /
Add support for building elogind against musl libc
[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 "log.h"
26 #include "bus-util.h"
27
28 int main(int argc, char *argv[]) {
29         _cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
30         int r;
31
32         if (argc != 2) {
33                 log_error("Incorrect number of arguments.");
34                 return EXIT_FAILURE;
35         }
36
37         elogind_set_program_name(argv[0]);
38         log_set_target(LOG_TARGET_AUTO);
39         log_parse_environment();
40         log_open();
41
42 #if 0
43         /* We send this event to the private D-Bus socket and then the
44          * system instance will forward this to the system bus. We do
45          * this to avoid an activation loop when we start dbus when we
46          * are called when the dbus service is shut down. */
47
48         r = bus_open_system_systemd(&bus);
49 #else
50         /* Unlike in systemd where this has to use a private socket,
51            since elogind doesn't associate control groups with services
52            and doesn't manage the dbus service, we can just use the
53            system bus.  */
54         r = sd_bus_open_system(&bus);
55 #endif // 0
56
57         if (r < 0) {
58 #if 0
59                 /* If we couldn't connect we assume this was triggered
60                  * while systemd got restarted/transitioned from
61                  * initrd to the system, so let's ignore this */
62                 log_debug_errno(r, "Failed to get D-Bus connection: %m");
63 #else
64                 /* If dbus isn't running or responding, there is nothing
65                  * we can do about it. */
66                 log_debug_errno(r, "Failed to open system bus: %m");
67 #endif // 0
68                 return EXIT_FAILURE;
69         }
70
71         r = sd_bus_emit_signal(bus,
72                                "/org/freedesktop/elogind/agent",
73                                "org.freedesktop.elogind.Agent",
74                                "Released",
75                                "s", argv[1]);
76         if (r < 0) {
77 #if 0
78                 log_debug_errno(r, "Failed to send signal message on private connection: %m");
79 #else
80                 log_debug_errno(r, "Failed to send signal message: %m");
81 #endif // 0
82                 return EXIT_FAILURE;
83         }
84
85         return EXIT_SUCCESS;
86 }