void mm_manager_start (MMManager *manager) { GList *devices, *iter; g_return_if_fail (manager != NULL); g_return_if_fail (MM_IS_MANAGER (manager)); mm_dbg ("Starting device scan..."); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "tty"); for (iter = devices; iter; iter = g_list_next (iter)) { device_added (manager, G_UDEV_DEVICE (iter->data)); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "net"); for (iter = devices; iter; iter = g_list_next (iter)) { device_added (manager, G_UDEV_DEVICE (iter->data)); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); mm_dbg ("Finished device scan..."); }
/* * Return a list of device specifications which NetworkManager should not * manage. Returned list will be freed by the system settings service, and * each element must be allocated using g_malloc() or its variants. */ static GSList* SCPluginIfupdown_get_unmanaged_specs (NMSystemConfigInterface *config) { SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config); GSList *specs = NULL; GHashTableIter iter; gpointer value; if (!ALWAYS_UNMANAGE && !priv->unmanage_well_known) return NULL; PLUGIN_PRINT("Ifupdown", "get unmanaged devices count: %d", g_hash_table_size (priv->well_known_ifaces)); g_hash_table_iter_init (&iter, priv->well_known_ifaces); while (g_hash_table_iter_next (&iter, NULL, &value)) { GUdevDevice *device = G_UDEV_DEVICE (value); const char *address; address = g_udev_device_get_sysfs_attr (device, "address"); if (address) specs = g_slist_append (specs, g_strdup_printf ("mac:%s", address)); } return specs; }
GUdevDevice * mm_port_probe_get_port (MMPortProbe *self) { g_return_val_if_fail (MM_IS_PORT_PROBE (self), NULL); return G_UDEV_DEVICE (g_object_ref (self->priv->port)); };
void udev_detect(void) { GUdevClient *client; const char *subsys[2] = { "tty", NULL }; GList *list, *iter; client = g_udev_client_new(subsys); list = g_udev_client_query_by_subsystem(client, subsys[0]); for (iter = list; iter; iter = g_list_next(iter)) { dump_device_and_parent(G_UDEV_DEVICE(iter->data), 0); if (device_is_valid(G_UDEV_DEVICE(iter->data))) { device_dump_config(G_UDEV_DEVICE(iter->data)); } g_object_unref(G_UDEV_DEVICE(iter->data)); } }
void nm_atm_manager_query_devices (NMAtmManager *self) { NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self); GUdevEnumerator *enumerator; GList *devices, *iter; g_return_if_fail (NM_IS_ATM_MANAGER (self)); enumerator = g_udev_enumerator_new (priv->client); g_udev_enumerator_add_match_subsystem (enumerator, "atm"); g_udev_enumerator_add_match_is_initialized (enumerator); devices = g_udev_enumerator_execute (enumerator); for (iter = devices; iter; iter = g_list_next (iter)) { adsl_add (self, G_UDEV_DEVICE (iter->data)); g_object_unref (G_UDEV_DEVICE (iter->data)); } g_list_free (devices); g_object_unref (enumerator); }
/** * rb_removable_media_manager_device_is_android: * @manager: the #RBRemovableMediaManager * @device: the #GUdevDevice to query * * Determines whether the specified device looks like an Android device. * * Return value: %TRUE if the device appears to be Android-based */ gboolean rb_removable_media_manager_device_is_android (RBRemovableMediaManager *manager, GObject *device) { #if defined(HAVE_GUDEV) gboolean match; const char *model; const char *vendor; int i; const char *androids[] = { "Android", "Nexus" }; const char *android_vendors[] = { "motorola", "OnePlus" }; match = FALSE; model = g_udev_device_get_property (G_UDEV_DEVICE (device), "ID_MODEL"); if (model != NULL) { for (i = 0; i < G_N_ELEMENTS (androids); i++) { if (strstr (model, androids[i])) match = TRUE; } } vendor = g_udev_device_get_property (G_UDEV_DEVICE (device), "ID_VENDOR"); if (vendor != NULL) { for (i = 0; i < G_N_ELEMENTS (android_vendors); i++) { if (strstr (vendor, android_vendors[i])) match = TRUE; } } return match; #else return FALSE; #endif }
static void nm_rfkill_manager_init (NMRfkillManager *self) { NMRfkillManagerPrivate *priv = NM_RFKILL_MANAGER_GET_PRIVATE (self); const char *subsys[] = { "rfkill", NULL }; GList *switches, *iter; guint32 i; for (i = 0; i < RFKILL_TYPE_MAX; i++) priv->rfkill_states[i] = RFKILL_UNBLOCKED; priv->client = g_udev_client_new (subsys); g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self); switches = g_udev_client_query_by_subsystem (priv->client, "rfkill"); for (iter = switches; iter; iter = g_list_next (iter)) { add_one_killswitch (self, G_UDEV_DEVICE (iter->data)); g_object_unref (G_UDEV_DEVICE (iter->data)); } g_list_free (switches); recheck_killswitches (self); }
static gboolean fu_altos_device_find_tty (FuAltosDevice *self, GError **error) { GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (self)); g_autoptr(GList) devices = NULL; g_autoptr(GUdevClient) gudev_client = g_udev_client_new (NULL); /* find all tty devices */ devices = g_udev_client_query_by_subsystem (gudev_client, "tty"); for (GList *l = devices; l != NULL; l = l->next) { GUdevDevice *dev = G_UDEV_DEVICE (l->data); /* get the tty device */ const gchar *dev_file = g_udev_device_get_device_file (dev); if (dev_file == NULL) continue; /* get grandparent */ dev = g_udev_device_get_parent (dev); if (dev == NULL) continue; dev = g_udev_device_get_parent (dev); if (dev == NULL) continue; /* check correct device */ if (g_udev_device_get_sysfs_attr_as_int (dev, "busnum") != g_usb_device_get_bus (usb_device)) continue; if (g_udev_device_get_sysfs_attr_as_int (dev, "devnum") != g_usb_device_get_address (usb_device)) continue; /* success */ self->tty = g_strdup (dev_file); return TRUE; } /* failure */ g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED, "failed to find tty for %u:%u", g_usb_device_get_bus (usb_device), g_usb_device_get_address (usb_device)); return FALSE; }
void mm_base_manager_start (MMBaseManager *manager, gboolean manual_scan) { GList *devices, *iter; g_return_if_fail (manager != NULL); g_return_if_fail (MM_IS_BASE_MANAGER (manager)); if (!manager->priv->auto_scan && !manual_scan) return; mm_dbg ("Starting %s device scan...", manual_scan ? "manual" : "automatic"); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "tty"); for (iter = devices; iter; iter = g_list_next (iter)) { start_device_added (manager, G_UDEV_DEVICE (iter->data), manual_scan); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "net"); for (iter = devices; iter; iter = g_list_next (iter)) { start_device_added (manager, G_UDEV_DEVICE (iter->data), manual_scan); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "usb"); for (iter = devices; iter; iter = g_list_next (iter)) { const gchar *name; name = g_udev_device_get_name (G_UDEV_DEVICE (iter->data)); if (name && g_str_has_prefix (name, "cdc-wdm")) start_device_added (manager, G_UDEV_DEVICE (iter->data), manual_scan); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); /* Newer kernels report 'usbmisc' subsystem */ devices = g_udev_client_query_by_subsystem (manager->priv->udev, "usbmisc"); for (iter = devices; iter; iter = g_list_next (iter)) { const gchar *name; name = g_udev_device_get_name (G_UDEV_DEVICE (iter->data)); if (name && g_str_has_prefix (name, "cdc-wdm")) start_device_added (manager, G_UDEV_DEVICE (iter->data), manual_scan); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); mm_dbg ("Finished device scan..."); }
void mm_manager_start (MMManager *manager) { GList *devices, *iter; g_return_if_fail (manager != NULL); g_return_if_fail (MM_IS_MANAGER (manager)); mm_dbg ("Starting device scan..."); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "tty"); for (iter = devices; iter; iter = g_list_next (iter)) { device_added (manager, G_UDEV_DEVICE (iter->data), FALSE); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "net"); for (iter = devices; iter; iter = g_list_next (iter)) { device_added (manager, G_UDEV_DEVICE (iter->data), FALSE); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "usb"); for (iter = devices; iter; iter = g_list_next (iter)) { const gchar *name; name = g_udev_device_get_name (G_UDEV_DEVICE (iter->data)); if (name && g_str_has_prefix (name, "cdc-wdm")) device_added (manager, G_UDEV_DEVICE (iter->data), FALSE); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); /* Newer kernels report 'usbmisc' subsystem */ devices = g_udev_client_query_by_subsystem (manager->priv->udev, "usbmisc"); for (iter = devices; iter; iter = g_list_next (iter)) { const gchar *name; name = g_udev_device_get_name (G_UDEV_DEVICE (iter->data)); if (name && g_str_has_prefix (name, "cdc-wdm")) device_added (manager, G_UDEV_DEVICE (iter->data), FALSE); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); mm_dbg ("Finished device scan..."); }
static void gs_plugin_modalias_ensure_devices (GsPlugin *plugin) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autoptr(GList) list = NULL; /* already set */ if (priv->devices->len > 0) return; /* get the devices, and assume ownership of each */ list = g_udev_client_query_by_subsystem (priv->client, NULL); for (GList *l = list; l != NULL; l = l->next) { GUdevDevice *device = G_UDEV_DEVICE (l->data); if (g_udev_device_get_sysfs_attr (device, "modalias") == NULL) { g_object_unref (device); continue; } g_ptr_array_add (priv->devices, device); } g_debug ("%u devices with modalias", priv->devices->len); }
static void init (NMSettingsPlugin *config) { SettingsPluginIfupdown *self = SETTINGS_PLUGIN_IFUPDOWN (config); SettingsPluginIfupdownPrivate *priv = SETTINGS_PLUGIN_IFUPDOWN_GET_PRIVATE (self); GHashTable *auto_ifaces; if_block *block = NULL; GList *keys, *iter; GHashTableIter con_iter; const char *block_name; NMIfupdownConnection *connection; const char *subsys[2] = { "net", NULL }; auto_ifaces = g_hash_table_new (g_str_hash, g_str_equal); if(!priv->connections) priv->connections = g_hash_table_new (g_str_hash, g_str_equal); if(!priv->kernel_ifaces) priv->kernel_ifaces = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); if(!priv->eni_ifaces) priv->eni_ifaces = g_hash_table_new (g_str_hash, g_str_equal); nm_log_info (LOGD_SETTINGS, "init!"); priv->client = g_udev_client_new (subsys); if (!priv->client) { nm_log_warn (LOGD_SETTINGS, " error initializing libgudev"); } else g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self); /* Read in all the interfaces */ ifparser_init (ENI_INTERFACES_FILE, 0); block = ifparser_getfirst (); while (block) { if(!strcmp ("auto", block->type) || !strcmp ("allow-hotplug", block->type)) g_hash_table_insert (auto_ifaces, block->name, GUINT_TO_POINTER (1)); else if (!strcmp ("iface", block->type)) { NMIfupdownConnection *exported; /* Bridge configuration */ if(!strncmp ("br", block->name, 2)) { /* Try to find bridge ports */ const char *ports = ifparser_getkey (block, "bridge-ports"); if (ports) { int i; int state = 0; char **port_ifaces; nm_log_info (LOGD_SETTINGS, "found bridge ports %s for %s", ports, block->name); port_ifaces = g_strsplit_set (ports, " \t", -1); for (i = 0; i < g_strv_length (port_ifaces); i++) { char *token = port_ifaces[i]; /* Skip crazy stuff like regex or all */ if (!strcmp ("all", token)) { continue; } /* Small SM to skip everything inside regex */ if (!strcmp ("regex", token)) { state++; continue; } if (!strcmp ("noregex", token)) { state--; continue; } if (state == 0 && strlen (token) > 0) { nm_log_info (LOGD_SETTINGS, "adding bridge port %s to eni_ifaces", token); g_hash_table_insert (priv->eni_ifaces, g_strdup (token), "known"); } } g_strfreev (port_ifaces); } goto next; } /* Skip loopback configuration */ if(!strcmp ("lo", block->name)) { goto next; } /* Remove any connection for this block that was previously found */ exported = g_hash_table_lookup (priv->connections, block->name); if (exported) { nm_log_info (LOGD_SETTINGS, "deleting %s from connections", block->name); nm_settings_connection_delete (NM_SETTINGS_CONNECTION (exported), NULL, NULL); g_hash_table_remove (priv->connections, block->name); } /* add the new connection */ exported = nm_ifupdown_connection_new (block); if (exported) { nm_log_info (LOGD_SETTINGS, "adding %s to connections", block->name); g_hash_table_insert (priv->connections, block->name, exported); } nm_log_info (LOGD_SETTINGS, "adding iface %s to eni_ifaces", block->name); g_hash_table_insert (priv->eni_ifaces, block->name, "known"); } else if (!strcmp ("mapping", block->type)) { g_hash_table_insert (priv->eni_ifaces, block->name, "known"); nm_log_info (LOGD_SETTINGS, "adding mapping %s to eni_ifaces", block->name); } next: block = block->next; } /* Make 'auto' interfaces autoconnect=TRUE */ g_hash_table_iter_init (&con_iter, priv->connections); while (g_hash_table_iter_next (&con_iter, (gpointer) &block_name, (gpointer) &connection)) { NMSettingConnection *setting; if (g_hash_table_lookup (auto_ifaces, block_name)) { setting = nm_connection_get_setting_connection (NM_CONNECTION (connection)); g_object_set (setting, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL); nm_log_info (LOGD_SETTINGS, "autoconnect"); } } g_hash_table_destroy (auto_ifaces); /* Check the config file to find out whether to manage interfaces */ priv->unmanage_well_known = !nm_config_data_get_value_boolean (NM_CONFIG_GET_DATA_ORIG, NM_CONFIG_KEYFILE_GROUP_IFUPDOWN, NM_CONFIG_KEYFILE_KEY_IFUPDOWN_MANAGED, !IFUPDOWN_UNMANAGE_WELL_KNOWN_DEFAULT); nm_log_info (LOGD_SETTINGS, "management mode: %s", priv->unmanage_well_known ? "unmanaged" : "managed"); /* Add well-known interfaces */ keys = g_udev_client_query_by_subsystem (priv->client, "net"); for (iter = keys; iter; iter = g_list_next (iter)) { udev_device_added (self, G_UDEV_DEVICE (iter->data)); g_object_unref (G_UDEV_DEVICE (iter->data)); } g_list_free (keys); /* Now if we're running in managed mode, let NM know there are new connections */ if (!priv->unmanage_well_known) { GList *con_list = g_hash_table_get_values (priv->connections); GList *cl_iter; for (cl_iter = con_list; cl_iter; cl_iter = g_list_next (cl_iter)) { g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_CONNECTION_ADDED, NM_SETTINGS_CONNECTION (cl_iter->data)); } g_list_free (con_list); } nm_log_info (LOGD_SETTINGS, "end _init."); }
static RBSource * create_source_device_cb (RBRemovableMediaManager *rmm, GObject *device_obj, RBMtpPlugin *plugin) { GUdevDevice *device = G_UDEV_DEVICE (device_obj); LIBMTP_device_entry_t *device_list; int numdevs; int vendor; int model; int busnum; int devnum; int i; /* check subsystem == usb? */ if (g_strcmp0 (g_udev_device_get_subsystem (device), "usb") != 0) { rb_debug ("device %s is not a USB device", g_udev_device_get_name (device)); return NULL; } /* check that it's not an iPhone or iPod Touch */ if (g_udev_device_get_property_as_boolean (device, "USBMUX_SUPPORTED")) { rb_debug ("device %s is supported through AFC, ignore", g_udev_device_get_name (device)); return NULL; } /* get device info */ vendor = get_property_as_int (device, "ID_VENDOR_ID", 16); model = get_property_as_int (device, "ID_MODEL_ID", 16); busnum = get_property_as_int (device, "BUSNUM", 10); devnum = get_property_as_int (device, "DEVNUM", 10); if (vendor == 0 || model == 0) { rb_debug ("couldn't get vendor or model ID for device (%x:%x)", vendor, model); return NULL; } rb_debug ("matching device %x:%x against libmtp device list", vendor, model); LIBMTP_Get_Supported_Devices_List(&device_list, &numdevs); for (i = 0; i < numdevs; i++) { if (device_list[i].vendor_id == vendor && device_list[i].product_id == model) { LIBMTP_raw_device_t rawdevice; RBSource *source; RBShell *shell; rb_debug ("found libmtp device list entry (model: %s, vendor: %s)", device_list[i].vendor, device_list[i].product); rawdevice.device_entry = device_list[i]; rawdevice.bus_location = busnum; rawdevice.devnum = devnum; g_object_get (plugin, "object", &shell, NULL); source = rb_mtp_source_new (shell, G_OBJECT (plugin), device, &rawdevice); plugin->mtp_sources = g_list_prepend (plugin->mtp_sources, source); g_signal_connect_object (G_OBJECT (source), "deleted", G_CALLBACK (source_deleted_cb), plugin, 0); g_object_unref (shell); return source; } } rb_debug ("device didn't match anything"); return NULL; }
static void SCPluginIfupdown_init (NMSystemConfigInterface *config) { SCPluginIfupdown *self = SC_PLUGIN_IFUPDOWN (config); SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (self); GHashTable *auto_ifaces; if_block *block = NULL; NMInotifyHelper *inotify_helper; GKeyFile* keyfile; GError *error = NULL; GList *keys, *iter; const char *subsys[2] = { "net", NULL }; auto_ifaces = g_hash_table_new (g_str_hash, g_str_equal); if(!priv->iface_connections) priv->iface_connections = g_hash_table_new (g_str_hash, g_str_equal); if(!priv->well_known_ifaces) priv->well_known_ifaces = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); if(!priv->well_known_interfaces) priv->well_known_interfaces = g_hash_table_new (g_str_hash, g_str_equal); PLUGIN_PRINT("SCPlugin-Ifupdown", "init!"); priv->client = g_udev_client_new (subsys); if (!priv->client) { PLUGIN_WARN ("SCPlugin-Ifupdown", " error initializing libgudev"); } else g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self); priv->unmanage_well_known = IFUPDOWN_UNMANAGE_WELL_KNOWN_DEFAULT; inotify_helper = nm_inotify_helper_get (); priv->inotify_event_id = g_signal_connect (inotify_helper, "event", G_CALLBACK (update_system_hostname), config); priv->inotify_system_hostname_wd = nm_inotify_helper_add_watch (inotify_helper, IFUPDOWN_SYSTEM_HOSTNAME_FILE); update_system_hostname (inotify_helper, NULL, NULL, config); /* Read in all the interfaces */ ifparser_init (ENI_INTERFACES_FILE, 0); block = ifparser_getfirst (); while (block) { if(!strcmp ("auto", block->type) || !strcmp ("allow-hotplug", block->type)) g_hash_table_insert (auto_ifaces, block->name, GUINT_TO_POINTER (1)); else if (!strcmp ("iface", block->type)) { NMIfupdownConnection *exported; /* Bridge configuration */ if(!strncmp ("br", block->name, 2)) { /* Try to find bridge ports */ const char *ports = ifparser_getkey (block, "bridge-ports"); if (ports) { int i; int state = 0; char **port_ifaces; PLUGIN_PRINT("SCPlugin-Ifupdown", "found bridge ports %s for %s", ports, block->name); port_ifaces = g_strsplit_set (ports, " \t", -1); for (i = 0; i < g_strv_length (port_ifaces); i++) { char *token = port_ifaces[i]; /* Skip crazy stuff like regex or all */ if (!strcmp ("all", token)) { continue; } /* Small SM to skip everything inside regex */ if (!strcmp ("regex", token)) { state++; continue; } if (!strcmp ("noregex", token)) { state--; continue; } if (state == 0 && strlen (token) > 0) { PLUGIN_PRINT("SCPlugin-Ifupdown", "adding bridge port %s to well_known_interfaces", token); g_hash_table_insert (priv->well_known_interfaces, g_strdup (token), "known"); } } g_strfreev (port_ifaces); } goto next; } /* Skip loopback configuration */ if(!strcmp ("lo", block->name)) { goto next; } /* Remove any connection for this block that was previously found */ exported = g_hash_table_lookup (priv->iface_connections, block->name); if (exported) { PLUGIN_PRINT("SCPlugin-Ifupdown", "deleting %s from iface_connections", block->name); nm_settings_connection_delete (NM_SETTINGS_CONNECTION (exported), ignore_cb, NULL); g_hash_table_remove (priv->iface_connections, block->name); } /* add the new connection */ exported = nm_ifupdown_connection_new (block); if (exported) { PLUGIN_PRINT("SCPlugin-Ifupdown", "adding %s to iface_connections", block->name); g_hash_table_insert (priv->iface_connections, block->name, exported); } PLUGIN_PRINT("SCPlugin-Ifupdown", "adding iface %s to well_known_interfaces", block->name); g_hash_table_insert (priv->well_known_interfaces, block->name, "known"); } else if (!strcmp ("mapping", block->type)) { g_hash_table_insert (priv->well_known_interfaces, block->name, "known"); PLUGIN_PRINT("SCPlugin-Ifupdown", "adding mapping %s to well_known_interfaces", block->name); } next: block = block->next; } /* Make 'auto' interfaces autoconnect=TRUE */ keys = g_hash_table_get_keys (priv->iface_connections); for (iter = keys; iter; iter = g_list_next (iter)) { NMIfupdownConnection *exported; NMSetting *setting; if (!g_hash_table_lookup (auto_ifaces, iter->data)) continue; exported = g_hash_table_lookup (priv->iface_connections, iter->data); setting = NM_SETTING (nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_CONNECTION)); g_object_set (setting, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL); nm_settings_connection_commit_changes (NM_SETTINGS_CONNECTION (exported), ignore_cb, NULL); PLUGIN_PRINT("SCPlugin-Ifupdown", "autoconnect"); } g_list_free (keys); g_hash_table_destroy (auto_ifaces); /* Find the config file */ if (g_file_test (IFUPDOWN_SYSTEM_SETTINGS_KEY_FILE, G_FILE_TEST_EXISTS)) priv->conf_file = IFUPDOWN_SYSTEM_SETTINGS_KEY_FILE; else priv->conf_file = IFUPDOWN_OLD_SYSTEM_SETTINGS_KEY_FILE; keyfile = g_key_file_new (); if (!g_key_file_load_from_file (keyfile, priv->conf_file, G_KEY_FILE_NONE, &error)) { nm_log_info (LOGD_SETTINGS, "loading system config file (%s) caused error: (%d) %s", priv->conf_file, error ? error->code : -1, error && error->message ? error->message : "(unknown)"); } else { gboolean manage_well_known; error = NULL; manage_well_known = g_key_file_get_boolean (keyfile, IFUPDOWN_KEY_FILE_GROUP, IFUPDOWN_KEY_FILE_KEY_MANAGED, &error); if (error) { nm_log_info (LOGD_SETTINGS, "getting keyfile key '%s' in group '%s' failed: (%d) %s", IFUPDOWN_KEY_FILE_GROUP, IFUPDOWN_KEY_FILE_KEY_MANAGED, error ? error->code : -1, error && error->message ? error->message : "(unknown)"); } else priv->unmanage_well_known = !manage_well_known; } PLUGIN_PRINT ("SCPluginIfupdown", "management mode: %s", priv->unmanage_well_known ? "unmanaged" : "managed"); if (keyfile) g_key_file_free (keyfile); /* Add well-known interfaces */ keys = g_udev_client_query_by_subsystem (priv->client, "net"); for (iter = keys; iter; iter = g_list_next (iter)) { udev_device_added (self, G_UDEV_DEVICE (iter->data)); g_object_unref (G_UDEV_DEVICE (iter->data)); } g_list_free (keys); /* Now if we're running in managed mode, let NM know there are new connections */ if (!priv->unmanage_well_known) { GList *con_list = g_hash_table_get_values (priv->iface_connections); GList *cl_iter; for (cl_iter = con_list; cl_iter; cl_iter = g_list_next (cl_iter)) { g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, NM_SETTINGS_CONNECTION (cl_iter->data)); } g_list_free (con_list); } PLUGIN_PRINT("SCPlugin-Ifupdown", "end _init."); }
/** * up_native_get_native_path: * @object: the native tracking object * * This converts a GObject used as the device data into a native path. * This would be implemented on a Linux system using: * g_udev_device_get_sysfs_path (G_UDEV_DEVICE (object)) * * Return value: The native path for the device which is unique, e.g. "/sys/class/power/BAT1" **/ const gchar * up_native_get_native_path (GObject *object) { return g_udev_device_get_sysfs_path (G_UDEV_DEVICE (object)); }
/** * rb_removable_media_manager_scan: * @manager: the #RBRemovableMediaManager * * Initiates a new scan of all attached media. Newly activated plugins that use * the create-source-volume or create-source-mount signals should call this if * the 'scanned' property is %TRUE. Otherwise, the first scan will catch any * existing volumes or mounts that the plugin is interested in. */ void rb_removable_media_manager_scan (RBRemovableMediaManager *manager) { RBRemovableMediaManagerPrivate *priv = GET_PRIVATE (manager); GHashTableIter iter; GList *list, *it; gpointer hkey, hvalue; priv->scanned = TRUE; /* check volumes first */ list = g_volume_monitor_get_volumes (priv->volume_monitor); /* - check for volumes that have disappeared */ g_hash_table_iter_init (&iter, priv->volume_mapping); while (g_hash_table_iter_next (&iter, &hkey, &hvalue)) { GVolume *volume = G_VOLUME (hkey); if (g_list_index (list, volume) == -1) { /* volume has vanished */ rb_removable_media_manager_remove_volume (manager, volume); } } /* - check for newly added volumes */ for (it = list; it != NULL; it = g_list_next (it)) { GVolume *volume = G_VOLUME (it->data); rb_removable_media_manager_add_volume (manager, volume); g_object_unref (volume); } g_list_free (list); /* check mounts */ list = g_volume_monitor_get_mounts (priv->volume_monitor); /* - check for mounts that have disappeared */ g_hash_table_iter_init (&iter, priv->mount_mapping); while (g_hash_table_iter_next (&iter, &hkey, &hvalue)) { GMount *mount = G_MOUNT (hkey); if (g_list_index (list, mount) == -1) { rb_removable_media_manager_remove_mount (manager, mount); } } /* - check for newly added mounts */ for (it = list; it != NULL; it = g_list_next (it)) { GMount *mount = G_MOUNT (it->data); rb_removable_media_manager_add_mount (manager, mount); g_object_unref (mount); } g_list_free (list); /* - check devices */ #if defined(HAVE_GUDEV) list = g_udev_client_query_by_subsystem (priv->gudev_client, "usb"); for (it = list; it != NULL; it = g_list_next (it)) { /* pretend the device was just added */ uevent_cb (priv->gudev_client, "add", G_UDEV_DEVICE (it->data), manager); } g_list_free (list); #endif }
static void udisks_linux_provider_start (UDisksProvider *_provider) { UDisksLinuxProvider *provider = UDISKS_LINUX_PROVIDER (_provider); UDisksDaemon *daemon; UDisksManager *manager; GList *devices; GList *udisks_devices; GList *l; guint n; provider->coldplug = TRUE; if (UDISKS_PROVIDER_CLASS (udisks_linux_provider_parent_class)->start != NULL) UDISKS_PROVIDER_CLASS (udisks_linux_provider_parent_class)->start (_provider); daemon = udisks_provider_get_daemon (UDISKS_PROVIDER (provider)); provider->manager_object = udisks_object_skeleton_new ("/org/freedesktop/UDisks2/Manager"); manager = udisks_linux_manager_new (daemon); udisks_object_skeleton_set_manager (provider->manager_object, manager); g_object_unref (manager); g_dbus_object_manager_server_export (udisks_daemon_get_object_manager (daemon), G_DBUS_OBJECT_SKELETON (provider->manager_object)); provider->sysfs_to_block = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref); provider->vpd_to_drive = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref); provider->sysfs_path_to_drive = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); provider->uuid_to_mdraid = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref); provider->sysfs_path_to_mdraid = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); provider->sysfs_path_to_mdraid_members = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); devices = g_udev_client_query_by_subsystem (provider->gudev_client, "block"); /* make sure we process sda before sdz and sdz before sdaa */ devices = g_list_sort (devices, (GCompareFunc) udev_device_name_cmp); /* probe for extra data we don't get from udev */ udisks_info ("Initialization (device probing)"); udisks_devices = NULL; for (l = devices; l != NULL; l = l->next) { GUdevDevice *device = G_UDEV_DEVICE (l->data); udisks_devices = g_list_prepend (udisks_devices, udisks_linux_device_new_sync (device)); } udisks_devices = g_list_reverse (udisks_devices); /* do two coldplug runs to handle dependencies between devices */ for (n = 0; n < 2; n++) { udisks_info ("Initialization (coldplug %d/2)", n + 1); for (l = udisks_devices; l != NULL; l = l->next) { UDisksLinuxDevice *device = l->data; udisks_linux_provider_handle_uevent (provider, "add", device); } } g_list_free_full (devices, g_object_unref); g_list_free_full (udisks_devices, g_object_unref); udisks_info ("Initialization complete"); /* schedule housekeeping for every 10 minutes */ provider->housekeeping_timeout = g_timeout_add_seconds (10*60, on_housekeeping_timeout, provider); /* ... and also do an initial run */ on_housekeeping_timeout (provider); provider->coldplug = FALSE; /* update Block:Configuration whenever fstab or crypttab entries are added or removed */ g_signal_connect (udisks_daemon_get_fstab_monitor (daemon), "entry-added", G_CALLBACK (fstab_monitor_on_entry_added), provider); g_signal_connect (udisks_daemon_get_fstab_monitor (daemon), "entry-removed", G_CALLBACK (fstab_monitor_on_entry_removed), provider); g_signal_connect (udisks_daemon_get_crypttab_monitor (daemon), "entry-added", G_CALLBACK (crypttab_monitor_on_entry_added), provider); g_signal_connect (udisks_daemon_get_crypttab_monitor (daemon), "entry-removed", G_CALLBACK (crypttab_monitor_on_entry_removed), provider); }