5 * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
6 * Copyright (C) 2010 BMW Car IT GmbH. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #include <dbus/dbus.h>
35 extern char **environ;
37 static void print(const char *format, ...)
42 vsyslog(LOG_INFO, format, ap);
47 static void append(DBusMessageIter *dict, const char *pattern)
49 DBusMessageIter entry;
50 const char *key, *value;
53 delim = strchr(pattern, '=');
59 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
62 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
64 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &value);
66 dbus_message_iter_close_container(dict, &entry);
69 int main(int argc, char *argv[])
74 DBusMessageIter iter, dict;
75 char **envp, *busname, *interface, *path, *reason;
78 openlog(basename(argv[0]), LOG_NDELAY | LOG_PID, LOG_DAEMON);
80 busname = getenv("CONNMAN_BUSNAME");
81 interface = getenv("CONNMAN_INTERFACE");
82 path = getenv("CONNMAN_PATH");
84 reason = getenv("script_type");
86 if (!busname || !interface || !path || !reason) {
87 print("Required environment variables not set");
91 dbus_error_init(&error);
93 conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
95 if (dbus_error_is_set(&error) == TRUE) {
96 print("%s", error.message);
97 dbus_error_free(&error);
99 print("Failed to get on system bus");
104 msg = dbus_message_new_method_call(busname, path,
105 interface, "notify");
107 dbus_connection_unref(conn);
108 print("Failed to allocate method call");
112 dbus_message_set_no_reply(msg, TRUE);
114 dbus_message_append_args(msg,
115 DBUS_TYPE_STRING, &reason,
118 dbus_message_iter_init_append(msg, &iter);
120 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
121 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
122 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
123 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
125 for (envp = environ; envp && *envp; envp++)
126 append(&dict, *envp);
128 dbus_message_iter_close_container(&iter, &dict);
130 if (dbus_connection_send(conn, msg, NULL) == FALSE) {
131 print("Failed to send message");
135 dbus_connection_flush(conn);
137 dbus_message_unref(msg);
139 dbus_connection_unref(conn);