static void
smartctl_sensors_interface_disk_init (SensorsApplet *sensors_applet,
			    const char *disk,
			    int unit)
{
  char *device;

  g_return_if_fail(sensors_applet != NULL);
  g_return_if_fail(disk != NULL);

  device = g_strdup_printf("/dev/%s%i", disk, unit);
  if (g_file_test(device, G_FILE_TEST_EXISTS)
      && smartctl_sensors_interface_run("enable", device, NULL)
      && smartctl_sensors_interface_get_temperature(device, NULL))
    {
      char *path;
      char *label;

      path = g_strdup_printf("/smartctl%s", device);
      label = g_strdup_printf("%s%i", disk, unit);

      sensors_applet_add_sensor(sensors_applet,
				path,
				device,
				label,
				SMARTCTL,
				TRUE,
				TEMP_SENSOR,
				HDD_ICON);

      g_free(path);
      g_free(label);
    }
  g_free(device);
}
static void load_all_plugins(SensorsApplet *sensors_applet,
                             const gchar *path) 
{
        if (g_file_test(path, 
                        G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
                GDir *dir;
                if ((dir = g_dir_open(path, 0, NULL)) != NULL) {
                        const gchar *file;
                        while ((file = g_dir_read_name(dir)) != NULL) {
                                // try and open plugin
                                gchar *plugin_file;
                                void *handle;
                                SensorsAppletPluginName name_fn;
                                SensorsAppletPluginInit init_fn;
                                SensorsAppletPluginGetSensorValue get_value_fn;

                                plugin_file = g_strdup_printf("%s/%s", path, file);
                                if ((handle = dlopen(plugin_file, RTLD_NOW)) != NULL) {
                                        g_debug("dlopen()'d %s", plugin_file);

                                        
                                        if ((name_fn = dlsym(handle, "sensors_applet_plugin_name")) != NULL &&
                                            (init_fn = dlsym(handle, "sensors_applet_plugin_init")) != NULL &&
                                            (get_value_fn = dlsym(handle, "sensors_applet_plugin_get_sensor_value")) != NULL) {
                                                GList *sensors;
                                                g_debug("initing plugin %s", name_fn());
                                                
                                                if ((sensors = init_fn()) != NULL) {
                                                        GList *sensor;
                                                        
                                                        g_debug("registering plugin %s", name_fn());
                                                        g_hash_table_insert(sensors_applet->plugins,
                                                                            g_strdup(name_fn()),
                                                                            get_value_fn);
                                                        for (sensor = g_list_first(sensors);
                                                             sensor != NULL;
                                                             sensor = g_list_next(sensor)) {
                                                                SensorsAppletSensorInfo *sensor_info = (SensorsAppletSensorInfo *)sensor->data;
                                                                sensors_applet_add_sensor(sensors_applet,
                                                                                          sensor_info->path,
                                                                                          sensor_info->id, 
                                                                                          sensor_info->label,
                                                                                          name_fn(),
                                                                                          sensor_info->type,
                                                                                          sensor_info->enable,
                                                                                          sensor_info->low_value,
                                                                                          sensor_info->high_value,
                                                                                          FALSE, // ALARM OFF
                                                                                          "", // no alarm commands
                                                                                          "", // no alarm commands
                                                                                          0, // alarm_timeout
                                                                                          sensor_info->multiplier,
                                                                                          sensor_info->offset,
                                                                                          sensor_info->icon,
                                                                                          sensor_info->graph_color);
                                                                
                                                                g_free(sensor_info->path);
                                                                g_free(sensor_info->id);
                                                                g_free(sensor_info->label);
                                                                g_free(sensor_info->graph_color);
                                                                g_free(sensor_info);
                                                        }
                                                        g_list_free(sensors);
                                                } else {
                                                        g_debug("plugin %s could not find any sensors", name_fn());
                                                        if (g_hash_table_lookup(sensors_applet->required_plugins,
                                                                                name_fn()))
                                                        {
                                                                g_debug("plugin %s required - registering even though no sensors detected", name_fn());
                                                                g_hash_table_insert(sensors_applet->plugins,
                                                                                    g_strdup(name_fn()),
                                                                                    get_value_fn);
                                                        } else {
                                                                g_debug("unloading plugin %s", name_fn());
                                                                dlclose(handle);
                                                        }
                                                }
                                        } else {
                                                g_debug("plugin file %s does not contain the required interface", plugin_file);
                                                dlclose(handle);
                                        }
                                }
                                g_free(plugin_file);
                        }
                        g_dir_close(dir);
                } else {
                        g_debug("error opening plugin dir %s", path);
                }
        } else {
                g_debug("path %s is not a valid directory", path);
        }
}