5 * Copyright (C) 2007 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <dbus/dbus.h>
32 extern char **environ;
34 static void append(DBusMessageIter *dict, const char *pattern)
36 DBusMessageIter entry;
37 const char *key, *value;
40 delim = strchr(pattern, '=');
46 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
49 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
51 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &value);
53 dbus_message_iter_close_container(dict, &entry);
56 int main(int argc, char *argv[])
60 DBusMessageIter iter, dict;
62 char **envp, *busname, *reason, *interface;
64 busname = getenv("BUSNAME");
66 pid = atoi(getenv("pid"));
67 reason = getenv("reason");
68 interface = getenv("interface");
70 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
74 msg = dbus_message_new_method_call(busname, "/org/isc/dhclient",
75 "org.isc.dhclient", "notify");
77 dbus_connection_unref(conn);
81 dbus_message_append_args(msg, DBUS_TYPE_UINT32, &pid,
82 DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID);
84 dbus_message_iter_init_append(msg, &iter);
86 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
87 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
88 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
89 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
91 for (envp = environ; envp && *envp; envp++) {
92 if (strlen(*envp) < 5)
95 if (strncmp(*envp, "new_", 4) == 0 ||
96 strncmp(*envp, "old_", 4) == 0 ||
97 strncmp(*envp, "alia", 4) == 0)
101 dbus_message_iter_close_container(&iter, &dict);
103 dbus_connection_send(conn, msg, NULL);
105 dbus_message_unref(msg);
107 dbus_connection_unref(conn);