1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
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.
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.
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/>.
22 #include <dbus/dbus.h>
27 #include "dbus-common.h"
29 int main(int argc, char *argv[]) {
31 DBusConnection *bus = NULL;
32 DBusMessage *m = NULL;
35 dbus_error_init(&error);
38 log_error("Incorrect number of arguments.");
42 log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
43 log_parse_environment();
46 /* If possible we go via the system bus, to make sure that
47 * session instances get the messages. If not possible we talk
48 * to the system instance directly. */
49 if (!(bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) {
51 dbus_error_free(&error);
53 if (!(bus = dbus_connection_open_private("unix:abstract=/org/freedesktop/systemd1/private", &error))) {
54 log_error("Failed to get D-Bus connection: %s", bus_error_message(&error));
58 if (bus_check_peercred(bus) < 0) {
59 log_error("Bus owner not root.");
64 if (!(m = dbus_message_new_signal("/org/freedesktop/systemd1/agent", "org.freedesktop.systemd1.Agent", "Released"))) {
65 log_error("Could not allocate signal message.");
69 if (!dbus_message_append_args(m,
70 DBUS_TYPE_STRING, &argv[1],
72 log_error("Could not attach group information to signal message.");
76 if (!dbus_connection_send(bus, m, NULL)) {
77 log_error("Failed to send signal message.");
85 dbus_connection_close(bus);
86 dbus_connection_unref(bus);
90 dbus_message_unref(m);
92 dbus_error_free(&error);