]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/cgroups-agent.c
util: properly detect ttyname_r() failing
[thirdparty/systemd.git] / src / cgroups-agent.c
CommitLineData
d6c9574f 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
8e274523
LP
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 General Public License as published by
10 the Free Software Foundation; either version 2 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 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <dbus/dbus.h>
23
24#include "log.h"
3c661fad 25#include "dbus-common.h"
8e274523
LP
26
27int main(int argc, char *argv[]) {
28 DBusError error;
29 DBusConnection *bus = NULL;
30 DBusMessage *m = NULL;
31 int r = 1;
32
33 dbus_error_init(&error);
34
35 if (argc != 2) {
36 log_error("Incorrect number of arguments.");
37 goto finish;
38 }
39
3c661fad
LP
40 log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
41 log_parse_environment();
42
43 /* If possible we go via the system bus, to make sure that
44 * session instances get the messages. If not possible we talk
45 * to the system instance directly. */
51bc5d4b 46 if (!(bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) {
3c661fad
LP
47
48 dbus_error_free(&error);
49
50 if (!(bus = dbus_connection_open_private("unix:abstract=/org/freedesktop/systemd1/private", &error))) {
51 log_error("Failed to get D-Bus connection: %s", error.message);
52 goto finish;
53 }
54
55 if (bus_check_peercred(bus) < 0) {
56 log_error("Bus owner not root.");
57 goto finish;
58 }
8e274523
LP
59 }
60
61 if (!(m = dbus_message_new_signal("/org/freedesktop/systemd1/agent", "org.freedesktop.systemd1.Agent", "Released"))) {
62 log_error("Could not allocate signal message.");
63 goto finish;
64 }
65
66 if (!dbus_message_append_args(m,
67 DBUS_TYPE_STRING, &argv[1],
68 DBUS_TYPE_INVALID)) {
69 log_error("Could not attach group information to signal message.");
70 goto finish;
71 }
72
73 if (!dbus_connection_send(bus, m, NULL)) {
74 log_error("Failed to send signal message.");
75 goto finish;
76 }
77
78 r = 0;
79
80finish:
51bc5d4b
LP
81 if (bus) {
82 dbus_connection_close(bus);
8e274523 83 dbus_connection_unref(bus);
51bc5d4b 84 }
8e274523
LP
85
86 if (m)
87 dbus_message_unref(m);
88
89 dbus_error_free(&error);
90 return r;
91}