146
143
gtk_widget_destroy (dialog);
150
up_check_mount_point_for_packages (const char *mount_point, gpointer data)
146
/** Invoked by GLib in response to a D-BUS disconnect event.
148
* @param data Context pointer
151
up_reconnect_to_hal (gpointer data __attribute__((__unused__)))
153
static unsigned int retries = 0;
155
g_message ("Trying a reconnect ...");
156
hal_ctx = up_do_hal_init ();
157
if (hal_ctx != NULL) {
158
g_message ("Reconnected OK.");
161
} else if (dbus_connection) {
162
dbus_connection_unref (dbus_connection);
163
dbus_connection = NULL;
166
/* Retry later if it failed. */
167
if (retries++ < 6000)
170
/* Too many retries; clean up and bail. */
171
g_warning ("gvm_reconnect_to_hal: no reconnection after 6000 retries, "
174
/* Too many retries; clean up and bail. */
179
static DBusHandlerResult
180
up_do_filter_dbus_msg (DBusConnection *connection __attribute__((__unused__)),
181
DBusMessage *message,
182
void *user_data __attribute__((__unused__)))
186
if (dbus_message_is_signal (message,
187
DBUS_INTERFACE_LOCAL,
189
g_timeout_add(1000, up_reconnect_to_hal, NULL);
190
libhal_ctx_shutdown (hal_ctx, &error);
191
libhal_ctx_free (hal_ctx);
193
dbus_connection_unref (dbus_connection);
194
dbus_connection = NULL;
195
return DBUS_HANDLER_RESULT_HANDLED;
198
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
202
hal_mainloop_integration (LibHalContext *ctx,
207
dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, error);
209
if (dbus_error_is_set (error))
212
dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
214
dbus_connection_setup_with_g_main (dbus_connection, NULL);
215
dbus_connection_add_filter (dbus_connection, up_do_filter_dbus_msg,
218
libhal_ctx_set_dbus_connection (ctx, dbus_connection);
223
/** callback when a property of a device changes.
225
* @param udi Unique Device Id
226
* @param key Name of the property that has changed
227
* @param is_removed Property removed
228
* @param is_added Property added
231
hal_property_modified(LibHalContext *ctx, const char *udi, const char *key,
232
dbus_bool_t is_removed, dbus_bool_t is_added)
234
//g_print("hal_device_changed(): %s\n",key);
236
/* we are only interessted in mount events from the cdrom*/
237
if (g_strcasecmp (key, "volume.is_mounted") != 0)
239
if(!libhal_device_get_property_bool(ctx, udi, key, NULL))
242
up_check_device_for_packages (ctx, udi);
245
/** check if the given udi contains package files
247
* @param udi Unique Device Id
250
up_check_device_for_packages (LibHalContext *ctx, const char *udi)
252
gchar *mount_point, *storage_device, *media_type;
254
storage_device = libhal_device_get_property_string (ctx, udi,
255
"block.storage_device",
257
if (!storage_device) {
258
g_warning("cannot get storage_device\n");
261
media_type = libhal_device_get_property_string (ctx, storage_device,
262
"storage.drive_type",
265
g_warning("cannot get storage.drive_type\n");
268
if (g_ascii_strcasecmp(media_type, "cdrom") != 0) {
269
//g_warning("no cdrom: %s\n",media_type);
273
mount_point = libhal_device_get_property_string (ctx, udi,
274
"volume.mount_point",
276
//g_print("mounted: %s on %s\n", udi, mount_point);
155
278
char *ubuntu_dir = g_strdup_printf("%s/ubuntu",mount_point);
156
279
char *aptoncd_file = g_strdup_printf("%s/aptoncd.info",mount_point);
180
303
//g_print("retval: %i \n", WEXITSTATUS(retval));
181
304
int cdtype = WEXITSTATUS(retval);
183
distro_cd_detected(data, cdtype, mount_point);
306
distro_cd_detected(libhal_ctx_get_user_data(ctx), cdtype, mount_point);
190
up_device_changed (GduPool *pool, GduDevice *device, gpointer data)
192
//g_print("up_device_changed %s\n", gdu_device_get_device_file (device));
194
// check if that is a removable device
195
if (!gdu_device_is_removable(device))
198
// we only care about the first mount point
199
const gchar *p = gdu_device_get_mount_path (device);
200
//g_print("checking mount point %s\n", p);
201
up_check_mount_point_for_packages (p, data);
206
up_check_mounted_devices (GduPool *pool, gpointer data)
208
GList *devices = gdu_pool_get_devices (pool);
313
up_check_mounted_devices (gpointer data)
315
LibHalContext *hal_ctx;
321
devices = libhal_get_all_devices (hal_ctx, &nr, NULL);
322
/* Now go over the devices and check for CDROMs
324
for(i=0; i<nr; i++) {
325
if(libhal_device_get_property_bool (hal_ctx, devices[i], "volume.is_mounted", NULL))
326
up_check_device_for_packages (hal_ctx, devices[i]);
210
while(devices != NULL) {
211
up_device_changed (pool, devices->data, data);
212
devices = g_list_next(devices);
214
g_list_free(devices);
218
up_do_hal_init (UpgradeNotifier *un)
220
GduPool *pool = gdu_pool_new ();
224
g_signal_connect (pool, "device_changed", (GCallback)up_device_changed, un);
225
// now check what devices we have
226
up_check_mounted_devices(pool, un);
235
#include "update-notifier.h"
238
up_do_hal_init (UpgradeNotifier *un)
240
g_warning("Detection and monitoring of CD-ROMs disabled.");
329
libhal_free_string_array (devices);
333
/** Internal UP initialization function
335
* @functions The LibHalFunctions to register as callbacks.
336
* @return The LibHalContext of the HAL connection or
346
hal_ctx = libhal_ctx_new ();
348
g_warning ("failed to initialize HAL!\n");
352
dbus_error_init (&error);
353
if (!hal_mainloop_integration (hal_ctx, &error)) {
354
g_warning ("hal_initialize failed: %s\n", error.message);
355
dbus_error_free (&error);
359
libhal_ctx_set_device_property_modified (hal_ctx,
360
hal_property_modified);
362
if (!libhal_device_property_watch_all (hal_ctx, &error)) {
363
g_warning ("failed to watch all HAL properties!: %s\n", error.message);
364
libhal_ctx_shutdown (hal_ctx, &error);
368
if (!libhal_ctx_init (hal_ctx, &error)) {
369
g_warning ("hal_initialize failed: %s\n", error.message);
370
dbus_error_free (&error);
371
libhal_ctx_free (hal_ctx);
376
* Do something to ping the HAL daemon - the above functions will
377
* succeed even if hald is not running, so long as DBUS is. But we
378
* want to exit silently if hald is not running, to behave on
381
devices = libhal_get_all_devices (hal_ctx, &nr, &error);
383
g_warning ("seems that HAL is not running\n");
384
libhal_ctx_shutdown (hal_ctx, &error);
385
if (dbus_error_is_set (&error))
386
dbus_error_free (&error);
387
libhal_ctx_free (hal_ctx);
390
libhal_free_string_array (devices);
392
// check for already mounted media for new package CDs
393
// (after a small delay)
394
g_timeout_add (5000, up_check_mounted_devices, hal_ctx);