2005-03-14 Ray Strode <rstrode@redhat.com>
Fourth (probably working) cut at porting to dbus 0.30 api and new hal. This cut adds some new logging macros to make debugging easier. * dispatcher-daemon/NetworkManagerDispatcher.c: * info-daemon/NetworkmanagerInfo.c: * info-daemon/NetworkManagerInfoPassphraseDialog.c: * info-daemon/NetworkManagerInfoVPN.c: * src/NetworkManager.c: * src/NetworkManagerAP.c: * src/NetworkManagerAPList.c: * src/NetworkManagerDHCP.c: * src/NetworkManagerDbus.c: * src/NetworkManagerDevice.c: * src/NetworkManagerPolicy.c: * src/NetworkManagerSystem.c: * src/NetworkManagerUtils.c: * src/NetworkManagerWireless.c: * src/autoip.c: * src/nm-dbus-nm.c: * src/backends/NetworkManagerDebian.c: * src/backends/NetworkManagerGentoo.c: * src/backends/NetworkManagerRedHat.c: * src/backends/NetworkManagerSlackware.c: use new logging macros. * dispatcher-daemon/NetworkManagerDispatcher.c: (nmd_dbus_filter): s/dbus_free/g_free/ * info-daemon/Makefile.am: link in utils library. * info-daemon/NetworkmanagerInfo.c: use new logging macros. (nmi_dbus_get_network): don't assume enumerations are 32-bit. (nmi_dbus_nmi_message_handler): don't free what doesn't belong to us. * libnm_glib/libnm_glib.c: (libnm_glib_get_nm_status): (libnm_glib_init): don't free what doesn't belong to us. (libnm_glib_dbus): strdup result, so it doesn't get lost when message is unref'd. * panel-applet/NMWirelessAppletDbus.c: (nmwa_dbus_update_devices): s/dbus_free/g_free/ * src/NetworkManager.c: (nm_monitor_wired_link_state): request initial status dump of all cards when we start up, instead of relying on /sys/.../carrier. (nm_info_handler), (nm_set_up_log_handlers): log handlers to specify what syslog priorites the logging macros default to. * src/NetworkManagerAPList.c: (nm_ap_list_populate_from_nmi): s/dbus_free_string_array/g_strfreev/ * src/NetworkManagerDbus.c: (nm_dbus_get_network_object): validate d-bus message argument types. Advance message iterator after reading argument, prepend instead of append to GSList. * src/NetworkManagerDevice.c: (nm_device_probe_wired_link_status): remove redundant /sys in /sys path. remove wrong contents == NULL means has carrier assumption. * src/nm-netlink-monitor.c (nm_netlink_monitor_request_status): implement function to ask kernel to dump interface link status over netlink socket. * test/*.c: s/dbus_free/g_free/ * utils/nm-utils.h: (nm_print_backtrace): new macro to print backtrace. (nm_get_timestamp): new macro to get sub-second precise unix timestamp. (nm_info), (nm_debug), (nm_warning), (nm_error): new logging functions. nm_info just prints, nm_debug includes timestamp and function, nm_warning includes function, nm_error includes backtrace and sigtrap. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@497 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
@@ -66,7 +66,6 @@ char * get_network_string_property (DBusConnection *connection, char *network, c
|
||||
if (dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &string, DBUS_TYPE_INVALID) && string)
|
||||
{
|
||||
ret_string = g_strdup (string);
|
||||
dbus_free (string);
|
||||
}
|
||||
dbus_message_unref (reply);
|
||||
|
||||
@@ -193,7 +192,7 @@ void get_networks_of_type (DBusConnection *connection, NMNetworkType type)
|
||||
}
|
||||
}
|
||||
|
||||
dbus_free_string_array (networks);
|
||||
g_strfreev (networks);
|
||||
}
|
||||
|
||||
void get_user_key_for_network (DBusConnection *connection)
|
||||
@@ -223,10 +222,10 @@ void get_user_key_for_network (DBusConnection *connection)
|
||||
void set_user_key_for_network (DBusConnection *connection, DBusMessage *message, GMainLoop *loop)
|
||||
{
|
||||
DBusError error;
|
||||
char *device;
|
||||
char *network;
|
||||
char *passphrase;
|
||||
char *key_type_string;
|
||||
const char *device;
|
||||
const char *network;
|
||||
const char *passphrase;
|
||||
const char *key_type_string;
|
||||
|
||||
g_return_if_fail (connection != NULL);
|
||||
g_return_if_fail (message != NULL);
|
||||
@@ -241,10 +240,6 @@ void set_user_key_for_network (DBusConnection *connection, DBusMessage *message,
|
||||
{
|
||||
fprintf( stderr, "Device was '%s'\nNetwork was '%s'\nPassphrase was '%s'\nKey type was '%s'\n", device, network, passphrase, key_type_string);
|
||||
|
||||
dbus_free (device);
|
||||
dbus_free (network);
|
||||
dbus_free (passphrase);
|
||||
dbus_free (key_type_string);
|
||||
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
|
76
test/nmnetlinktest.c
Normal file
76
test/nmnetlinktest.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <asm/types.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <linux/if.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <nm-netlink-monitor.h>
|
||||
|
||||
static void
|
||||
device_added (NmNetlinkMonitor *monitor,
|
||||
const gchar *device_name)
|
||||
{
|
||||
g_print ("interface '%s' connected\n", device_name);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
device_removed (NmNetlinkMonitor *monitor,
|
||||
const gchar *device_name)
|
||||
{
|
||||
g_print ("interface '%s' disconnected\n", device_name);
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
NmNetlinkMonitor *monitor;
|
||||
GMainLoop *loop;
|
||||
GError *error;
|
||||
|
||||
g_type_init ();
|
||||
|
||||
monitor = nm_netlink_monitor_new ();
|
||||
|
||||
error = NULL;
|
||||
nm_netlink_monitor_open_connection (monitor, &error);
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
g_printerr ("could not open connection: %s\n",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
g_signal_connect (G_OBJECT (monitor),
|
||||
"interface-connected",
|
||||
G_CALLBACK (device_added), NULL);
|
||||
|
||||
g_signal_connect (G_OBJECT (monitor),
|
||||
"interface-disconnected",
|
||||
G_CALLBACK (device_removed), NULL);
|
||||
|
||||
nm_netlink_monitor_attach (monitor, NULL);
|
||||
|
||||
nm_netlink_monitor_request_status (monitor, &error);
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
g_printerr ("could not request status of interfaces: %s\n",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
return 2;
|
||||
}
|
||||
|
||||
g_main_loop_run (loop);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -296,10 +296,10 @@ void print_device_networks (DBusConnection *connection, const char *path)
|
||||
|
||||
fprintf( stderr, " %s (%s) Strength: %d%%\n", networks[i], name,
|
||||
get_object_signal_strength (connection, networks[i]) );
|
||||
dbus_free (name);
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
dbus_free_string_array (networks);
|
||||
g_strfreev (networks);
|
||||
}
|
||||
|
||||
|
||||
@@ -327,7 +327,7 @@ void print_devices (DBusConnection *connection)
|
||||
fprintf (stderr, " Device type: wireless\n");
|
||||
fprintf (stderr, " Strength: %d%%\n", get_object_signal_strength (connection, devices[i]));
|
||||
fprintf (stderr, " Active Network: '%s'\n", active_network);
|
||||
dbus_free (active_network);
|
||||
g_free (active_network);
|
||||
|
||||
print_device_networks (connection, devices[i]);
|
||||
fprintf (stderr, "\n");
|
||||
@@ -338,7 +338,7 @@ void print_devices (DBusConnection *connection)
|
||||
fprintf (stderr, " Device type: unknown\n");
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
dbus_free_string_array (devices);
|
||||
g_strfreev (devices);
|
||||
}
|
||||
|
||||
|
||||
@@ -400,7 +400,7 @@ int main( int argc, char *argv[] )
|
||||
return (1);
|
||||
}
|
||||
fprintf (stderr, "NM Status: '%s'\n", status);
|
||||
dbus_free (status);
|
||||
g_free (status);
|
||||
|
||||
path = get_active_device (connection);
|
||||
fprintf (stderr, "Active device: '%s'\n", path ? path : "(none)");
|
||||
@@ -408,7 +408,7 @@ int main( int argc, char *argv[] )
|
||||
{
|
||||
char *name = get_object_name (connection, path);
|
||||
fprintf (stderr, "Active device name: '%s'\n", name ? name : "(none)");
|
||||
dbus_free (name);
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
print_devices (connection);
|
||||
@@ -419,7 +419,7 @@ int main( int argc, char *argv[] )
|
||||
set_device_network (connection, path, argv[1]);
|
||||
}
|
||||
|
||||
dbus_free (path);
|
||||
g_free (path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user