]>
Commit | Line | Data |
---|---|---|
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 | ||
22f4096c LP |
24 | #include <stdlib.h> |
25 | ||
8e274523 | 26 | #include "log.h" |
3c661fad | 27 | #include "dbus-common.h" |
8e274523 LP |
28 | |
29 | int main(int argc, char *argv[]) { | |
30 | DBusError error; | |
31 | DBusConnection *bus = NULL; | |
32 | DBusMessage *m = NULL; | |
22f4096c | 33 | int r = EXIT_FAILURE; |
8e274523 LP |
34 | |
35 | dbus_error_init(&error); | |
36 | ||
37 | if (argc != 2) { | |
38 | log_error("Incorrect number of arguments."); | |
39 | goto finish; | |
40 | } | |
41 | ||
3c661fad LP |
42 | log_set_target(LOG_TARGET_SYSLOG_OR_KMSG); |
43 | log_parse_environment(); | |
2396fb04 | 44 | log_open(); |
3c661fad | 45 | |
53c6a358 LP |
46 | |
47 | /* We send this event to the private D-Bus socket and then the | |
48 | * system instance will forward this to the system bus. We do | |
35b8ca3a | 49 | * this to avoid an activation loop when we start dbus when we |
53c6a358 LP |
50 | * are called when the dbus service is shut down. */ |
51 | ||
52 | if (!(bus = dbus_connection_open_private("unix:abstract=/org/freedesktop/systemd1/private", &error))) { | |
53 | log_error("Failed to get D-Bus connection: %s", bus_error_message(&error)); | |
54 | goto finish; | |
55 | } | |
56 | ||
57 | if (bus_check_peercred(bus) < 0) { | |
58 | log_error("Bus owner not root."); | |
59 | goto finish; | |
8e274523 LP |
60 | } |
61 | ||
62 | if (!(m = dbus_message_new_signal("/org/freedesktop/systemd1/agent", "org.freedesktop.systemd1.Agent", "Released"))) { | |
63 | log_error("Could not allocate signal message."); | |
64 | goto finish; | |
65 | } | |
66 | ||
67 | if (!dbus_message_append_args(m, | |
68 | DBUS_TYPE_STRING, &argv[1], | |
69 | DBUS_TYPE_INVALID)) { | |
70 | log_error("Could not attach group information to signal message."); | |
71 | goto finish; | |
72 | } | |
73 | ||
74 | if (!dbus_connection_send(bus, m, NULL)) { | |
53c6a358 | 75 | log_error("Failed to send signal message on private connection."); |
8e274523 LP |
76 | goto finish; |
77 | } | |
78 | ||
22f4096c | 79 | r = EXIT_SUCCESS; |
8e274523 LP |
80 | |
81 | finish: | |
51bc5d4b | 82 | if (bus) { |
5d452f9c | 83 | dbus_connection_flush(bus); |
51bc5d4b | 84 | dbus_connection_close(bus); |
8e274523 | 85 | dbus_connection_unref(bus); |
51bc5d4b | 86 | } |
8e274523 | 87 | |
53c6a358 | 88 | |
8e274523 LP |
89 | if (m) |
90 | dbus_message_unref(m); | |
91 | ||
92 | dbus_error_free(&error); | |
93 | return r; | |
94 | } |