diff -ur hal-0.5.11/hald/create_cache.c hal-0.5.11~git20080402/hald/create_cache.c --- hal-0.5.11/hald/create_cache.c 2008-05-08 00:23:46.000000000 +0100 +++ hal-0.5.11~git20080402/hald/create_cache.c 2008-03-14 19:57:37.000000000 +0000 @@ -172,9 +172,7 @@ return MERGE_UNKNOWN; } -#define ROUND(len,align) ((len + align - 1) & -align) -#define ROUND32(len) ROUND(len, 4) -#define RULES_ROUND(off) ROUND(off, __alignof__(struct rule)) +#define ROUND32(len) ((len + 3) & ~0x03) static void pad32_write(int fd, off_t offset, void *data, size_t len) { @@ -271,10 +269,9 @@ if (fdi_ctx->rule.rtype == RULE_UNKNOWN) DIE(("I refuse to store garbage")); - fdi_ctx->rule.rule_size = - RULES_ROUND(sizeof(struct rule) + - ROUND32(fdi_ctx->rule.key_len) + - ROUND32(fdi_ctx->rule.value_len)); + fdi_ctx->rule.rule_size = sizeof(struct rule) + + ROUND32(fdi_ctx->rule.key_len) + + ROUND32(fdi_ctx->rule.value_len); pad32_write(fdi_ctx->cache_fd, fdi_ctx->position, &fdi_ctx->rule, sizeof(struct rule)); @@ -300,7 +297,7 @@ if (fdi_ctx->depth >= HAL_MAX_INDENT_DEPTH) DIE(("Rule depth overflow")); fdi_ctx->match_at_depth[fdi_ctx->depth++] = fdi_ctx->position; -} +}; static void set_jump_position(struct fdi_context *fdi_ctx) { @@ -310,7 +307,7 @@ DIE(("Rule depth underrun")); fdi_ctx->depth--; - offset = RULES_ROUND(lseek(fdi_ctx->cache_fd, 0, SEEK_END)); + offset = lseek(fdi_ctx->cache_fd, 0, SEEK_END); pad32_write(fdi_ctx->cache_fd, fdi_ctx->match_at_depth[fdi_ctx->depth] + offsetof(struct rule, jump_position), &offset, sizeof(fdi_ctx->rule.jump_position)); @@ -334,7 +331,7 @@ init_rule_struct(&fdi_ctx->rule); fdi_ctx->rule.rtype = get_rule_type(el); - fdi_ctx->position = RULES_ROUND(lseek(fdi_ctx->cache_fd, 0, SEEK_END)); + fdi_ctx->position = lseek(fdi_ctx->cache_fd, 0, SEEK_END); if (fdi_ctx->rule.rtype == RULE_UNKNOWN) return; /* get key and attribute for current rule */ @@ -435,11 +432,6 @@ if (rtype == RULE_UNKNOWN) return; if (rtype == RULE_MATCH){ - if (fdi_ctx->rule.rtype == RULE_MATCH) { - /* the match rule wasn't stored yet, store it now. So it's stored - * _before_ jump_position is written into the cache */ - store_rule(fdi_ctx); - } set_jump_position(fdi_ctx); return; } @@ -518,7 +510,7 @@ /* insert last dummy rule into list */ init_rule_struct(&fdi_ctx->rule); fdi_ctx->rule.rtype = RULE_EOF; - fdi_ctx->position = RULES_ROUND(lseek(fdi_ctx->cache_fd, 0, SEEK_END)); + fdi_ctx->position = lseek(fdi_ctx->cache_fd, 0, SEEK_END); store_key(fdi_ctx, filename); store_value(fdi_ctx, "", 0); store_rule(fdi_ctx); @@ -543,7 +535,7 @@ num_skipped_fdi_files = 0; - num_entries = scandir (dir, &name_list, NULL, _alphasort); + num_entries = scandir (dir, &name_list, 0, _alphasort); if (num_entries == -1) { HAL_ERROR (("Cannot scan '%s': %s", dir, strerror (errno))); goto error; @@ -607,6 +599,8 @@ } +int haldc_force_recreate = 0; + /* returns number of skipped fdi files or -1 on unrecoverable errors */ static int di_rules_init (void) @@ -614,7 +608,7 @@ char * cachename; int fd = -1; struct cache_header header; - gchar *cachename_temp; + char cachename_temp [PATH_MAX+1]; char *hal_fdi_source_preprobe = getenv ("HAL_FDI_SOURCE_PREPROBE"); char *hal_fdi_source_information = getenv ("HAL_FDI_SOURCE_INFORMATION"); char *hal_fdi_source_policy = getenv ("HAL_FDI_SOURCE_POLICY"); @@ -629,7 +623,8 @@ if (haldc_verbose) HAL_INFO (("Loading rules")); - cachename_temp = g_strconcat (cachename, "~", NULL); + strncpy(cachename_temp, cachename, PATH_MAX); + strncat(cachename_temp, "~", PATH_MAX); fd = open(cachename_temp, O_CREAT|O_RDWR|O_TRUNC, 0644); if(fd < 0) { @@ -640,7 +635,7 @@ memset(&header, 0, sizeof(struct cache_header)); pad32_write(fd, 0, &header, sizeof(struct cache_header)); - header.fdi_rules_preprobe = RULES_ROUND(lseek(fd, 0, SEEK_END)); + header.fdi_rules_preprobe = lseek(fd, 0, SEEK_END); if (hal_fdi_source_preprobe != NULL) { if ((n = rules_search_and_add_fdi_files (hal_fdi_source_preprobe, fd)) == -1) goto error; @@ -654,7 +649,7 @@ num_skipped_fdi_files += n; } - header.fdi_rules_information = RULES_ROUND(lseek(fd, 0, SEEK_END)); + header.fdi_rules_information = lseek(fd, 0, SEEK_END); if (hal_fdi_source_information != NULL) { if ((n = rules_search_and_add_fdi_files (hal_fdi_source_information, fd)) == -1) goto error; @@ -668,7 +663,7 @@ num_skipped_fdi_files += n; } - header.fdi_rules_policy = RULES_ROUND(lseek(fd, 0, SEEK_END)); + header.fdi_rules_policy = lseek(fd, 0, SEEK_END); if (hal_fdi_source_policy != NULL) { if ((n = rules_search_and_add_fdi_files (hal_fdi_source_policy, fd)) == -1) goto error; @@ -686,8 +681,9 @@ pad32_write(fd, 0, &header, sizeof(struct cache_header)); close(fd); if (rename (cachename_temp, cachename) != 0) { + unlink (cachename_temp); HAL_ERROR (("Cannot rename '%s' to '%s': %s", cachename_temp, cachename, strerror (errno))); - goto error; + return -1; } if (haldc_verbose){ @@ -707,7 +703,6 @@ close (fd); unlink (cachename_temp); - g_free (cachename_temp); return -1; } @@ -718,14 +713,15 @@ * */ static void -usage (void) +usage () { fprintf (stderr, "\n" "usage : hald-generate-fdi-cache [OPTION]\n"); fprintf (stderr, "\n" + " --force Force regeneration of cache.\n" " --help Show this information and exit.\n" - " --verbose Show verbose rule processing output.\n" - " --version Output version information and exit.\n" + " --verbose Show verbose rule processing output.\n" + " --version Output version information and exit.\n" "\n" "hald-generate-fdi-cache is a tool to generate binary cache from FDI files.\n" "\n" @@ -746,6 +742,7 @@ static struct option long_options[] = { {"help", 0, NULL, 0}, {"version", 0, NULL, 0}, + {"force", 0, NULL, 0}, {"verbose", 0, NULL, 0}, {NULL, 0, NULL, 0} }; @@ -767,6 +764,8 @@ return 0; } else if (strcmp (opt, "verbose") == 0) { haldc_verbose = 1; + } else if (strcmp (opt, "force") == 0) { + haldc_force_recreate = 1; } break; diff -ur hal-0.5.11/hald/device.c hal-0.5.11~git20080402/hald/device.c --- hal-0.5.11/hald/device.c 2008-05-08 00:24:11.000000000 +0100 +++ hal-0.5.11~git20080402/hald/device.c 2008-03-14 19:57:37.000000000 +0000 @@ -80,14 +80,14 @@ } g_slist_free (prop->v.strlist_value); } - g_slice_free (HalProperty, prop); + g_free (prop); } static inline HalProperty * hal_property_new (int type) { HalProperty *prop; - prop = g_slice_new0 (HalProperty); + prop = g_new0 (HalProperty, 1); prop->type = type; return prop; } @@ -211,8 +211,7 @@ } if (!validated) { - HAL_WARNING (("Property has invalid UTF-8 string '%s', it was changed to: '%s'", - value, prop->v.str_value)); + HAL_WARNING (("Property has invalid UTF-8 string '%s'", value)); } } @@ -370,7 +369,6 @@ CAPABILITY_ADDED, LOCK_ACQUIRED, LOCK_RELEASED, - PRE_PROPERTY_CHANGED, LAST_SIGNAL }; @@ -426,19 +424,6 @@ G_TYPE_BOOLEAN, G_TYPE_BOOLEAN); - signals[PRE_PROPERTY_CHANGED] = - g_signal_new ("pre_property_changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalDeviceClass, - property_changed), - NULL, NULL, - hald_marshal_VOID__STRING_BOOL, - G_TYPE_NONE, 2, - G_TYPE_STRING, - G_TYPE_BOOLEAN); - - signals[CAPABILITY_ADDED] = g_signal_new ("capability_added", G_TYPE_FROM_CLASS (klass), @@ -487,9 +472,9 @@ device->private->num_addons = 0; device->private->num_addons_ready = 0; - device->private->props = g_hash_table_new_full (g_direct_hash, - g_direct_equal, - NULL, + device->private->props = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, (GDestroyNotify) hal_property_free); } @@ -536,15 +521,10 @@ static inline HalProperty * hal_device_property_find (HalDevice *device, const char *key) { - GQuark quark = g_quark_try_string (key); - g_return_val_if_fail (device != NULL, NULL); g_return_val_if_fail (key != NULL, NULL); - if (quark) - return g_hash_table_lookup (device->private->props, GINT_TO_POINTER(quark)); - else - return NULL; + return g_hash_table_lookup (device->private->props, key); } typedef struct @@ -796,7 +776,6 @@ if (device->private->udi != NULL) g_free (device->private->udi); device->private->udi = g_strdup (udi); - hal_device_property_set_string (device, "info.udi", udi); } void @@ -871,12 +850,11 @@ { hdpfe_ud_t *c; HalProperty *prop; - const gchar *key_string = g_quark_to_string ((GQuark) GPOINTER_TO_UINT(key)); c = (hdpfe_ud_t *) user_data; prop = (HalProperty *) value; - c->callback (c->device, key_string, c->user_data); + c->callback (c->device, (const char *) key, c->user_data); } void @@ -1073,9 +1051,6 @@ if (strcmp (hal_property_get_string (prop), value != NULL ? value : "") == 0) return TRUE; - g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0, - key, FALSE); - hal_property_set_string (prop, value); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, @@ -1085,8 +1060,7 @@ prop = hal_property_new (HAL_PROPERTY_TYPE_STRING); hal_property_set_string (prop, value); - g_hash_table_insert (device->private->props, - GINT_TO_POINTER(g_quark_from_string (key)), prop); + g_hash_table_insert (device->private->props, g_strdup (key), prop); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, key, FALSE, TRUE); @@ -1112,9 +1086,6 @@ if (hal_property_get_int (prop) == value) return TRUE; - g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0, - key, FALSE); - hal_property_set_int (prop, value); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, @@ -1123,8 +1094,7 @@ } else { prop = hal_property_new (HAL_PROPERTY_TYPE_INT32); hal_property_set_int (prop, value); - g_hash_table_insert (device->private->props, - GINT_TO_POINTER(g_quark_from_string (key)), prop); + g_hash_table_insert (device->private->props, g_strdup (key), prop); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, key, FALSE, TRUE); @@ -1150,9 +1120,6 @@ if (hal_property_get_uint64 (prop) == value) return TRUE; - g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0, - key, FALSE); - hal_property_set_uint64 (prop, value); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, @@ -1161,8 +1128,7 @@ } else { prop = hal_property_new (HAL_PROPERTY_TYPE_UINT64); hal_property_set_uint64 (prop, value); - g_hash_table_insert (device->private->props, - GINT_TO_POINTER(g_quark_from_string (key)), prop); + g_hash_table_insert (device->private->props, g_strdup (key), prop); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, key, FALSE, TRUE); @@ -1188,9 +1154,6 @@ if (hal_property_get_bool (prop) == value) return TRUE; - g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0, - key, FALSE); - hal_property_set_bool (prop, value); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, @@ -1199,8 +1162,7 @@ } else { prop = hal_property_new (HAL_PROPERTY_TYPE_BOOLEAN); hal_property_set_bool (prop, value); - g_hash_table_insert (device->private->props, - GINT_TO_POINTER(g_quark_from_string (key)), prop); + g_hash_table_insert (device->private->props, g_strdup (key), prop); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, key, FALSE, TRUE); @@ -1226,9 +1188,6 @@ if (hal_property_get_double (prop) == value) return TRUE; - g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0, - key, FALSE); - hal_property_set_double (prop, value); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, @@ -1237,8 +1196,7 @@ } else { prop = hal_property_new (HAL_PROPERTY_TYPE_DOUBLE); hal_property_set_double (prop, value); - g_hash_table_insert (device->private->props, - GINT_TO_POINTER(g_quark_from_string (key)), prop); + g_hash_table_insert (device->private->props, g_strdup (key), prop); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, key, FALSE, TRUE); @@ -1276,21 +1234,17 @@ if (equal) return TRUE; } - g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0, - key, FALSE); - /* TODO: check why hal_property_strlist_clear (prop) not work and why * we need to remove the key and a new one to get this running: * - multiple copy calls mixed with e.g. append rules */ - g_hash_table_remove (device->private->props, GINT_TO_POINTER(g_quark_from_string(key))); + g_hash_table_remove (device->private->props, key); prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST); for (l = value ; l != NULL; l = l->next) { hal_property_strlist_append (prop, l->data); } - g_hash_table_insert (device->private->props, GINT_TO_POINTER(g_quark_from_string (key)), - prop); + g_hash_table_insert (device->private->props, g_strdup (key), prop); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, key, FALSE, FALSE); @@ -1300,8 +1254,7 @@ for (l = value ; l != NULL; l = l->next) { hal_property_strlist_append (prop, l->data); } - g_hash_table_insert (device->private->props, GINT_TO_POINTER(g_quark_from_string (key)), - prop); + g_hash_table_insert (device->private->props, g_strdup (key), prop); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, key, FALSE, TRUE); @@ -1354,17 +1307,10 @@ gboolean hal_device_property_remove (HalDevice *device, const char *key) { - GQuark quark = g_quark_try_string (key); - if (quark && g_hash_table_lookup (device->private->props, GINT_TO_POINTER(quark))) { - g_signal_emit (device, signals[PRE_PROPERTY_CHANGED], 0, - key, TRUE); - - if (g_hash_table_remove (device->private->props, - GINT_TO_POINTER(quark))) { - g_signal_emit (device, signals[PROPERTY_CHANGED], 0, - key, TRUE, FALSE); - return TRUE; - } + if (g_hash_table_remove (device->private->props, key)) { + g_signal_emit (device, signals[PROPERTY_CHANGED], 0, + key, TRUE, FALSE); + return TRUE; } return FALSE; } @@ -1476,8 +1422,7 @@ prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST); hal_property_strlist_append (prop, value); - g_hash_table_insert (device->private->props, - GINT_TO_POINTER(g_quark_from_string (key)), prop); + g_hash_table_insert (device->private->props, g_strdup (key), prop); if (!changeset) g_signal_emit (device, signals[PROPERTY_CHANGED], 0, @@ -1535,8 +1480,7 @@ prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST); hal_property_strlist_prepend (prop, value); - g_hash_table_insert (device->private->props, - GINT_TO_POINTER(g_quark_from_string (key)), prop); + g_hash_table_insert (device->private->props, g_strdup (key), prop); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, key, FALSE, TRUE); @@ -1582,8 +1526,7 @@ if (prop == NULL) { prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST); - g_hash_table_insert (device->private->props, - GINT_TO_POINTER(g_quark_from_string (key)), prop); + g_hash_table_insert (device->private->props, g_strdup (key), prop); if (!changeset) g_signal_emit (device, signals[PROPERTY_CHANGED], 0, @@ -1595,9 +1538,9 @@ return FALSE; /* TODO: check why hal_property_strlist_clear (prop) not work */ - g_hash_table_remove (device->private->props, GINT_TO_POINTER(g_quark_from_string(key))); + g_hash_table_remove (device->private->props, key); prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST); - g_hash_table_insert (device->private->props, GINT_TO_POINTER(g_quark_from_string(key)), prop); + g_hash_table_insert (device->private->props, g_strdup (key), prop); if (!changeset) { g_signal_emit (device, signals[PROPERTY_CHANGED], 0, @@ -1635,8 +1578,7 @@ prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST); hal_property_strlist_prepend (prop, value); - g_hash_table_insert (device->private->props, - GINT_TO_POINTER(g_quark_from_string (key)), prop); + g_hash_table_insert (device->private->props, g_strdup (key), prop); g_signal_emit (device, signals[PROPERTY_CHANGED], 0, key, FALSE, TRUE); diff -ur hal-0.5.11/hald/device_info.c hal-0.5.11~git20080402/hald/device_info.c --- hal-0.5.11/hald/device_info.c 2008-05-08 00:23:47.000000000 +0100 +++ hal-0.5.11~git20080402/hald/device_info.c 2008-03-14 19:57:37.000000000 +0000 @@ -804,7 +804,7 @@ return FALSE; } - // return FALSE; + return FALSE; } /* we have finished the callouts for a device, now add it to the gdl */ @@ -1021,6 +1021,8 @@ key, hal_device_get_udi (d))); spawned = hal_device_new (); hal_device_property_set_string (spawned, "info.subsystem", "unknown"); + hal_device_property_set_string (spawned, "info.bus", "unknown"); + hal_device_property_set_string (spawned, "info.udi", key); hal_device_property_set_string (spawned, "info.parent", hal_device_get_udi (d)); hal_device_set_udi (spawned, key); diff -ur hal-0.5.11/hald/device_pm.c hal-0.5.11~git20080402/hald/device_pm.c --- hal-0.5.11/hald/device_pm.c 2008-05-08 00:23:55.000000000 +0100 +++ hal-0.5.11~git20080402/hald/device_pm.c 2008-03-14 19:57:37.000000000 +0000 @@ -51,11 +51,9 @@ const char *reporting_unit; int reporting_current; int reporting_lastfull; - int reporting_design; int reporting_rate; int normalised_current; int normalised_lastfull; - int normalised_design; int normalised_rate; int design_voltage; int voltage; @@ -69,8 +67,6 @@ "battery.reporting.current"); reporting_lastfull = hal_device_property_get_int (d, "battery.reporting.last_full"); - reporting_design = hal_device_property_get_int (d, - "battery.reporting.design"); reporting_rate = hal_device_property_get_int (d, "battery.reporting.rate"); @@ -102,20 +98,18 @@ /* If the current voltage is unknown, smaller than 50% of design voltage (fd.o #8593) * or greater than design, then use design voltage. */ if (voltage < (design_voltage/2) || voltage > design_voltage) { - //HAL_DEBUG (("Current voltage is unknown, smaller than 50%% or greater than design")); + HAL_DEBUG (("Current voltage is unknown, smaller than 50%% or greater than design")); voltage = design_voltage; } normalised_current = (reporting_current * voltage) / 1000; normalised_lastfull = (reporting_lastfull * voltage) / 1000; - normalised_design = (reporting_design * voltage) / 1000; normalised_rate = (reporting_rate * voltage) / 1000; } else { /* handle as if mWh (which don't need conversion), which is * the most common case. */ normalised_current = reporting_current; normalised_lastfull = reporting_lastfull; - normalised_design = reporting_design; normalised_rate = reporting_rate; } @@ -126,8 +120,6 @@ normalised_current = 0; if (normalised_lastfull < 0) normalised_lastfull = 0; - if (normalised_design < 0) - normalised_design = 0; if (normalised_rate < 0) normalised_rate = 0; @@ -150,7 +142,6 @@ if (bat_type != NULL && !strncmp (bat_type, "primary", 7)) { /* check if the machine is on AC or on battery */ - /* TODO: rework for power_supply */ devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (), "info.category", "ac_adapter"); @@ -197,7 +188,6 @@ hal_device_property_set_int (d, "battery.charge_level.current", normalised_current); hal_device_property_set_int (d, "battery.charge_level.last_full", normalised_lastfull); - hal_device_property_set_int (d, "battery.charge_level.design", normalised_design); hal_device_property_set_int (d, "battery.charge_level.rate", normalised_rate); } @@ -215,19 +205,19 @@ int current; int lastfull; - percentage = -1; + /* default to fully charge to avoid triggering low power warnings on + * really broken batteries */ + percentage = 100; /* use the charge level compared to the last full amount */ current = hal_device_property_get_int (d, "battery.charge_level.current"); lastfull = hal_device_property_get_int (d, "battery.charge_level.last_full"); /* make sure we have current */ - if (current < 0) { - HAL_WARNING (("battery.charge_level.current %i, delete battery.charge_level.percentage", current)); - } else if (current == 0) { - percentage = 0; /* battery is empty */ + if (current <= 0) { + HAL_WARNING (("battery.charge_level.current %i, returning -1!", current)); } else if (lastfull <= 0) { - HAL_WARNING (("battery.charge_level.lastfull %i, delete battery.charge_level.percentage", lastfull)); + HAL_WARNING (("battery.charge_level.lastfull %i, percentage returning -1!", lastfull)); } else { percentage = ((double) current / (double) lastfull) * 100; /* Some bios's will report this out of range of 0..100, limit it here */ @@ -236,11 +226,7 @@ else if (percentage < 0) percentage = 1; } - - if (percentage < 0) - hal_device_property_remove (d, "battery.charge_level.percentage"); - else - hal_device_property_set_int (d, "battery.charge_level.percentage", percentage); + hal_device_property_set_int (d, "battery.charge_level.percentage", percentage); } /** @@ -254,31 +240,6 @@ device_pm_calculate_time (HalDevice *d) { int time; - gboolean calculate_per_time; - - calculate_per_time = hal_device_property_get_bool (d, "battery.remaining_time.calculate_per_time"); - - /* check if we may need to calculate the remaining time because of special cases */ - if (!calculate_per_time && hal_device_property_get_bool(d, "battery.rechargeable.is_charging")) { - const char *type; - const char *unit; - - type = hal_device_property_get_string(d, "battery.type"); - if ((type != NULL) && (strcmp(type, "primary") == 0)) { - unit = hal_device_property_get_string(d, "battery.charge_level.unit"); - /* check if the unit is mWh */ - if ((unit != NULL) && (strcmp(unit, "mWh") == 0)) { - /* check if the rate is higher than 50 Watt, this should be wrong - better calculate the time based on time */ - if (hal_device_property_get_int (d, "battery.charge_level.rate") > 50000) { - HAL_WARNING(("battery.charge_level.rate (%d) was > 50000 mWh, assume thats wrong, calculate from now based on time.", - hal_device_property_get_int (d, "battery.charge_level.rate"))); - hal_device_property_set_bool (d, "battery.remaining_time.calculate_per_time", TRUE); - calculate_per_time = TRUE; - } - } - } - } time = util_compute_time_remaining ( hal_device_get_udi (d), @@ -287,7 +248,7 @@ hal_device_property_get_int (d, "battery.charge_level.last_full"), hal_device_property_get_bool (d, "battery.rechargeable.is_discharging"), hal_device_property_get_bool (d, "battery.rechargeable.is_charging"), - calculate_per_time); + hal_device_property_get_bool (d, "battery.remaining_time.calculate_per_time")); /* zero time is unknown */ if (time > 0) diff -ur hal-0.5.11/hald/device_store.c hal-0.5.11~git20080402/hald/device_store.c --- hal-0.5.11/hald/device_store.c 2008-05-08 00:23:48.000000000 +0100 +++ hal-0.5.11~git20080402/hald/device_store.c 2008-03-14 19:57:37.000000000 +0000 @@ -137,7 +137,6 @@ static void hal_device_store_init (HalDeviceStore *device) { - device->property_index = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); } GType @@ -176,27 +175,6 @@ } static void -property_index_check_all (HalDeviceStore *store, HalDevice *device, gboolean add); - -static void -property_index_modify_string (HalDeviceStore *store, HalDevice *device, - const char *key, gboolean added); - -static void -device_pre_property_changed (HalDevice *device, - const char *key, - gboolean removed, - gpointer data) -{ - HalDeviceStore *store = HAL_DEVICE_STORE (data); - - if (hal_device_property_get_type (device, key) == HAL_PROPERTY_TYPE_STRING) { - property_index_modify_string(store, device, key, FALSE); - } -} - - -static void emit_device_property_changed (HalDevice *device, const char *key, gboolean added, @@ -205,10 +183,6 @@ { HalDeviceStore *store = HAL_DEVICE_STORE (data); - if (hal_device_property_get_type (device, key) == HAL_PROPERTY_TYPE_STRING) { - property_index_modify_string(store, device, key, TRUE); - } - g_signal_emit (store, signals[DEVICE_PROPERTY_CHANGED], 0, device, key, added, removed); } @@ -264,8 +238,6 @@ g_signal_connect (device, "property_changed", G_CALLBACK (emit_device_property_changed), store); - g_signal_connect (device, "pre_property_changed", - G_CALLBACK (device_pre_property_changed), store); g_signal_connect (device, "capability_added", G_CALLBACK (emit_device_capability_added), store); g_signal_connect (device, "lock_acquired", @@ -273,7 +245,6 @@ g_signal_connect (device, "lock_released", G_CALLBACK (emit_device_lock_released), store); - property_index_check_all (store, device, TRUE); g_signal_emit (store, signals[STORE_CHANGED], 0, device, TRUE); out: @@ -292,9 +263,6 @@ (gpointer)emit_device_property_changed, store); g_signal_handlers_disconnect_by_func (device, - (gpointer)device_pre_property_changed, - store); - g_signal_handlers_disconnect_by_func (device, (gpointer)emit_device_capability_added, store); g_signal_handlers_disconnect_by_func (device, @@ -304,8 +272,6 @@ (gpointer)emit_device_lock_released, store); - property_index_check_all (store, device, FALSE); - g_signal_emit (store, signals[STORE_CHANGED], 0, device, FALSE); g_object_unref (device); @@ -364,7 +330,7 @@ hal_device_store_print (HalDeviceStore *store) { fprintf (stderr, "===============================================\n"); - fprintf (stderr, "Dumping %u devices\n", + fprintf (stderr, "Dumping %d devices\n", g_slist_length (store->devices)); fprintf (stderr, "===============================================\n"); hal_device_store_foreach (store, @@ -379,37 +345,25 @@ const char *value) { GSList *iter; - GSList *devices; - GHashTable *index; g_return_val_if_fail (store != NULL, NULL); g_return_val_if_fail (key != NULL, NULL); g_return_val_if_fail (value != NULL, NULL); - index = g_hash_table_lookup (store->property_index, key); + for (iter = store->devices; iter != NULL; iter = iter->next) { + HalDevice *d = HAL_DEVICE (iter->data); + int type; + + if (!hal_device_has_property (d, key)) + continue; + + type = hal_device_property_get_type (d, key); + if (type != HAL_PROPERTY_TYPE_STRING) + continue; - if (index) { - devices = g_hash_table_lookup (index, value); - if (devices) - return (HalDevice*) devices->data; - else - return NULL; - } else { - for (iter = store->devices; iter != NULL; iter = iter->next) { - HalDevice *d = HAL_DEVICE (iter->data); - int type; - - if (!hal_device_has_property (d, key)) - continue; - - type = hal_device_property_get_type (d, key); - if (type != HAL_PROPERTY_TYPE_STRING) - continue; - - if (strcmp (hal_device_property_get_string (d, key), - value) == 0) - return d; - } + if (strcmp (hal_device_property_get_string (d, key), + value) == 0) + return d; } return NULL; @@ -450,107 +404,26 @@ { GSList *iter; GSList *matches = NULL; - GSList *devices; - GHashTable *index; g_return_val_if_fail (store != NULL, NULL); g_return_val_if_fail (key != NULL, NULL); g_return_val_if_fail (value != NULL, NULL); - index = g_hash_table_lookup (store->property_index, key); - - if (index) { - devices = g_hash_table_lookup (index, value); - return g_slist_copy(devices); - } else { - for (iter = store->devices; iter != NULL; iter = iter->next) { - HalDevice *d = HAL_DEVICE (iter->data); - int type; - - if (!hal_device_has_property (d, key)) - continue; - - type = hal_device_property_get_type (d, key); - if (type != HAL_PROPERTY_TYPE_STRING) - continue; - - if (strcmp (hal_device_property_get_string (d, key), - value) == 0) - matches = g_slist_prepend (matches, d); - } - } - - return matches; -} - + for (iter = store->devices; iter != NULL; iter = iter->next) { + HalDevice *d = HAL_DEVICE (iter->data); + int type; -void -hal_device_store_index_property (HalDeviceStore *store, const char *key) -{ - GHashTable *index; + if (!hal_device_has_property (d, key)) + continue; - index = g_hash_table_lookup (store->property_index, key); + type = hal_device_property_get_type (d, key); + if (type != HAL_PROPERTY_TYPE_STRING) + continue; - if (!index) { - index = g_hash_table_new (g_str_hash, g_str_equal); - g_hash_table_insert (store->property_index, g_strdup (key), index); + if (strcmp (hal_device_property_get_string (d, key), + value) == 0) + matches = g_slist_prepend (matches, d); } -} -static void -property_index_modify_string (HalDeviceStore *store, HalDevice *device, - const char *key, gboolean added) -{ - GHashTable *index; - const char *value; - GSList *devices; - - value = hal_device_property_get_string (device, key); - index = g_hash_table_lookup (store->property_index, key); - - if (!index) return; - - devices = g_hash_table_lookup (index, value); - - if (added) { /*add*/ - HAL_DEBUG (("adding %p to (%s,%s)", device, key, value)); - devices = g_slist_prepend (devices, device); - } else { /*remove*/ - HAL_DEBUG (("removing %p from (%s,%s)", device, key, value)); - devices = g_slist_remove_all (devices, device); - } - g_hash_table_insert (index, (gpointer) value, devices); -} - -#if GLIB_CHECK_VERSION (2,14,0) - /* Nothing */ -#else -inline static void -list_keys (gpointer key, gpointer value, GList **keys) -{ - *keys = g_list_append (*keys, key); -} - -inline static GList* -g_hash_table_get_keys (GHashTable *hash) -{ - GList *keys = NULL; - g_hash_table_foreach (hash, (GHFunc)list_keys, &keys); - return keys; -} -#endif - -static void -property_index_check_all (HalDeviceStore *store, HalDevice *device, gboolean added) -{ - GList *indexed_properties, *lp; - - indexed_properties = g_hash_table_get_keys (store->property_index); - for (lp = indexed_properties; lp; lp = g_list_next (lp)) { - if (hal_device_property_get_type (device, lp->data) == HAL_PROPERTY_TYPE_STRING) { - property_index_modify_string (store, device, lp->data, added); - } - } - g_list_free (indexed_properties); + return matches; } - diff -ur hal-0.5.11/hald/device_store.h hal-0.5.11~git20080402/hald/device_store.h --- hal-0.5.11/hald/device_store.h 2008-05-08 00:23:48.000000000 +0100 +++ hal-0.5.11~git20080402/hald/device_store.h 2008-03-14 19:57:37.000000000 +0000 @@ -38,7 +38,6 @@ GObject parent; GSList *devices; - GHashTable *property_index; }; struct _HalDeviceStoreClass { @@ -122,6 +121,5 @@ void hal_device_store_print (HalDeviceStore *store); -void hal_device_store_index_property (HalDeviceStore *store, const char *key); #endif /* DEVICE_STORE_H */ diff -ur hal-0.5.11/hald/dummy/osspec.c hal-0.5.11~git20080402/hald/dummy/osspec.c --- hal-0.5.11/hald/dummy/osspec.c 2008-05-08 00:23:30.000000000 +0100 +++ hal-0.5.11~git20080402/hald/dummy/osspec.c 2008-03-14 19:57:37.000000000 +0000 @@ -37,27 +37,6 @@ #include "../util.h" #include "../device_info.h" -HalFileMonitor * -osspec_get_file_monitor (void) -{ - return NULL; -} - -guint -hal_file_monitor_add_notify (HalFileMonitor *monitor, - const char *path, - int mask, - HalFileMonitorNotifyFunc notify_func, - gpointer data) -{ - return 0; -} - -void -osspec_privileged_init (void) -{ -} - void osspec_init (void) { @@ -82,7 +61,9 @@ root = hal_device_new (); hal_device_property_set_string (root, "info.subsystem", "unknown"); + hal_device_property_set_string (root, "info.bus", "unknown"); hal_device_property_set_string (root, "info.product", "Computer"); + hal_device_property_set_string (root, "info.udi", "/org/freedesktop/Hal/devices/computer"); hal_device_set_udi (root, "/org/freedesktop/Hal/devices/computer"); hal_device_store_add (hald_get_tdl (), root); diff -ur hal-0.5.11/hald/hald.c hal-0.5.11~git20080402/hald/hald.c --- hal-0.5.11/hald/hald.c 2008-05-08 00:23:57.000000000 +0100 +++ hal-0.5.11~git20080402/hald/hald.c 2008-03-14 19:57:37.000000000 +0000 @@ -254,42 +254,13 @@ return temporary_device_list; } -void -hald_compute_udi (gchar *dst, gsize dstsize, const gchar *format, ...) -{ - int i; - char buf[256]; - va_list args; - - va_start (args, format); - hal_util_compute_udi_valist (hald_get_gdl (), dst, dstsize, format, args); - va_end (args); - - if (hal_device_store_find (hald_get_gdl (), dst) == NULL && - hal_device_store_find (hald_get_tdl (), dst) == NULL) - goto out; - - for (i = 0; ; i++) { - g_snprintf (buf, sizeof(buf), "%s_%d", dst, i); - if (hal_device_store_find (hald_get_gdl (), buf) == NULL && - hal_device_store_find (hald_get_tdl (), buf) == NULL) { - g_strlcpy (dst, buf, dstsize); - goto out; - } - } - -out: - ; - -} - /** * usage: * * Print out program usage. */ static void -usage (void) +usage () { fprintf (stderr, "\n" "usage : hald [--daemon=yes|no] [--verbose=yes|no] [--help]\n"); fprintf (stderr, @@ -322,7 +293,7 @@ /** If #TRUE, we will spew out debug */ dbus_bool_t hald_is_verbose = FALSE; dbus_bool_t hald_use_syslog = FALSE; -static dbus_bool_t hald_debug_exit_after_probing = FALSE; +dbus_bool_t hald_debug_exit_after_probing = FALSE; #ifdef HAVE_POLKIT PolKitContext *pk_context; @@ -506,15 +477,9 @@ g_source_remove (_polkit_cooloff_timer); HAL_INFO (("restarting cool-off timer")); } -#ifdef HAVE_GLIB_2_14 - _polkit_cooloff_timer = g_timeout_add_seconds (1, - _polkit_config_really_changed, - NULL); -#else _polkit_cooloff_timer = g_timeout_add (1000, /* one second... */ _polkit_config_really_changed, NULL); -#endif } #endif /* HAVE_POLKIT */ diff -ur hal-0.5.11/hald/hald_dbus.c hal-0.5.11~git20080402/hald/hald_dbus.c --- hal-0.5.11/hald/hald_dbus.c 2008-05-08 00:23:29.000000000 +0100 +++ hal-0.5.11~git20080402/hald/hald_dbus.c 2008-03-14 19:57:37.000000000 +0000 @@ -65,10 +65,6 @@ #endif static GHashTable *singletons = NULL; -static void foreach_property_append (HalDevice *device, - const char *key, - gpointer user_data); - static void raise_error (DBusConnection *connection, DBusMessage *in_reply_to, @@ -340,83 +336,6 @@ return TRUE; } -static gboolean -foreach_device_get_udi_with_properties (HalDeviceStore *store, HalDevice *device, gpointer user_data) -{ - DBusMessageIter *iter = user_data; - DBusMessageIter iter_struct; - DBusMessageIter iter_dict; - const char *udi; - - dbus_message_iter_open_container (iter, - DBUS_TYPE_STRUCT, - NULL, - &iter_struct); - - udi = hal_device_get_udi (device); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &udi); - - dbus_message_iter_open_container (&iter_struct, - DBUS_TYPE_ARRAY, - DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING - DBUS_TYPE_STRING_AS_STRING - DBUS_TYPE_VARIANT_AS_STRING - DBUS_DICT_ENTRY_END_CHAR_AS_STRING, - &iter_dict); - - hal_device_property_foreach (device, foreach_property_append, &iter_dict); - - dbus_message_iter_close_container (&iter_struct, &iter_dict); - dbus_message_iter_close_container (iter, &iter_struct); - return TRUE; -} - -/** - * manager_get_all_devices_with_properties: - * @connection: D-BUS connection - * @message: Message - * - * Returns: What to do with the message - * - * Get all devices. - * - *
- *  array{struct {object_reference, map{string, any}}} Manager.GetAllDevicesWithProperties()
- *  
- * - */ -DBusHandlerResult -manager_get_all_devices_with_properties (DBusConnection * connection, - DBusMessage * message) -{ - DBusMessage *reply; - DBusMessageIter iter; - DBusMessageIter iter_array; - - reply = dbus_message_new_method_return (message); - if (reply == NULL) - DIE (("No memory")); - - dbus_message_iter_init_append (reply, &iter); - dbus_message_iter_open_container (&iter, - DBUS_TYPE_ARRAY, - "(sa{sv})", - &iter_array); - - hal_device_store_foreach (hald_get_gdl (), - foreach_device_get_udi_with_properties, - &iter_array); - - dbus_message_iter_close_container (&iter, &iter_array); - - if (!dbus_connection_send (connection, reply, NULL)) - DIE (("No memory")); - - dbus_message_unref (reply); - - return DBUS_HANDLER_RESULT_HANDLED; -} - /** * manager_get_all_devices: * @connection: D-BUS connection @@ -1109,7 +1028,7 @@ case HAL_PROPERTY_TYPE_STRLIST: { DBusMessageIter iter_var, iter_array; - HalDeviceStrListIter hd_iter; + HalDeviceStrListIter iter; dbus_message_iter_open_container (&iter_dict_entry, DBUS_TYPE_VARIANT, @@ -1122,11 +1041,11 @@ DBUS_TYPE_STRING_AS_STRING, &iter_array); - for (hal_device_property_strlist_iter_init (device, key, &hd_iter); - hal_device_property_strlist_iter_is_valid (&hd_iter); - hal_device_property_strlist_iter_next (&hd_iter)) { + for (hal_device_property_strlist_iter_init (device, key, &iter); + hal_device_property_strlist_iter_is_valid (&iter); + hal_device_property_strlist_iter_next (&iter)) { const char *v; - v = hal_device_property_strlist_iter_get_value (&hd_iter); + v = hal_device_property_strlist_iter_get_value (&iter); dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, @@ -3208,7 +3127,6 @@ DBusError error; const char *interface_name; const char *introspection_xml; - HelperInterfaceHandler *hih; dbus_bool_t res; HAL_TRACE (("entering")); @@ -3249,7 +3167,7 @@ hal_device_property_strlist_add (device, "info.interfaces", interface_name); - hih = g_new0 (HelperInterfaceHandler, 1); + HelperInterfaceHandler *hih = g_new0 (HelperInterfaceHandler, 1); hih->connection = connection; hih->interface_name = g_strdup (interface_name); hih->introspection_xml = g_strdup (introspection_xml); @@ -3682,6 +3600,7 @@ } hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); hal_device_store_add (hald_get_tdl (), d); dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &udi); g_free (udi); @@ -3853,7 +3772,7 @@ } /* sanity check & avoid races */ - hal_util_make_udi_unique (hald_get_gdl (), udi, sizeof udi, udi0); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof udi, "%s", udi0); if (hal_device_store_find (hald_get_gdl (), udi)) { /* loose it */ @@ -3866,6 +3785,7 @@ /* set new udi */ hal_device_property_remove (d, "info.udi"); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); /* FIXME: * 'RequireEnable' property? @@ -4403,9 +4323,6 @@ " \n" " \n" " \n" - " \n" - " \n" - " \n" " \n" " \n" " \n" @@ -4464,7 +4381,6 @@ " \n"); } else { HalDevice *d; - HalDeviceStrListIter if_iter; d = hal_device_store_find (hald_get_gdl (), path); if (d == NULL) @@ -4556,9 +4472,8 @@ " \n" " \n" " \n" - " \n"); + " \n" - xml = g_string_append (xml, " \n" " \n" " \n" @@ -4637,6 +4552,7 @@ " \n" " \n"); + HalDeviceStrListIter if_iter; for (hal_device_property_strlist_iter_init (d, "info.interfaces", &if_iter); hal_device_property_strlist_iter_is_valid (&if_iter); @@ -4801,12 +4717,6 @@ "/org/freedesktop/Hal/Manager") == 0) { return manager_get_all_devices (connection, message); } else if (dbus_message_is_method_call (message, - "org.freedesktop.Hal.Manager", - "GetAllDevicesWithProperties") && - strcmp (dbus_message_get_path (message), - "/org/freedesktop/Hal/Manager") == 0) { - return manager_get_all_devices_with_properties (connection, message); - } else if (dbus_message_is_method_call (message, "org.freedesktop.Hal.Manager", "DeviceExists") && strcmp (dbus_message_get_path (message), @@ -5166,14 +5076,8 @@ dbus_connection_unref (dbus_connection); dbus_connection = NULL; -#ifdef HAVE_GLIB_2_14 - g_timeout_add_seconds (3, reinit_dbus, NULL); -#else g_timeout_add (3000, reinit_dbus, NULL); -#endif - } else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameAcquired")){ - /* we don't need to do anything atm with this signal ... */ - return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) { @@ -5279,9 +5183,9 @@ GSList *i; GSList *j; - //HAL_INFO (("************************")); - //HAL_INFO (("Client to local_server was disconnected for %x", connection)); - //HAL_INFO (("************************")); + HAL_INFO (("************************")); + HAL_INFO (("Client to local_server was disconnected for %x", connection)); + HAL_INFO (("************************")); for (i = helper_interface_handlers; i != NULL; i = j) { HelperInterfaceHandler *hih = i->data; @@ -5323,9 +5227,9 @@ static void local_server_unregister_handler (DBusConnection *connection, void *user_data) { - //HAL_INFO (("***************************")); - //HAL_INFO (("********* unregistered %x", connection)); - //HAL_INFO (("***************************")); + HAL_INFO (("***************************")); + HAL_INFO (("********* unregistered %x", connection)); + HAL_INFO (("***************************")); } static void @@ -5337,9 +5241,9 @@ &local_server_message_handler, NULL, NULL, NULL, NULL}; - //HAL_INFO (("***************************")); - //HAL_INFO (("********* got a connection %x", new_connection)); - //HAL_INFO (("***************************")); + HAL_INFO (("***************************")); + HAL_INFO (("********* got a connection %x", new_connection)); + HAL_INFO (("***************************")); /*dbus_connection_add_filter (new_connection, server_filter_function, NULL, NULL);*/ @@ -5404,6 +5308,96 @@ #ifdef HAVE_CONKIT static void +hald_dbus_session_added (CKTracker *tracker, CKSession *session, void *user_data) +{ + HalDevice *d; + char **programs; + char *extra_env[5] = {"HALD_ACTION=session_add", + NULL /* "HALD_SESSION_ADD_SESSION_ID=" */, + NULL /* "HALD_SESSION_ADD_SESSION_UID=" */, + NULL /* "HALD_SESSION_ADD_SESSION_IS_ACTIVE=" */, + NULL}; + + HAL_INFO (("In hald_dbus_session_added for session '%s' on seat '%s'", + ck_session_get_id (session), + ck_session_get_seat (session) != NULL ? ck_seat_get_id (ck_session_get_seat (session)) : "(NONE)")); + + d = hal_device_store_find (hald_get_gdl (), "/org/freedesktop/Hal/devices/computer"); + if (d == NULL) { + d = hal_device_store_find (hald_get_tdl (), "/org/freedesktop/Hal/devices/computer"); + } + if (d == NULL) { + goto out; + } + + programs = hal_device_property_dup_strlist_as_strv (d, "info.callouts.session_add"); + if (programs == NULL) { + goto out; + } + + extra_env[1] = g_strdup_printf ("HALD_SESSION_ADD_SESSION_ID=%s", ck_session_get_id (session)); + extra_env[2] = g_strdup_printf ("HALD_SESSION_ADD_SESSION_UID=%d", ck_session_get_user (session)); + extra_env[3] = g_strdup_printf ("HALD_SESSION_ADD_SESSION_IS_ACTIVE=%s", + ck_session_is_active (session) ? "true" : "false"); + hal_callout_device (d, + NULL /* callback */, + NULL /* userdata1 */, + NULL /* userdata2 */, + programs, + extra_env); + g_free (extra_env[1]); + g_free (extra_env[2]); + g_free (extra_env[3]); +out: + ; +} + +static void +hald_dbus_session_removed (CKTracker *tracker, CKSession *session, void *user_data) +{ + HalDevice *d; + char **programs; + char *extra_env[5] = {"HALD_ACTION=session_remove", + NULL /* "HALD_SESSION_REMOVE_SESSION_ID=" */, + NULL /* "HALD_SESSION_REMOVE_SESSION_UID=" */, + NULL /* "HALD_SESSION_REMOVE_SESSION_IS_ACTIVE=" */, + NULL}; + + HAL_INFO (("In hald_dbus_session_removed for session '%s' on seat '%s'", + ck_session_get_id (session), + ck_session_get_seat (session) != NULL ? ck_seat_get_id (ck_session_get_seat (session)) : "(NONE)")); + + d = hal_device_store_find (hald_get_gdl (), "/org/freedesktop/Hal/devices/computer"); + if (d == NULL) { + d = hal_device_store_find (hald_get_tdl (), "/org/freedesktop/Hal/devices/computer"); + } + if (d == NULL) { + goto out; + } + + programs = hal_device_property_dup_strlist_as_strv (d, "info.callouts.session_remove"); + if (programs == NULL) { + goto out; + } + + extra_env[1] = g_strdup_printf ("HALD_SESSION_REMOVE_SESSION_ID=%s", ck_session_get_id (session)); + extra_env[2] = g_strdup_printf ("HALD_SESSION_REMOVE_SESSION_UID=%d", ck_session_get_user (session)); + extra_env[3] = g_strdup_printf ("HALD_SESSION_REMOVE_SESSION_IS_ACTIVE=%s", + ck_session_is_active (session) ? "true" : "false"); + hal_callout_device (d, + NULL /* callback */, + NULL /* userdata1 */, + NULL /* userdata2 */, + programs, + extra_env); + g_free (extra_env[1]); + g_free (extra_env[2]); + g_free (extra_env[3]); +out: + ; +} + +static void hald_dbus_seat_added (CKTracker *tracker, CKSeat *seat, void *user_data) { /* TODO: we could run callouts here... but they wouldn't do anything useful right now */ @@ -5502,87 +5496,6 @@ reconfigure_acl (); } - -typedef struct { - HalDevice *d; - char **programs; - char **extra_env; -} SessionChangesEntry; - -static GList *session_changes_queue = NULL; -gboolean session_changes_is_running = FALSE; - -static void session_changes_process_queue (void); - -static void -session_changes_done_cb (HalDevice *d, gpointer userdata1, gpointer userdata2) -{ - SessionChangesEntry *entry = userdata1; - - HAL_INFO (("session_changes_done_cb")); - - g_assert (entry->d == d); - - /* hal_callout_device takes ownership of entry->programs so we don't free it here */ - g_object_unref (entry->d); - g_strfreev (entry->extra_env); - g_free (entry); - - session_changes_is_running = FALSE; - - session_changes_process_queue (); -} - -static void -session_changes_process_queue (void) -{ - SessionChangesEntry *entry; - - HAL_INFO (("session_changes_process_queue")); - - /* nothing to run */ - if (session_changes_queue == NULL) - return; - - /* something is already running; wait for it to terminate */ - if (session_changes_is_running) - return; - - HAL_INFO ((" running element in queue")); - - /* pop the first element */ - entry = session_changes_queue->data; - session_changes_queue = g_list_remove (session_changes_queue, entry); - - hal_callout_device (entry->d, - session_changes_done_cb, /* callback */ - entry, /* userdata1 */ - NULL, /* userdata2 */ - entry->programs, - entry->extra_env); - - session_changes_is_running = TRUE; -} - -static void -session_changes_push (HalDevice *d, char **programs, char **extra_env) -{ - SessionChangesEntry *entry; - - HAL_INFO (("session_changes_push")); - - entry = g_new0 (SessionChangesEntry, 1); - entry->d = g_object_ref (d); - entry->programs = g_strdupv (programs); - entry->extra_env = g_strdupv (extra_env); - - /* push to end of queue */ - session_changes_queue = g_list_append (session_changes_queue, entry); - - /* only process the queue if there we are the only element */ - session_changes_process_queue (); -} - static void hald_dbus_session_active_changed (CKTracker *tracker, CKSession *session, void *user_data) { @@ -5618,96 +5531,15 @@ } extra_env[1] = g_strdup_printf ("HALD_SESSION_ACTIVE_CHANGED_SESSION_ID=%s", ck_session_get_id (session)); - extra_env[2] = g_strdup_printf ("HALD_SESSION_ACTIVE_CHANGED_SESSION_UID=%u", ck_session_get_user (session)); + extra_env[2] = g_strdup_printf ("HALD_SESSION_ACTIVE_CHANGED_SESSION_UID=%d", ck_session_get_user (session)); extra_env[3] = g_strdup_printf ("HALD_SESSION_ACTIVE_CHANGED_SESSION_IS_ACTIVE=%s", ck_session_is_active (session) ? "true" : "false"); - - session_changes_push (d, programs, extra_env); - - g_free (extra_env[1]); - g_free (extra_env[2]); - g_free (extra_env[3]); -out: - ; -} - -static void -hald_dbus_session_added (CKTracker *tracker, CKSession *session, void *user_data) -{ - HalDevice *d; - char **programs; - char *extra_env[5] = {"HALD_ACTION=session_add", - NULL /* "HALD_SESSION_ADD_SESSION_ID=" */, - NULL /* "HALD_SESSION_ADD_SESSION_UID=" */, - NULL /* "HALD_SESSION_ADD_SESSION_IS_ACTIVE=" */, - NULL}; - - HAL_INFO (("In hald_dbus_session_added for session '%s' on seat '%s'", - ck_session_get_id (session), - ck_session_get_seat (session) != NULL ? ck_seat_get_id (ck_session_get_seat (session)) : "(NONE)")); - - d = hal_device_store_find (hald_get_gdl (), "/org/freedesktop/Hal/devices/computer"); - if (d == NULL) { - d = hal_device_store_find (hald_get_tdl (), "/org/freedesktop/Hal/devices/computer"); - } - if (d == NULL) { - goto out; - } - - programs = hal_device_property_dup_strlist_as_strv (d, "info.callouts.session_add"); - if (programs == NULL) { - goto out; - } - - extra_env[1] = g_strdup_printf ("HALD_SESSION_ADD_SESSION_ID=%s", ck_session_get_id (session)); - extra_env[2] = g_strdup_printf ("HALD_SESSION_ADD_SESSION_UID=%u", ck_session_get_user (session)); - extra_env[3] = g_strdup_printf ("HALD_SESSION_ADD_SESSION_IS_ACTIVE=%s", - ck_session_is_active (session) ? "true" : "false"); - - session_changes_push (d, programs, extra_env); - - g_free (extra_env[1]); - g_free (extra_env[2]); - g_free (extra_env[3]); -out: - ; -} - -static void -hald_dbus_session_removed (CKTracker *tracker, CKSession *session, void *user_data) -{ - HalDevice *d; - char **programs; - char *extra_env[5] = {"HALD_ACTION=session_remove", - NULL /* "HALD_SESSION_REMOVE_SESSION_ID=" */, - NULL /* "HALD_SESSION_REMOVE_SESSION_UID=" */, - NULL /* "HALD_SESSION_REMOVE_SESSION_IS_ACTIVE=" */, - NULL}; - - HAL_INFO (("In hald_dbus_session_removed for session '%s' on seat '%s'", - ck_session_get_id (session), - ck_session_get_seat (session) != NULL ? ck_seat_get_id (ck_session_get_seat (session)) : "(NONE)")); - - d = hal_device_store_find (hald_get_gdl (), "/org/freedesktop/Hal/devices/computer"); - if (d == NULL) { - d = hal_device_store_find (hald_get_tdl (), "/org/freedesktop/Hal/devices/computer"); - } - if (d == NULL) { - goto out; - } - - programs = hal_device_property_dup_strlist_as_strv (d, "info.callouts.session_remove"); - if (programs == NULL) { - goto out; - } - - extra_env[1] = g_strdup_printf ("HALD_SESSION_REMOVE_SESSION_ID=%s", ck_session_get_id (session)); - extra_env[2] = g_strdup_printf ("HALD_SESSION_REMOVE_SESSION_UID=%d", ck_session_get_user (session)); - extra_env[3] = g_strdup_printf ("HALD_SESSION_REMOVE_SESSION_IS_ACTIVE=%s", - ck_session_is_active (session) ? "true" : "false"); - - session_changes_push (d, programs, extra_env); - + hal_callout_device (d, + NULL /* callback */, + NULL /* userdata1 */, + NULL /* userdata2 */, + programs, + extra_env); g_free (extra_env[1]); g_free (extra_env[2]); g_free (extra_env[3]); diff -ur hal-0.5.11/hald/hald_dbus.h hal-0.5.11~git20080402/hald/hald_dbus.h --- hal-0.5.11/hald/hald_dbus.h 2008-05-08 00:23:29.000000000 +0100 +++ hal-0.5.11~git20080402/hald/hald_dbus.h 2008-03-14 19:57:37.000000000 +0000 @@ -32,8 +32,6 @@ DBusHandlerResult manager_get_all_devices (DBusConnection *connection, DBusMessage *message); -DBusHandlerResult manager_get_all_devices_with_properties (DBusConnection *connection, - DBusMessage *message); DBusHandlerResult manager_find_device_string_match (DBusConnection *connection, DBusMessage *message); DBusHandlerResult manager_find_device_by_capability (DBusConnection *connection, diff -ur hal-0.5.11/hald/hald.h hal-0.5.11~git20080402/hald/hald.h --- hal-0.5.11/hald/hald.h 2008-05-08 00:23:57.000000000 +0100 +++ hal-0.5.11~git20080402/hald/hald.h 2008-03-14 19:57:37.000000000 +0000 @@ -47,10 +47,8 @@ HalDeviceStore *hald_get_gdl (void); HalDeviceStore *hald_get_tdl (void); -void hald_compute_udi (gchar *dst, gsize dstsize, const gchar *format, ...); - -void property_atomic_update_begin (void); -void property_atomic_update_end (void); +void property_atomic_update_begin (); +void property_atomic_update_end (); extern dbus_bool_t hald_is_verbose; extern dbus_bool_t hald_use_syslog; diff -ur hal-0.5.11/hald/hald_marshal.c hal-0.5.11~git20080402/hald/hald_marshal.c --- hal-0.5.11/hald/hald_marshal.c 2008-05-08 00:36:15.000000000 +0100 +++ hal-0.5.11~git20080402/hald/hald_marshal.c 2008-04-02 17:50:23.000000000 +0100 @@ -163,46 +163,9 @@ data2); } -/* VOID:STRING,BOOL (hald_marshal.list:4) */ -void -hald_marshal_VOID__STRING_BOOLEAN (GClosure *closure, - GValue *return_value G_GNUC_UNUSED, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint G_GNUC_UNUSED, - gpointer marshal_data) -{ - typedef void (*GMarshalFunc_VOID__STRING_BOOLEAN) (gpointer data1, - gpointer arg_1, - gboolean arg_2, - gpointer data2); - register GMarshalFunc_VOID__STRING_BOOLEAN callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - g_return_if_fail (n_param_values == 3); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_VOID__STRING_BOOLEAN) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_string (param_values + 1), - g_marshal_value_peek_boolean (param_values + 2), - data2); -} - -/* VOID:STRING (hald_marshal.list:5) */ +/* VOID:STRING (hald_marshal.list:4) */ -/* VOID:OBJECT,BOOL (hald_marshal.list:6) */ +/* VOID:OBJECT,BOOL (hald_marshal.list:5) */ void hald_marshal_VOID__OBJECT_BOOLEAN (GClosure *closure, GValue *return_value G_GNUC_UNUSED, @@ -239,7 +202,7 @@ data2); } -/* VOID:OBJECT,STRING,BOOL,BOOL (hald_marshal.list:7) */ +/* VOID:OBJECT,STRING,BOOL,BOOL (hald_marshal.list:6) */ void hald_marshal_VOID__OBJECT_STRING_BOOLEAN_BOOLEAN (GClosure *closure, GValue *return_value G_GNUC_UNUSED, @@ -280,7 +243,7 @@ data2); } -/* VOID:OBJECT,STRING (hald_marshal.list:8) */ +/* VOID:OBJECT,STRING (hald_marshal.list:7) */ void hald_marshal_VOID__OBJECT_STRING (GClosure *closure, GValue *return_value G_GNUC_UNUSED, @@ -317,5 +280,5 @@ data2); } -/* VOID:VOID (hald_marshal.list:9) */ +/* VOID:VOID (hald_marshal.list:8) */ diff -ur hal-0.5.11/hald/hald_marshal.h hal-0.5.11~git20080402/hald/hald_marshal.h --- hal-0.5.11/hald/hald_marshal.h 2008-05-08 00:36:15.000000000 +0100 +++ hal-0.5.11~git20080402/hald/hald_marshal.h 2008-04-02 17:50:23.000000000 +0100 @@ -31,19 +31,10 @@ gpointer marshal_data); #define hald_marshal_VOID__STRING_BOOL_BOOL hald_marshal_VOID__STRING_BOOLEAN_BOOLEAN -/* VOID:STRING,BOOL (hald_marshal.list:4) */ -extern void hald_marshal_VOID__STRING_BOOLEAN (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); -#define hald_marshal_VOID__STRING_BOOL hald_marshal_VOID__STRING_BOOLEAN - -/* VOID:STRING (hald_marshal.list:5) */ +/* VOID:STRING (hald_marshal.list:4) */ #define hald_marshal_VOID__STRING g_cclosure_marshal_VOID__STRING -/* VOID:OBJECT,BOOL (hald_marshal.list:6) */ +/* VOID:OBJECT,BOOL (hald_marshal.list:5) */ extern void hald_marshal_VOID__OBJECT_BOOLEAN (GClosure *closure, GValue *return_value, guint n_param_values, @@ -52,7 +43,7 @@ gpointer marshal_data); #define hald_marshal_VOID__OBJECT_BOOL hald_marshal_VOID__OBJECT_BOOLEAN -/* VOID:OBJECT,STRING,BOOL,BOOL (hald_marshal.list:7) */ +/* VOID:OBJECT,STRING,BOOL,BOOL (hald_marshal.list:6) */ extern void hald_marshal_VOID__OBJECT_STRING_BOOLEAN_BOOLEAN (GClosure *closure, GValue *return_value, guint n_param_values, @@ -61,7 +52,7 @@ gpointer marshal_data); #define hald_marshal_VOID__OBJECT_STRING_BOOL_BOOL hald_marshal_VOID__OBJECT_STRING_BOOLEAN_BOOLEAN -/* VOID:OBJECT,STRING (hald_marshal.list:8) */ +/* VOID:OBJECT,STRING (hald_marshal.list:7) */ extern void hald_marshal_VOID__OBJECT_STRING (GClosure *closure, GValue *return_value, guint n_param_values, @@ -69,7 +60,7 @@ gpointer invocation_hint, gpointer marshal_data); -/* VOID:VOID (hald_marshal.list:9) */ +/* VOID:VOID (hald_marshal.list:8) */ #define hald_marshal_VOID__VOID g_cclosure_marshal_VOID__VOID G_END_DECLS diff -ur hal-0.5.11/hald/hald_runner.c hal-0.5.11~git20080402/hald/hald_runner.c --- hal-0.5.11/hald/hald_runner.c 2008-05-08 00:24:13.000000000 +0100 +++ hal-0.5.11~git20080402/hald/hald_runner.c 2008-03-14 19:57:37.000000000 +0000 @@ -451,7 +451,7 @@ add_env (iter, s, ck_session_is_active (session) ? "true" : "false"); g_free (s); s = g_strdup_printf ("CK_SESSION_UID_%s", session_id); - p = g_strdup_printf ("%u", ck_session_get_user (session)); + p = g_strdup_printf ("%d", ck_session_get_user (session)); add_env (iter, s, p); g_free (s); g_free (p); @@ -510,7 +510,7 @@ } #endif /* HAVE_CONKIT */ - if (uname (&un) >= 0) { + if (uname (&un) == 0) { char *sysname; sysname = g_ascii_strdown (un.sysname, -1); @@ -938,7 +938,7 @@ } void -hald_runner_kill_all (void) +hald_runner_kill_all () { DBusMessage *msg, *reply; DBusError err; diff -ur hal-0.5.11/hald/hald_runner.h hal-0.5.11~git20080402/hald/hald_runner.h --- hal-0.5.11/hald/hald_runner.h 2008-05-08 00:24:13.000000000 +0100 +++ hal-0.5.11~git20080402/hald/hald_runner.h 2007-11-05 21:45:35.000000000 +0000 @@ -92,7 +92,7 @@ gpointer data1, gpointer data2); void hald_runner_kill_device(HalDevice *device); -void hald_runner_kill_all(void); +void hald_runner_kill_all(); /* called by the core to tell the runner a device was finalized */ void runner_device_finalized (HalDevice *device); diff -ur hal-0.5.11/hald/ids.c hal-0.5.11~git20080402/hald/ids.c --- hal-0.5.11/hald/ids.c 2008-05-08 00:23:31.000000000 +0100 +++ hal-0.5.11~git20080402/hald/ids.c 2008-03-14 19:57:37.000000000 +0000 @@ -56,7 +56,7 @@ /** Initialize the pci.ids line iterator to the beginning of the file */ static void -pci_ids_line_iter_init (void) +pci_ids_line_iter_init () { pci_ids_iter_pos = 0; } @@ -103,7 +103,7 @@ * See if there are more lines to process in pci.ids */ static dbus_bool_t -pci_ids_line_iter_has_more (void) +pci_ids_line_iter_has_more () { return pci_ids_iter_pos < pci_ids_len; } @@ -339,7 +339,7 @@ /** Initialize the usb.ids line iterator to the beginning of the file */ static void -usb_ids_line_iter_init (void) +usb_ids_line_iter_init () { usb_ids_iter_pos = 0; } @@ -386,7 +386,7 @@ * See if there are more lines to process in usb.ids */ static dbus_bool_t -usb_ids_line_iter_has_more (void) +usb_ids_line_iter_has_more () { return usb_ids_iter_pos < usb_ids_len; } diff -ur hal-0.5.11/hald/linux/acpi.c hal-0.5.11~git20080402/hald/linux/acpi.c --- hal-0.5.11/hald/linux/acpi.c 2008-05-08 00:23:34.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/acpi.c 2008-03-14 19:57:37.000000000 +0000 @@ -54,7 +54,7 @@ ACPI_TYPE_BUTTON }; -#define ACPI_POLL_INTERVAL 30 /* in seconds */ +#define ACPI_POLL_INTERVAL 30000 typedef struct ACPIDevHandler_s { @@ -727,7 +727,7 @@ { HotplugEvent *hotplug_event; HAL_INFO (("Processing %s", fullpath)); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_ADD; hotplug_event->type = HOTPLUG_EVENT_ACPI; g_strlcpy (hotplug_event->acpi.acpi_path, fullpath, sizeof (hotplug_event->acpi.acpi_path)); @@ -855,7 +855,7 @@ if (!found) return; - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_ADD; hotplug_event->type = HOTPLUG_EVENT_ACPI; g_strlcpy (hotplug_event->acpi.acpi_path, path, sizeof (hotplug_event->acpi.acpi_path)); @@ -933,25 +933,13 @@ acpi_synthesize_sonypi_display (); /* setup timer for things that we need to poll */ -#ifdef HAVE_GLIB_2_14 - g_timeout_add_seconds (ACPI_POLL_INTERVAL, - acpi_poll, - NULL); -#else - g_timeout_add (1000 * ACPI_POLL_INTERVAL, + g_timeout_add (ACPI_POLL_INTERVAL, acpi_poll, NULL); -#endif - - /* setup timer for things that we need only to poll infrequently */ - - /* don't use g_timeout_add_seconds() here as the related code path - * is possibly CPU and time eating and we don't want have any - * other timeout synced with this one - */ - g_timeout_add (1000 * ACPI_POLL_INTERVAL * 120, - battery_poll_infrequently, - NULL); + /* setup timer for things that we need only to poll infrequently*/ + g_timeout_add ((ACPI_POLL_INTERVAL*120), + battery_poll_infrequently, + NULL); return TRUE; } @@ -960,19 +948,13 @@ acpi_generic_add (const gchar *acpi_path, HalDevice *parent, ACPIDevHandler *handler) { HalDevice *d; - - if (((handler->acpi_type == ACPI_TYPE_BATTERY) || (handler->acpi_type == ACPI_TYPE_AC_ADAPTER)) && _have_sysfs_power_supply) - return NULL; - d = hal_device_new (); hal_device_property_set_string (d, "linux.acpi_path", acpi_path); hal_device_property_set_int (d, "linux.acpi_type", handler->acpi_type); - if (parent != NULL) hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent)); else hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer"); - if (handler->refresh == NULL || !handler->refresh (d, handler, FALSE)) { g_object_unref (d); d = NULL; @@ -1006,10 +988,11 @@ acpi_generic_compute_udi (HalDevice *d, ACPIDevHandler *handler) { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/acpi_%s", - hal_util_get_last_element (hal_device_property_get_string (d, "linux.acpi_path"))); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/acpi_%s", + hal_util_get_last_element (hal_device_property_get_string (d, "linux.acpi_path"))); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -1270,7 +1253,7 @@ acpi_path = hal_device_property_get_string (d, "linux.acpi_path"); acpi_type = hal_device_property_get_int (d, "linux.acpi_type"); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_ADD; hotplug_event->type = HOTPLUG_EVENT_ACPI; g_strlcpy (hotplug_event->acpi.acpi_path, acpi_path, sizeof (hotplug_event->acpi.acpi_path)); @@ -1288,7 +1271,7 @@ acpi_path = hal_device_property_get_string (d, "linux.acpi_path"); acpi_type = hal_device_property_get_int (d, "linux.acpi_type"); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_REMOVE; hotplug_event->type = HOTPLUG_EVENT_ACPI; g_strlcpy (hotplug_event->acpi.acpi_path, acpi_path, sizeof (hotplug_event->acpi.acpi_path)); diff -ur hal-0.5.11/hald/linux/addons/addon-acpi.c hal-0.5.11~git20080402/hald/linux/addons/addon-acpi.c --- hal-0.5.11/hald/linux/addons/addon-acpi.c 2008-05-08 00:23:38.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/addons/addon-acpi.c 2008-03-14 19:57:37.000000000 +0000 @@ -193,44 +193,39 @@ snprintf (udi, sizeof (udi), "/org/freedesktop/Hal/devices/acpi_%s", acpi_name); -#ifdef BUILD_ACPI_IBM - if (strncmp (acpi_path, "ibm/hotkey", sizeof ("ibm/hotkey") -1) == 0) { - /* handle ibm ACPI hotkey events*/ - handle_ibm_acpi_events(ctx, acpi_num1, acpi_num2); - } else -#endif - - if (libhal_device_exists(ctx, udi, &error)) { + if (strncmp (acpi_path, "button", sizeof ("button") - 1) == 0) { + char *type; - if (strncmp (acpi_path, "button", sizeof ("button") - 1) == 0) { - char *type; + HAL_DEBUG (("button event")); - HAL_DEBUG (("button event")); + /* TODO: only rescan if button got state */ + if (libhal_device_rescan (ctx, udi, &error)) { + type = libhal_device_get_property_string(ctx, udi, + "button.type", + &error); + if (dbus_error_is_set (&error)) { + dbus_error_free (&error); + } - /* TODO: only rescan if button got state */ - if (libhal_device_rescan (ctx, udi, &error)) { - type = libhal_device_get_property_string(ctx, udi, - "button.type", - &error); - if (dbus_error_is_set (&error)) { - dbus_error_free (&error); - } - - if (type != NULL) { - libhal_device_emit_condition (ctx, udi, "ButtonPressed", - type, &error); - libhal_free_string(type); - } else { - libhal_device_emit_condition (ctx, udi, "ButtonPressed", "", &error); - } + if (type != NULL) { + libhal_device_emit_condition (ctx, udi, "ButtonPressed", + type, &error); + libhal_free_string(type); + } else { + libhal_device_emit_condition (ctx, udi, "ButtonPressed", "", &error); } - } else if (strncmp (acpi_path, "ac_adapter", sizeof ("ac_adapter") - 1) == 0) { - HAL_DEBUG (("ac_adapter event")); - libhal_device_rescan (ctx, udi, &error); - } else if (strncmp (acpi_path, "battery", sizeof ("battery") - 1) == 0) { - HAL_DEBUG (("battery event")); - libhal_device_rescan (ctx, udi, &error); } + } else if (strncmp (acpi_path, "ac_adapter", sizeof ("ac_adapter") - 1) == 0) { + HAL_DEBUG (("ac_adapter event")); + libhal_device_rescan (ctx, udi, &error); + } else if (strncmp (acpi_path, "battery", sizeof ("battery") - 1) == 0) { + HAL_DEBUG (("battery event")); + libhal_device_rescan (ctx, udi, &error); +#ifdef BUILD_ACPI_IBM + } else if (strncmp (acpi_path, "ibm/hotkey", sizeof ("ibm/hotkey") -1) == 0) { + /* handle ibm ACPI hotkey events*/ + handle_ibm_acpi_events(ctx, acpi_num1, acpi_num2); +#endif } } else { @@ -303,6 +298,8 @@ * sleep for 5s and try to reconnect (again). */ sleep (5); } + + return 1; } /* vim:set sw=8 noet: */ Only in hal-0.5.11~git20080402/hald/linux/addons: addon-als.c diff -ur hal-0.5.11/hald/linux/addons/addon-cpufreq.c hal-0.5.11~git20080402/hald/linux/addons/addon-cpufreq.c --- hal-0.5.11/hald/linux/addons/addon-cpufreq.c 2008-05-08 00:23:36.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/addons/addon-cpufreq.c 2008-03-14 19:57:37.000000000 +0000 @@ -49,22 +49,22 @@ #define CPUFREQ_ERROR_NO_SUITABLE_GOVERNOR "NoSuitableGovernor" #define CPUFREQ_ERROR_GOVERNOR_INIT_FAILED "GovernorInitFailed" -static const char SYSFS_GOVERNOR_FILE[] = +const char SYSFS_GOVERNOR_FILE[] = "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_governor"; -static const char SYSFS_AVAILABLE_GOVERNORS_FILE[] = +const char SYSFS_AVAILABLE_GOVERNORS_FILE[] = "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_available_governors"; -static const char ONDEMAND_UP_THRESHOLD_FILE[] = +const char ONDEMAND_UP_THRESHOLD_FILE[] = "/sys/devices/system/cpu/cpu%u/cpufreq/ondemand/up_threshold"; -static const char SYSFS_AFFECTED_CPUS_FILE[] = +const char SYSFS_AFFECTED_CPUS_FILE[] = "/sys/devices/system/cpu/cpu%u/cpufreq/affected_cpus"; -static const char SYSFS_CPU_ONLINE_FILE[] = +const char SYSFS_CPU_ONLINE_FILE[] = "/sys/devices/system/cpu/cpu%u/online"; -static const char ONDEMAND_IGNORE_NICE_LOAD_FILE[] = +const char ONDEMAND_IGNORE_NICE_LOAD_FILE[] = "/sys/devices/system/cpu/cpu%u/cpufreq/ondemand/ignore_nice_load"; static gboolean dbus_raise_error(DBusConnection *connection, DBusMessage *message, @@ -223,12 +223,11 @@ for (it = *list; it != NULL; it = g_slist_next(it)) { gboolean equal = TRUE; - GSList *list_it = NULL; - GSList *current_it = NULL; - if (current == it->data) continue; + GSList *list_it = NULL; + GSList *current_it = NULL; for (list_it = it->data, current_it = current; list_it != NULL && current_it != NULL; list_it = g_slist_next(list_it), current_it = g_slist_next(current_it)) { @@ -689,9 +688,9 @@ /** clear all previous cpufreq_objs */ if (g_slist_length(cpufreq_objs) > 0) { - GSList *iter = NULL; - for (iter = cpufreq_objs; iter != NULL; iter = g_slist_next(iter)) { - struct cpufreq_obj *obj = iter->data; + GSList *it = NULL; + for (it = cpufreq_objs; it != NULL; it = g_slist_next(it)) { + struct cpufreq_obj *obj = it->data; obj->free(obj->iface); free(obj->iface); free(obj); @@ -1102,11 +1101,6 @@ dbus_error_init(&dbus_error); - /* since we wait only for method calls with interface == DBUS_INTERFACE check - it and return if there are calls with other interfaces */ - if (!dbus_message_has_interface(message, DBUS_INTERFACE)) - return DBUS_HANDLER_RESULT_HANDLED; - #ifdef HAVE_POLKIT if (!dbus_is_privileged(connection, message, &dbus_error)) return DBUS_HANDLER_RESULT_HANDLED; @@ -1321,9 +1315,9 @@ sigaddset(&signal_action.sa_mask, SIGTERM); signal_action.sa_flags = SA_RESTART || SA_NOCLDSTOP; signal_action.sa_handler = exit_handler; - sigaction(SIGINT, &signal_action, NULL); - sigaction(SIGQUIT, &signal_action, NULL); - sigaction(SIGTERM, &signal_action, NULL); + sigaction(SIGINT, &signal_action, 0); + sigaction(SIGQUIT, &signal_action, 0); + sigaction(SIGTERM, &signal_action, 0); if (!is_supported()) { HAL_WARNING(("CPUFreq not supported. Exiting...")); diff -ur hal-0.5.11/hald/linux/addons/addon-cpufreq-userspace.c hal-0.5.11~git20080402/hald/linux/addons/addon-cpufreq-userspace.c --- hal-0.5.11/hald/linux/addons/addon-cpufreq-userspace.c 2008-05-08 00:23:36.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/addons/addon-cpufreq-userspace.c 2008-03-14 19:57:37.000000000 +0000 @@ -46,10 +46,10 @@ #define DEFAULT_CONSIDER_NICE FALSE #define PROC_STAT_FILE "/proc/stat" -static const char SYSFS_SCALING_SETSPEED_FILE[] = +const char SYSFS_SCALING_SETSPEED_FILE[] = "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_setspeed"; -static const char SYSFS_SCALING_AVAILABLE_FREQS_FILE[] = +const char SYSFS_SCALING_AVAILABLE_FREQS_FILE[] = "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_available_frequencies"; /* shortcut for g_array_index */ @@ -115,7 +115,7 @@ char line[256]; char cpu_string[7]; FILE *fp; - int new_num_cpus, i; + int new_num_cpus; new_num_cpus = sysconf(_SC_NPROCESSORS_CONF); if (new_num_cpus == -1 || new_num_cpus != cpuload.num_cpus) { @@ -141,9 +141,8 @@ /* start with the first line, "overall" cpu load */ /* if cpuload.num_cpus == 1, we do not need to evaluate "overall" and "per-cpu" load */ sprintf(cpu_string, "cpu "); - + int i; for (i = 0; i <= cpuload.num_cpus - (cpuload.num_cpus == 1); i++) { - unsigned long working_time; if (fgets(line,255,fp) == NULL) { HAL_WARNING(("%s too short (%s)", PROC_STAT_FILE, cpu_string)); @@ -167,6 +166,7 @@ return -1; } + unsigned long working_time; if (consider_nice) { working_time = user_time + system_time + nice_time; idle_time += iowait_time; @@ -353,6 +353,7 @@ { GSList *cpus = (GSList*)iface->cpus; GSList *it = NULL; + int ret = 0; int cpu_load = 0; for (it = cpus; it != NULL; it = g_slist_next(it)) { @@ -379,15 +380,19 @@ iface->current_speed = 0; HAL_DEBUG(("jumped to max (%d kHz)", g_a_i(iface->speeds_kHz, iface->current_speed))); + ret = 1; } } else if (cpu_load > config.up_threshold && iface->current_speed > 0) { iface->current_speed = increase_speed(iface); HAL_DEBUG(("increased to %d kHz", g_a_i(iface->speeds_kHz, iface->current_speed))); + ret = 1; } else if (cpu_load < (int)g_a_i(iface->demotion, iface->current_speed) && iface->current_speed < iface->last_step) { iface->current_speed = decrease_speed(iface); HAL_DEBUG(("decreased to %d kHz", g_a_i(iface->speeds_kHz, iface->current_speed))); + ret = -1; } else { + ret = 0; HAL_DEBUG(("Speed not changed")); } @@ -398,11 +403,10 @@ /* create the hysteresis array */ static void create_hysteresis_array(struct userspace_interface *iface) { - int i; - g_array_free(iface->demotion, TRUE); iface->demotion = g_array_new(TRUE, TRUE, sizeof(unsigned)); + int i; if (iface->last_step > 0) { for (i = 0; i < iface->last_step; i++) { int demotion = (config.up_threshold - HYSTERESIS) * diff -ur hal-0.5.11/hald/linux/addons/addon-dell-backlight.cpp hal-0.5.11~git20080402/hald/linux/addons/addon-dell-backlight.cpp --- hal-0.5.11/hald/linux/addons/addon-dell-backlight.cpp 2008-05-08 00:23:38.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/addons/addon-dell-backlight.cpp 2008-03-14 19:57:37.000000000 +0000 @@ -23,10 +23,7 @@ * **************************************************************************/ -#ifdef HAVE_CONFIG_H -# include -#endif - +#include #include #include @@ -181,30 +178,17 @@ DBusError err; DBusMessage *reply = NULL; dbus_bool_t AC; - char **udis; - int i, num_devices; - dbus_error_init (&err); if (!check_priv (connection, message, dbus_message_get_path (message), "org.freedesktop.hal.power-management.lcd-panel")) { return DBUS_HANDLER_RESULT_HANDLED; } - - /* set a default */ - AC = TRUE; + /* Mechanism to ensure that we always set the AC brightness when we are on AC-power etc. */ - if ((udis = libhal_find_device_by_capability(halctx, "ac_adapter", &num_devices, &err)) != NULL) { - for (i = 0; udis[i] != NULL; i++) { - if (dbus_error_is_set(&err)) - dbus_error_free (&err); - - if (libhal_device_property_exists (halctx, udis[i], "ac_adapter.present", &err)) { - AC = libhal_device_get_property_bool (halctx, udis[i], "ac_adapter.present", &err); - break; /* we found one AC device, leave the for-loop */ - } - } - libhal_free_string_array(udis); - } + AC = libhal_device_get_property_bool (halctx, + "/org/freedesktop/Hal/devices/acpi_AC", + "ac_adapter.present", + &err); if (dbus_message_is_method_call (message, "org.freedesktop.Hal.Device.LaptopPanel", @@ -213,9 +197,6 @@ HAL_DEBUG (("Received SetBrightness DBus call")); - if (dbus_error_is_set(&err)) - dbus_error_free (&err); - if (dbus_message_get_args (message, &err, DBUS_TYPE_INT32, &brightness, Only in hal-0.5.11/hald/linux/addons: addon-imac-backlight.c diff -ur hal-0.5.11/hald/linux/addons/addon-input.c hal-0.5.11~git20080402/hald/linux/addons/addon-input.c --- hal-0.5.11/hald/linux/addons/addon-input.c 2008-05-08 00:23:37.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/addons/addon-input.c 2008-03-14 19:57:37.000000000 +0000 @@ -210,7 +210,7 @@ GError *gerror = NULL; gsize read_bytes; - if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) + if (condition & (G_IO_HUP | G_IO_ERR)) return FALSE; /** tbh, we can probably assume every time we read we have a whole @@ -248,11 +248,6 @@ case SW_HEADPHONE_INSERT: name = "headphone_insert"; break; -#ifdef SW_RADIO - case SW_RADIO: - name = "radio"; - break; -#endif } if (name != NULL) { long bitmask[NBITS(SW_MAX)]; @@ -309,14 +304,19 @@ static void destroy_data (InputData *data) { - HAL_DEBUG (("Input device '%s' destroyed, free data.", data->udi)); + HAL_DEBUG (("Removing GIOChannel for'%s'", data->udi)); + + /* Null out the GIOChannel in the hash table, but + * leave the key in for DeviceRemoved + */ + g_hash_table_replace (inputs, g_strdup(data->udi), NULL); g_free (data); } static void -update_proc_title (void) +update_proc_title () { GList *lp; gchar *new_command_line, *p; @@ -383,7 +383,7 @@ g_hash_table_insert (inputs, g_strdup(udi), channel); g_io_add_watch_full (channel, - G_PRIORITY_DEFAULT, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, + G_PRIORITY_DEFAULT, G_IO_IN | G_IO_ERR | G_IO_HUP, event_io, data, (GDestroyNotify) destroy_data); } @@ -408,10 +408,8 @@ return; } - if (channel) { - g_io_channel_shutdown(channel, FALSE, NULL); + if (channel) g_io_channel_unref (channel); - } g_hash_table_remove (inputs, udi); @@ -445,7 +443,7 @@ hal_set_proc_title_init (argc, argv); - setup_logger (); + /* setup_logger (); */ dbus_error_init (&error); if ((ctx = libhal_ctx_init_direct (&error)) == NULL) { diff -ur hal-0.5.11/hald/linux/addons/addon-macbook-backlight.c hal-0.5.11~git20080402/hald/linux/addons/addon-macbook-backlight.c --- hal-0.5.11/hald/linux/addons/addon-macbook-backlight.c 2008-05-08 00:23:37.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/addons/addon-macbook-backlight.c 2008-03-14 19:57:37.000000000 +0000 @@ -48,20 +48,15 @@ * of the backlight when it is enabled. */ -#ifdef HAVE_CONFIG_H -# include -#endif - #include #include -#include #include -#include -#include #include +#include #include +#include #define DBUS_API_SUBJECT_TO_CHANGE @@ -77,8 +72,7 @@ #define ACCESS_OFFSET (REGISTER_OFFSET & PAGE_MASK) #define ACCESS_INDEX (ACCESS_OFFSET >> 2) -static unsigned int *register_page; -static LibHalContext *halctx = NULL; +unsigned int *register_page; static unsigned long determine_video_base_address (void) @@ -115,7 +109,7 @@ static gboolean map_register_page (void) { - unsigned long address; + long address; int fd; address = determine_video_base_address (); @@ -302,6 +296,7 @@ int main (int argc, char **argv) { + LibHalContext *halctx; DBusConnection *conn; GMainLoop *main_loop; const char *udi; diff -ur hal-0.5.11/hald/linux/addons/addon-macbookpro-backlight.c hal-0.5.11~git20080402/hald/linux/addons/addon-macbookpro-backlight.c --- hal-0.5.11/hald/linux/addons/addon-macbookpro-backlight.c 2008-05-08 00:23:35.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/addons/addon-macbookpro-backlight.c 2008-03-14 19:57:37.000000000 +0000 @@ -24,10 +24,7 @@ * **************************************************************************/ -#ifdef HAVE_CONFIG_H -# include -#endif - +#include #include #include #include @@ -480,9 +477,6 @@ size_t length = 0; int fd; int state; - struct pci_access *pacc; - struct pci_dev *dev; - DBusError err; setup_logger (); @@ -517,9 +511,10 @@ /* address = 0x90300000; */ /* length = 0x20000; */ - pacc = pci_alloc(); + struct pci_access *pacc = pci_alloc(); pci_init(pacc); pci_scan_bus(pacc); + struct pci_dev *dev; for(dev=pacc->devices; dev; dev=dev->next) { /* Iterate over all devices */ pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES); if ((dev->vendor_id == 0x1002) && (dev->device_id == 0x71c5)) { // ATI X1600 Only in hal-0.5.11~git20080402/hald/linux/addons: addon-mmc.c diff -ur hal-0.5.11/hald/linux/addons/addon-omap-backlight.c hal-0.5.11~git20080402/hald/linux/addons/addon-omap-backlight.c --- hal-0.5.11/hald/linux/addons/addon-omap-backlight.c 2008-05-08 00:23:38.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/addons/addon-omap-backlight.c 2008-03-14 19:57:37.000000000 +0000 @@ -25,10 +25,7 @@ * **************************************************************************/ -#ifdef HAVE_CONFIG_H -# include -#endif - +#include #include #include #include Only in hal-0.5.11~git20080402/hald/linux/addons: addon-omap-gpio.c diff -ur hal-0.5.11/hald/linux/addons/addon-storage.c hal-0.5.11~git20080402/hald/linux/addons/addon-storage.c --- hal-0.5.11/hald/linux/addons/addon-storage.c 2008-05-08 00:23:39.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/addons/addon-storage.c 2008-03-14 19:57:37.000000000 +0000 @@ -61,8 +61,6 @@ static gboolean system_is_idle = FALSE; static gboolean check_lock_state = TRUE; -static gboolean polling_disabled = FALSE; - static void force_unmount (LibHalContext *ctx, const char *udi) { @@ -279,7 +277,6 @@ }; static gboolean poll_for_media (gpointer user_data); -static gboolean poll_for_media_force (void); static int interval_in_seconds = 2; @@ -289,10 +286,7 @@ static void update_proc_title (void) { - - if (polling_disabled) { - hal_set_proc_title ("hald-addon-storage: no polling on %s because it is explicitly disabled", device_file); - } else if (is_locked_by_hal) { + if (is_locked_by_hal) { if (is_locked_via_o_excl) { hal_set_proc_title ("hald-addon-storage: no polling because %s is locked via HAL and O_EXCL", device_file); } else { @@ -333,12 +327,7 @@ if (poll_timer > 0) g_source_remove (poll_timer); - -#ifdef HAVE_GLIB_2_14 - poll_timer = g_timeout_add_seconds (interval_in_seconds, poll_for_media, NULL); -#else poll_timer = g_timeout_add (interval_in_seconds * 1000, poll_for_media, NULL); -#endif update_proc_title (); } @@ -346,9 +335,11 @@ static gboolean poll_for_media (gpointer user_data) { + int fd; + int got_media; + if (check_lock_state) { DBusError error; - dbus_bool_t should_poll; check_lock_state = FALSE; @@ -362,35 +353,16 @@ } else { HAL_INFO (("... device %s is not locked on HAL", device_file)); is_locked_by_hal = FALSE; + update_proc_title (); } - - dbus_error_init (&error); - should_poll = libhal_device_get_property_bool (ctx, udi, "storage.media_check_enabled", &error); - polling_disabled = !should_poll; - update_proc_title (); } /* TODO: we could remove the timeout completely... */ - if (is_locked_by_hal || polling_disabled) + if (is_locked_by_hal) goto skip_check; - - poll_for_media_force (); - -skip_check: - return TRUE; -} - -/* returns: whether the state changed */ -static gboolean -poll_for_media_force (void) -{ - int fd; - int got_media; - int old_media_status; - + got_media = FALSE; - - old_media_status = media_status; + if (is_cdrom) { int drive; @@ -566,75 +538,51 @@ /*HAL_DEBUG (("polling %s; got media=%d", device_file, got_media));*/ skip_check: - return old_media_status != media_status; + return TRUE; } #ifdef HAVE_CONKIT static gboolean get_system_idle_from_ck (void) { - gboolean ret; - DBusError error; - DBusMessage *message; - DBusMessage *reply; - - ret = FALSE; - - message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", - "/org/freedesktop/ConsoleKit/Manager", - "org.freedesktop.ConsoleKit.Manager", - "GetSystemIdleHint"); - dbus_error_init (&error); - reply = dbus_connection_send_with_reply_and_block (con, message, -1, &error); - if (reply == NULL || dbus_error_is_set (&error)) { - HAL_ERROR (("Error doing Manager.GetSystemIdleHint on ConsoleKit: %s: %s", error.name, error.message)); - dbus_message_unref (message); - if (reply != NULL) - dbus_message_unref (reply); - goto error; - } - if (!dbus_message_get_args (reply, NULL, - DBUS_TYPE_BOOLEAN, &(system_is_idle), - DBUS_TYPE_INVALID)) { - HAL_ERROR (("Invalid GetSystemIdleHint reply from CK")); - goto error; - } - dbus_message_unref (message); - dbus_message_unref (reply); + gboolean ret; + DBusError error; + DBusMessage *message; + DBusMessage *reply; - ret = TRUE; + ret = FALSE; + + message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", + "/org/freedesktop/ConsoleKit/Manager", + "org.freedesktop.ConsoleKit.Manager", + "GetSystemIdleHint"); + dbus_error_init (&error); + reply = dbus_connection_send_with_reply_and_block (con, message, -1, &error); + if (reply == NULL || dbus_error_is_set (&error)) { + HAL_ERROR (("Error doing Manager.GetSystemIdleHint on ConsoleKit: %s: %s", error.name, error.message)); + dbus_message_unref (message); + if (reply != NULL) + dbus_message_unref (reply); + goto error; + } + if (!dbus_message_get_args (reply, NULL, + DBUS_TYPE_BOOLEAN, &(system_is_idle), + DBUS_TYPE_INVALID)) { + HAL_ERROR (("Invalid GetSystemIdleHint reply from CK")); + goto error; + } + dbus_message_unref (message); + dbus_message_unref (reply); + + ret = TRUE; error: - return ret; + return ret; } #endif /* HAVE_CONKIT */ static DBusHandlerResult -direct_filter_function (DBusConnection *connection, DBusMessage *message, void *user_data) -{ - if (dbus_message_is_method_call (message, - "org.freedesktop.Hal.Device.Storage.Removable", - "CheckForMedia")) { - DBusMessage *reply; - dbus_bool_t call_had_sideeffect; - - HAL_INFO (("Forcing poll for media becusse CheckForMedia() was called")); - - call_had_sideeffect = poll_for_media_force (); - - reply = dbus_message_new_method_return (message); - dbus_message_append_args (reply, - DBUS_TYPE_BOOLEAN, &call_had_sideeffect, - DBUS_TYPE_INVALID); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - } - - return DBUS_HANDLER_RESULT_HANDLED; -} - -static DBusHandlerResult dbus_filter_function (DBusConnection *connection, DBusMessage *message, void *user_data) { #ifdef HAVE_CONKIT @@ -680,8 +628,6 @@ main (int argc, char *argv[]) { DBusError error; - LibHalContext *ctx_direct; - DBusConnection *con_direct; char *bus; char *drive_type; char *support_media_changed_str; @@ -722,21 +668,6 @@ dbus_connection_set_exit_on_disconnect (con, 0); dbus_error_init (&error); - if ((ctx_direct = libhal_ctx_init_direct (&error)) == NULL) { - HAL_ERROR (("Cannot connect to hald")); - goto out; - } - dbus_error_init (&error); - if (!libhal_device_addon_is_ready (ctx_direct, udi, &error)) { - goto out; - } - con_direct = libhal_ctx_get_dbus_connection (ctx_direct); - dbus_connection_setup_with_g_main (con_direct, NULL); - dbus_connection_set_exit_on_disconnect (con_direct, 0); - dbus_connection_add_filter (con_direct, direct_filter_function, NULL, NULL); - - - dbus_error_init (&error); if ((ctx = libhal_ctx_init_direct (&error)) == NULL) goto out; @@ -756,7 +687,6 @@ media_status = MEDIA_STATUS_UNKNOWN; - #ifdef HAVE_CONKIT /* TODO: ideally we should track the sessions on the seats on * which the device belongs to. But right now we don't really @@ -803,18 +733,6 @@ g_free (str); dbus_connection_add_filter (con, dbus_filter_function, NULL, NULL); - if (!libhal_device_claim_interface (ctx, - udi, - "org.freedesktop.Hal.Device.Storage.Removable", - " \n" - " \n" - " \n", - &error)) { - HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.Storage.Removable'")); - goto out; - } - - update_polling_interval (); g_main_loop_run (loop); Only in hal-0.5.11~git20080402/hald/linux/addons: addon-usb-cable.c diff -ur hal-0.5.11/hald/linux/addons/addon-usb-csr.c hal-0.5.11~git20080402/hald/linux/addons/addon-usb-csr.c --- hal-0.5.11/hald/linux/addons/addon-usb-csr.c 2008-05-08 00:23:38.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/addons/addon-usb-csr.c 2008-03-14 19:57:37.000000000 +0000 @@ -68,7 +68,7 @@ static const char *device_udi; /* prototypes */ -static struct usb_device *find_device (PropertyCacheItem *pci); +static struct usb_device *find_device (const char *hal_device_udi, PropertyCacheItem *pci); static PropertyCacheItem* property_cache_item_get (const char *hal_device_udi) @@ -129,7 +129,7 @@ HAL_DEBUG (("Is dual: %d", is_dual)); addr = is_dual? 1<<8 : 0; - curr_device = find_device (pci); + curr_device = find_device (hal_device_udi, pci); if (curr_device == NULL) { HAL_ERROR (("Device %s not found", hal_device_udi)); return; @@ -150,17 +150,13 @@ HAL_DEBUG (("Charge level: %d->%d", pci->current_charge, current_charge)); if (current_charge != pci->current_charge) { - pci->current_charge = current_charge; dbus_error_init (&err); + pci->current_charge = current_charge; dbus_error_init (&err); libhal_device_set_property_int (halctx, hal_device_udi, "battery.charge_level.current", current_charge, &err); - if (current_charge != 0) { + if (current_charge != 0) percentage = (100.0 / 7.0) * current_charge; - libhal_device_set_property_int (halctx, hal_device_udi, - "battery.charge_level.percentage", percentage, &err); - } else { - libhal_device_remove_property(halctx, hal_device_udi, - "battery.charge_level.percentage", &err); - } + libhal_device_set_property_int (halctx, hal_device_udi, + "battery.charge_level.percentage", percentage, &err); } } } else @@ -170,7 +166,7 @@ /* TODO: Is it linux-specific way to find the device? */ static struct usb_device* -find_device (PropertyCacheItem *pci) +find_device (const char *hal_device_udi, PropertyCacheItem *pci) { struct usb_bus* curr_bus; char LUdirname[5]; @@ -224,7 +220,7 @@ } static void -device_removed (const char *hal_device_udi) +device_removed (LibHalContext *ctx, const char *hal_device_udi) { /* this device is removed */ if (is_the_device (hal_device_udi)) { @@ -245,7 +241,7 @@ if (is_removed) { HAL_DEBUG (("** Main Property %s removed: %s", key, hal_device_udi)); /* probably we'll have to exit if this is our device */ - device_removed (hal_device_udi); + device_removed (ctx, hal_device_udi); } } else /* "Secondary" property modified */ @@ -330,11 +326,7 @@ "info.product", &err)); main_loop = g_main_loop_new (NULL, FALSE); -#ifdef HAVE_GLIB_2_14 - g_timeout_add_seconds (TIMEOUT, check_all_batteries, NULL); -#else g_timeout_add (1000L * TIMEOUT, check_all_batteries, NULL); -#endif g_main_loop_run (main_loop); libhal_ctx_shutdown (halctx, &err); diff -ur hal-0.5.11/hald/linux/apm.c hal-0.5.11~git20080402/hald/linux/apm.c --- hal-0.5.11/hald/linux/apm.c 2008-05-08 00:23:33.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/apm.c 2008-03-14 19:57:37.000000000 +0000 @@ -41,7 +41,7 @@ APM_TYPE_AC_ADAPTER }; -static int interval_poll_round = 0; +int interval_poll_round = 0; typedef struct APMDevHandler_s { @@ -64,7 +64,7 @@ int battery_time; } APMInfo; -#define APM_POLL_INTERVAL 2 /* in seconds */ +#define APM_POLL_INTERVAL 2000 static gboolean apm_poll (gpointer data) @@ -297,28 +297,22 @@ /* Set appropriate properties on the computer object */ hal_device_property_set_string (computer, "power_management.type", "apm"); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_ADD; hotplug_event->type = HOTPLUG_EVENT_APM; g_strlcpy (hotplug_event->apm.apm_path, "/proc/apm", sizeof (hotplug_event->apm.apm_path)); hotplug_event->apm.apm_type = APM_TYPE_BATTERY; hotplug_event_enqueue (hotplug_event); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->type = HOTPLUG_EVENT_APM; g_strlcpy (hotplug_event->apm.apm_path, "/proc/apm", sizeof (hotplug_event->apm.apm_path)); hotplug_event->apm.apm_type = APM_TYPE_AC_ADAPTER; hotplug_event_enqueue (hotplug_event); -#ifdef HAVE_GLIB_2_14 - g_timeout_add_seconds (APM_POLL_INTERVAL, - apm_poll, - NULL); -#else - g_timeout_add (1000 * APM_POLL_INTERVAL, + g_timeout_add (APM_POLL_INTERVAL, apm_poll, NULL); -#endif out: return ret; @@ -348,19 +342,20 @@ gchar udi[256]; if (handler->apm_type == APM_TYPE_BATTERY ) { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/apm_battery"); - + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/apm_battery"); + } else if (handler->apm_type == APM_TYPE_AC_ADAPTER ) { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/apm_ac_adapter"); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/apm_ac_adapter"); } else { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/apm_%d", - hal_device_property_get_int (d, "info.category")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/apm_%d", + hal_device_property_get_int (d, "info.category")); } hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -519,7 +514,7 @@ apm_path = hal_device_property_get_string (d, "linux.apm_path"); apm_type = hal_device_property_get_int (d, "linux.apm_type"); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_ADD; hotplug_event->type = HOTPLUG_EVENT_APM; g_strlcpy (hotplug_event->apm.apm_path, apm_path, sizeof (hotplug_event->apm.apm_path)); @@ -537,7 +532,7 @@ apm_path = hal_device_property_get_string (d, "linux.apm_path"); apm_type = hal_device_property_get_int (d, "linux.apm_type"); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_REMOVE; hotplug_event->type = HOTPLUG_EVENT_APM; g_strlcpy (hotplug_event->apm.apm_path, apm_path, sizeof (hotplug_event->apm.apm_path)); diff -ur hal-0.5.11/hald/linux/blockdev.c hal-0.5.11~git20080402/hald/linux/blockdev.c --- hal-0.5.11/hald/linux/blockdev.c 2008-05-08 00:23:41.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/blockdev.c 2008-03-14 19:57:37.000000000 +0000 @@ -77,57 +77,49 @@ uuid = hal_device_property_get_string (d, "volume.uuid"); if (uuid != NULL && strlen (uuid) > 0) { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/volume_uuid_%s", uuid); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/volume_uuid_%s", uuid); } else if (volumelabel != NULL && strlen (volumelabel) > 0) { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/volume_label_%s", volumelabel); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/volume_label_%s", volumelabel); } else if (hal_device_property_get_bool(d, "volume.is_disc") && hal_device_property_get_bool(d, "volume.disc.is_blank")) { /* this should be a empty CD/DVD */ - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/volume_empty_%s", - hal_device_property_get_string (d, "volume.disc.type")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/volume_empty_%s", + hal_device_property_get_string (d, "volume.disc.type")); } else { /* fallback to partition number, size */ - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/volume_part%d_size_%lld", - hal_device_property_get_int (d, "volume.partition.number"), - hal_device_property_get_uint64 (d, "volume.size")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/volume_part%d_size_%lld", + hal_device_property_get_int (d, "volume.partition.number"), + hal_device_property_get_uint64 (d, "volume.size")); } g_free(volumelabel); } else { const char *model; const char *serial; - const char *bus; - const char *type; model = hal_device_property_get_string (d, "storage.model"); serial = hal_device_property_get_string (d, "storage.serial"); - bus = hal_device_property_get_string (d, "storage.bus"); - type = hal_device_property_get_string (d, "storage.drive_type"); if (serial != NULL) { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/storage_serial_%s", - serial); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/storage_serial_%s", + serial); } else if ((model != NULL) && (strlen(model) != 0) ) { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/storage_model_%s", - model); - } else if ((bus != NULL) && (type != NULL)){ - hald_compute_udi (udi, sizeof (udi), - "%s_storage_%s_%s", - hal_device_property_get_string (d, "storage.originating_device"), - bus, type); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/storage_model_%s", + model); } else { - hald_compute_udi (udi, sizeof (udi), - "%s_storage", - hal_device_property_get_string (d, "storage.originating_device")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_storage", + hal_device_property_get_string (d, "storage.originating_device")); } } hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -360,7 +352,7 @@ snprintf (fake_sysfs_path, sizeof(fake_sysfs_path), "%s/fakevolume", sysfs_path); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_ADD; hotplug_event->type = HOTPLUG_EVENT_SYSFS_BLOCK; g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem)); @@ -742,11 +734,7 @@ } /* check again in two seconds */ -#ifdef HAVE_GLIB_2_14 - g_timeout_add_seconds (2, md_check_sync_timeout, g_strdup (sysfs_path)); -#else g_timeout_add (2000, md_check_sync_timeout, g_strdup (sysfs_path)); -#endif } } else hal_device_property_set_bool (d, "storage.linux_raid.is_syncing", FALSE); @@ -954,8 +942,6 @@ is_device_mapper = TRUE; } } - } else { - HAL_INFO(("Couldn't find slave volume in devices")); } } g_free (target); @@ -1009,6 +995,7 @@ hal_device_property_set_string (d, "info.product", "PC Floppy Drive"); hal_device_property_set_string (d, "storage.drive_type", "floppy"); hal_device_property_set_string (d, "storage.originating_device", hal_device_get_udi (parent)); + hal_device_property_set_string (d, "storage.physical_device", hal_device_get_udi (parent)); hal_device_property_set_bool (d, "storage.removable", TRUE); hal_device_property_set_bool (d, "storage.removable.media_available", FALSE); hal_device_property_set_bool (d, "storage.hotpluggable", FALSE); @@ -1180,15 +1167,17 @@ is_hotpluggable = TRUE; hal_device_property_set_string (d, "storage.bus", "mmc"); break; - } else if (strcmp (bus, "ccw") == 0) { + } else if (strcmp (bus, "mtd") == 0) { physdev = d_it; physdev_udi = udi_it; - is_hotpluggable = TRUE; - hal_device_property_set_string (d, "storage.bus", "ccw"); - } else if (strcmp (bus, "vio") == 0) { + hal_device_property_set_string (d, "storage.bus", "mtd"); + break; + } else if (strcmp (bus, "ccw") == 0) { physdev = d_it; physdev_udi = udi_it; - hal_device_property_set_string (d, "storage.bus", "vio"); + is_hotpluggable = TRUE; + hal_device_property_set_string + (d, "storage.bus", "ccw"); } } @@ -1203,6 +1192,7 @@ } hal_device_property_set_string (d, "storage.originating_device", physdev_udi); + hal_device_property_set_string (d, "storage.physical_device", physdev_udi); if (!hal_util_get_int_from_file (sysfs_path_real, "removable", (gint *) &is_removable, 10)) { HAL_WARNING (("Cannot get 'removable' file")); @@ -1323,24 +1313,6 @@ } else if (strcmp (parent_bus, "mmc") == 0) { hal_device_property_set_string (d, "storage.drive_type", "sd_mmc"); - } else if (strcmp (parent_bus, "vio") == 0) { - char buf[256]; - const gchar *prop; - - snprintf(buf, sizeof(buf), "%s/device", sysfs_path_real); - prop = hal_util_get_string_from_file (buf, "name"); - if (prop) { - if (strcmp (prop, "viocd") == 0) { - hal_device_property_set_string (d, "info.product", "Vio Virtual CD"); - hal_device_property_set_string (d, "storage.drive_type", "cdrom"); - } else if (strcmp (prop, "viodasd") == 0) { - hal_device_property_set_string (d, "info.product", "Vio Virtual Disk"); - hal_device_property_set_string (d, "storage.drive_type", "disk"); - } else if (strcmp (prop, "viotape") == 0) { - hal_device_property_set_string (d, "info.product", "Vio Virtual Tape"); - hal_device_property_set_string (d, "storage.drive_type", "tape"); - } - } } hal_device_property_set_string (d, "info.category", "storage"); @@ -1706,7 +1678,7 @@ serial = hal_device_property_get_string (d, "storage.serial"); revision = hal_device_property_get_string (d, "storage.firmware_revision"); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_ADD; hotplug_event->type = HOTPLUG_EVENT_SYSFS; g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem)); @@ -1731,7 +1703,7 @@ sysfs_path = hal_device_property_get_string (d, "linux.sysfs_path"); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_REMOVE; hotplug_event->type = HOTPLUG_EVENT_SYSFS; g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem)); @@ -1760,12 +1732,12 @@ if (!g_spawn_sync("/", (char **) argv, - NULL, /* envp */ - G_SPAWN_LEAVE_DESCRIPTORS_OPEN, /* flags */ - NULL, /* child_setup */ - NULL, /* user_data */ + NULL, /* envp */ + 0, /* flags */ + NULL, /* child_setup */ + NULL, /* user_data */ &u_stdout, - NULL, /* stderr */ + NULL, /* stderr */ &u_exit_status, &g_error)) { HAL_ERROR (("Error spawning udevinfo: %s", g_error->message)); @@ -1859,7 +1831,7 @@ } else { HAL_INFO (("Adding md device at '%s' ('%s')", sysfs_path, device_file)); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_ADD; hotplug_event->type = HOTPLUG_EVENT_SYSFS_BLOCK; g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem)); @@ -1912,7 +1884,7 @@ HAL_INFO (("Removing md device at '%s' ('%s')", sysfs_path, device_file)); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_REMOVE; hotplug_event->type = HOTPLUG_EVENT_SYSFS_BLOCK; g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem)); diff -ur hal-0.5.11/hald/linux/coldplug.c hal-0.5.11~git20080402/hald/linux/coldplug.c --- hal-0.5.11/hald/linux/coldplug.c 2008-05-08 00:23:32.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/coldplug.c 2008-03-14 19:57:37.000000000 +0000 @@ -55,110 +55,21 @@ static GHashTable *sysfs_to_udev_map; static GSList *device_list; static char dev_root[HAL_PATH_MAX]; -static gchar *udevinfo_stdout = NULL; - -typedef struct _UdevInfo UdevInfo; - -struct _UdevInfo -{ - const char *sysfs_path; - const char *device_file; - const char *vendor; - const char *model; - const char *revision; - const char *serial; - const char *fsusage; - const char *fstype; - const char *fsversion; - const char *fsuuid; - const char *fslabel; -}; - -static void udev_info_free (gpointer data) -{ - g_slice_free(UdevInfo, data); -} - - -static HotplugEvent* -udev_info_to_hotplug_event (const UdevInfo *info) -{ - HotplugEvent *hotplug_event; - gchar *str; - - hotplug_event = g_slice_new0 (HotplugEvent); - g_strlcpy (hotplug_event->sysfs.sysfs_path, "/sys", sizeof(hotplug_event->sysfs.sysfs_path)); - g_strlcat (hotplug_event->sysfs.sysfs_path, info->sysfs_path, sizeof(hotplug_event->sysfs.sysfs_path)); - - HAL_INFO(("creating HotplugEvent for %s", hotplug_event->sysfs.sysfs_path)); - - if (info->device_file) { - g_snprintf (hotplug_event->sysfs.device_file, sizeof(hotplug_event->sysfs.device_file), - "%s/%s", dev_root, info->device_file); - HAL_INFO(("with device file %s", hotplug_event->sysfs.device_file)); - } - if ((str = hal_util_strdup_valid_utf8(info->vendor)) != NULL) { - g_strlcpy (hotplug_event->sysfs.vendor, str, sizeof(hotplug_event->sysfs.vendor)); - g_free (str); - } - - if ((str = hal_util_strdup_valid_utf8(info->model)) != NULL) { - g_strlcpy (hotplug_event->sysfs.model, str, sizeof(hotplug_event->sysfs.model)); - g_free (str); - } - - if ((str = hal_util_strdup_valid_utf8(info->revision)) != NULL) { - g_strlcpy (hotplug_event->sysfs.revision, str, sizeof(hotplug_event->sysfs.revision)); - g_free (str); - } - - if ((str = hal_util_strdup_valid_utf8(info->serial)) != NULL) { - g_strlcpy (hotplug_event->sysfs.serial, str, sizeof(hotplug_event->sysfs.serial)); - g_free (str); - } - - if ((str = hal_util_strdup_valid_utf8(info->fsusage)) != NULL) { - g_strlcpy (hotplug_event->sysfs.fsusage, str, sizeof(hotplug_event->sysfs.fsusage)); - g_free (str); - } - - if ((str = hal_util_strdup_valid_utf8(info->fstype)) != NULL) { - g_strlcpy (hotplug_event->sysfs.fstype, str, sizeof(hotplug_event->sysfs.fstype)); - g_free (str); - } - - if ((str = hal_util_strdup_valid_utf8(info->fsversion)) != NULL) { - g_strlcpy (hotplug_event->sysfs.fsversion, str, sizeof(hotplug_event->sysfs.fsversion)); - g_free (str); - } - - if ((str = hal_util_strdup_valid_utf8(info->fsuuid)) != NULL) { - g_strlcpy (hotplug_event->sysfs.fsuuid, str, sizeof(hotplug_event->sysfs.fsuuid)); - g_free (str); - } - - if ((str = hal_util_strdup_valid_utf8(info->fslabel)) != NULL) { - g_strlcpy (hotplug_event->sysfs.fslabel, str, sizeof(hotplug_event->sysfs.fslabel)); - g_free (str); - } - - return hotplug_event; -} - static gboolean hal_util_init_sysfs_to_udev_map (void) { char *udevdb_export_argv[] = { "/usr/bin/udevinfo", "-e", NULL }; char *udevroot_argv[] = { "/usr/bin/udevinfo", "-r", NULL }; + char *udevinfo_stdout; int udevinfo_exitcode; - UdevInfo *info = NULL; + HotplugEvent *hotplug_event = NULL; char *p; - sysfs_to_udev_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, udev_info_free); + sysfs_to_udev_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); /* get udevroot */ - if (g_spawn_sync ("/", udevroot_argv, NULL, G_SPAWN_LEAVE_DESCRIPTORS_OPEN, NULL, NULL, + if (g_spawn_sync ("/", udevroot_argv, NULL, 0, NULL, NULL, &udevinfo_stdout, NULL, &udevinfo_exitcode, @@ -179,7 +90,7 @@ HAL_INFO (("dev_root is %s", dev_root)); /* get udevdb export */ - if (g_spawn_sync ("/", udevdb_export_argv, NULL, G_SPAWN_LEAVE_DESCRIPTORS_OPEN, NULL, NULL, + if (g_spawn_sync ("/", udevdb_export_argv, NULL, 0, NULL, NULL, &udevinfo_stdout, NULL, &udevinfo_exitcode, @@ -198,6 +109,7 @@ p = udevinfo_stdout; while (p[0] != '\0') { char *line, *end; + gchar *str; /* get line, terminate and move to next line */ line = p; @@ -209,49 +121,79 @@ /* insert device */ if (line[0] == '\0') { - if (info != NULL) { - g_hash_table_insert (sysfs_to_udev_map, g_strdup_printf ("/sys%s", info->sysfs_path), info); - HAL_INFO (("found (udevdb export) '/sys%s' -> '%s/%s'", - info->sysfs_path, dev_root, info->device_file)); - info = NULL; + if (hotplug_event != NULL) { + g_hash_table_insert (sysfs_to_udev_map, g_strdup (hotplug_event->sysfs.sysfs_path), hotplug_event); + HAL_INFO (("found (udevdb export) '%s' -> '%s'", + hotplug_event->sysfs.sysfs_path, hotplug_event->sysfs.device_file)); + hotplug_event = NULL; } continue; } /* new device */ if (strncmp(line, "P: ", 3) == 0) { - info = g_slice_new0 (UdevInfo); - info->sysfs_path = &line[3]; + hotplug_event = g_new0 (HotplugEvent, 1); + g_strlcpy (hotplug_event->sysfs.sysfs_path, "/sys", sizeof(hotplug_event->sysfs.sysfs_path)); + g_strlcat (hotplug_event->sysfs.sysfs_path, &line[3], sizeof(hotplug_event->sysfs.sysfs_path)); continue; } /* only valid if we have an actual device */ - if (info == NULL) + if (hotplug_event == NULL) continue; if (strncmp(line, "N: ", 3) == 0) { - info->device_file = &line[3]; + g_snprintf (hotplug_event->sysfs.device_file, sizeof(hotplug_event->sysfs.device_file), + "%s/%s", dev_root, &line[3]); } else if (strncmp(line, "E: ID_VENDOR=", 13) == 0) { - info->vendor = &line[13]; + if ((str = hal_util_strdup_valid_utf8(&line[13])) != NULL) { + g_strlcpy (hotplug_event->sysfs.vendor, str, sizeof(hotplug_event->sysfs.vendor)); + g_free (str); + } } else if (strncmp(line, "E: ID_MODEL=", 12) == 0) { - info->model = &line[12]; + if ((str = hal_util_strdup_valid_utf8(&line[12])) != NULL) { + g_strlcpy (hotplug_event->sysfs.model, str, sizeof(hotplug_event->sysfs.model)); + g_free (str); + } } else if (strncmp(line, "E: ID_REVISION=", 15) == 0) { - info->revision = &line[15]; + if ((str = hal_util_strdup_valid_utf8(&line[15])) != NULL) { + g_strlcpy (hotplug_event->sysfs.revision, str, sizeof(hotplug_event->sysfs.revision)); + g_free (str); + } } else if (strncmp(line, "E: ID_SERIAL=", 13) == 0) { - info->serial = &line[13]; + if ((str = hal_util_strdup_valid_utf8(&line[13])) != NULL) { + g_strlcpy (hotplug_event->sysfs.serial, str, sizeof(hotplug_event->sysfs.serial)); + g_free (str); + } } else if (strncmp(line, "E: ID_FS_USAGE=", 15) == 0) { - info->fsusage = &line[15]; + if ((str = hal_util_strdup_valid_utf8(&line[15])) != NULL) { + g_strlcpy (hotplug_event->sysfs.fsusage, str, sizeof(hotplug_event->sysfs.fsusage)); + g_free (str); + } } else if (strncmp(line, "E: ID_FS_TYPE=", 14) == 0) { - info->fstype = &line[14]; + if ((str = hal_util_strdup_valid_utf8(&line[14])) != NULL) { + g_strlcpy (hotplug_event->sysfs.fstype, str, sizeof(hotplug_event->sysfs.fstype)); + g_free (str); + } } else if (strncmp(line, "E: ID_FS_VERSION=", 17) == 0) { - info->fsversion = &line[17]; + if ((str = hal_util_strdup_valid_utf8(&line[17])) != NULL) { + g_strlcpy (hotplug_event->sysfs.fsversion, str, sizeof(hotplug_event->sysfs.fsversion)); + g_free (str); + } } else if (strncmp(line, "E: ID_FS_UUID=", 14) == 0) { - info->fsuuid = &line[14]; + if ((str = hal_util_strdup_valid_utf8(&line[14])) != NULL) { + g_strlcpy (hotplug_event->sysfs.fsuuid, str, sizeof(hotplug_event->sysfs.fsuuid)); + g_free (str); + } } else if (strncmp(line, "E: ID_FS_LABEL=", 15) == 0) { - info->fslabel = &line[15]; + if ((str = hal_util_strdup_valid_utf8(&line[15])) != NULL) { + g_strlcpy (hotplug_event->sysfs.fslabel, str, sizeof(hotplug_event->sysfs.fslabel)); + g_free (str); + } } } + g_free(udevinfo_stdout); return TRUE; error: @@ -261,23 +203,55 @@ return FALSE; } +static HotplugEvent *pool = NULL; +static int pool_next_free = 0; +static int pool_num_freed = 0; +static int pool_size = 1000; + +static void +pool_free (gpointer data) +{ + HAL_INFO (("pool_num_freed = %d (of %d)", pool_num_freed, pool_next_free)); + pool_num_freed++; + if (pool_num_freed == pool_next_free) { + HAL_INFO (("Freeing whole pool")); + g_free (pool); + } +} + static HotplugEvent *coldplug_get_hotplug_event(const gchar *sysfs_path, const gchar *subsystem, HotplugEventType type) { - HotplugEvent *hotplug_event; + HotplugEvent *hotplug_event, *hotplug_event_udev; const char *pos; gchar path[HAL_PATH_MAX]; struct stat statbuf; - UdevInfo *info; + gboolean from_pool = FALSE; + + /* TODO: FIXME: this is experimental code */ + if (pool == NULL) { + pool = g_new0 (HotplugEvent, pool_size); + pool_next_free = 0; + pool_num_freed = 0; + } + + if (pool_next_free >= pool_size) { + hotplug_event = g_new0 (HotplugEvent, 1); + } else { + from_pool = TRUE; + hotplug_event = pool + pool_next_free++; + hotplug_event->free_function = pool_free; + } /* lookup if udev has something stored in its database */ - info = (UdevInfo*) g_hash_table_lookup (sysfs_to_udev_map, sysfs_path); - if (info) { - hotplug_event = udev_info_to_hotplug_event (info); + hotplug_event_udev = (HotplugEvent *) g_hash_table_lookup (sysfs_to_udev_map, sysfs_path); + if (hotplug_event_udev != NULL) { + memcpy(hotplug_event, hotplug_event_udev, sizeof(HotplugEvent)); + if (from_pool) { + hotplug_event->free_function = pool_free; + } HAL_INFO (("new event (dev node from udev) '%s' '%s'", hotplug_event->sysfs.sysfs_path, hotplug_event->sysfs.device_file)); } else { - hotplug_event = g_slice_new0 (HotplugEvent); - /* device is not in udev database */ g_strlcpy(hotplug_event->sysfs.sysfs_path, sysfs_path, sizeof(hotplug_event->sysfs.sysfs_path)); @@ -327,7 +301,7 @@ if (!(statbuf.st_mode & S_IWUSR)) goto error; - sysfs_dev = g_slice_new0 (struct sysfs_device); + sysfs_dev = g_new0 (struct sysfs_device, 1); if (sysfs_dev == NULL) goto error; @@ -352,11 +326,11 @@ sysfs_dev->path = g_strdup (path); found: sysfs_dev->subsystem = g_strdup (subsystem); - device_list = g_slist_append (device_list, sysfs_dev); + device_list = g_slist_prepend (device_list, sysfs_dev); return 0; error: - g_slice_free (struct sysfs_device, sysfs_dev); + g_free (sysfs_dev); return -1; } @@ -522,7 +496,7 @@ } } -static void process_coldplug_events(void) +static void queue_events(void) { GSList *dev; @@ -535,11 +509,10 @@ sysfs_dev->subsystem, sysfs_dev->type); hotplug_event_enqueue (hotplug_event); - hotplug_event_process_queue(); g_free (sysfs_dev->path); g_free (sysfs_dev->subsystem); - g_slice_free (struct sysfs_device, sysfs_dev); + g_free (sysfs_dev); } g_slist_free (device_list); @@ -574,22 +547,23 @@ if (stat("/sys/subsystem", &statbuf) == 0) { scan_subsystem ("subsystem"); device_list = g_slist_sort (device_list, _device_order); - process_coldplug_events (); + queue_events (); } else { scan_subsystem ("bus"); device_list = g_slist_sort (device_list, _device_order); - process_coldplug_events (); + queue_events (); scan_class (); + scan_single_bus ("mmc"); scan_single_bus ("bluetooth"); device_list = g_slist_sort (device_list, _device_order); - process_coldplug_events (); + queue_events (); /* scan /sys/block, if it isn't already a class */ if (stat("/sys/class/block", &statbuf) != 0) { scan_block (); device_list = g_slist_sort (device_list, _device_order); - process_coldplug_events (); + queue_events (); } /* add events from reading /proc/mdstat */ @@ -597,7 +571,6 @@ } g_hash_table_destroy (sysfs_to_udev_map); - g_free (udevinfo_stdout); return TRUE; error: diff -ur hal-0.5.11/hald/linux/device.c hal-0.5.11~git20080402/hald/linux/device.c --- hal-0.5.11/hald/linux/device.c 2008-05-08 00:23:42.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/device.c 2008-03-14 19:57:37.000000000 +0000 @@ -72,10 +72,6 @@ gboolean _have_sysfs_lid_button = FALSE; gboolean _have_sysfs_power_button = FALSE; gboolean _have_sysfs_sleep_button = FALSE; -gboolean _have_sysfs_power_supply = FALSE; - -#define POWER_SUPPLY_BATTERY_POLL_INTERVAL 30 /* in seconds */ -#define DOCK_STATION_UNDOCK_POLL_INTERVAL 300 /* in milliseconds */ /* we must use this kernel-compatible implementation */ #define BITS_PER_LONG (sizeof(long) * 8) @@ -243,10 +239,6 @@ hal_device_property_set_string (d, "button.type", "tablet_mode"); } else if (test_bit (SW_HEADPHONE_INSERT, bitmask)) { hal_device_property_set_string (d, "button.type", "headphone_insert"); -#ifdef SW_RADIO - } else if (test_bit (SW_RADIO, bitmask)) { - hal_device_property_set_string (d, "button.type", "radio"); -#endif } } @@ -266,18 +258,9 @@ goto out; num_bits = input_str_to_bitmask (s, bitmask, sizeof (bitmask)); - if (test_bit (ABS_X, bitmask) && test_bit (ABS_Y, bitmask)) { - if (test_bit (ABS_PRESSURE, bitmask)) { - hal_device_add_capability (d, "input.touchpad"); - goto out; - } else { - /* - * This path is taken by VMware's USB mouse, which has - * absolute axes, but no touch/pressure button. - */ - hal_device_add_capability (d, "input.mouse"); - goto out; - } + if (test_bit (ABS_X, bitmask) && test_bit (ABS_Y, bitmask) && test_bit (ABS_PRESSURE, bitmask)) { + hal_device_add_capability (d, "input.touchpad"); + goto out; } /* TODO: Hmm; this code looks sketchy... why do we do !test_bit on the Y axis ?? */ @@ -338,6 +321,7 @@ hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); if (parent_dev != NULL) { hal_device_property_set_string (d, "input.originating_device", hal_device_get_udi (parent_dev)); + hal_device_property_set_string (d, "input.physical_device", hal_device_get_udi (parent_dev)); hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); } else { hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer"); @@ -391,10 +375,11 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "%s_logicaldev_input", - hal_device_property_get_string (d, "info.parent")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_logicaldev_input", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -470,20 +455,21 @@ gchar udi[256]; if (hal_device_has_capability (d, "bluetooth_acl")) { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/bluetooth_acl_%0llx", - hal_device_property_get_uint64 (d, "bluetooth_acl.address")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/bluetooth_acl_%0llx", + hal_device_property_get_uint64 (d, "bluetooth_acl.address")); } else if (hal_device_has_capability (d, "bluetooth_sco")) { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/bluetooth_acl_%0llx", - hal_device_property_get_uint64 (d, "bluetooth_acl.address")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/bluetooth_acl_%0llx", + hal_device_property_get_uint64 (d, "bluetooth_acl.address")); } else { - hald_compute_udi (udi, sizeof (udi), - "%s_bluetooth_hci_%0llx", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_uint64 (d, "bluetooth_hci.address")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_bluetooth_hci_%0llx", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_uint64 (d, "bluetooth_hci.address")); } hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -510,6 +496,7 @@ hal_device_add_capability (d, "net"); hal_device_property_set_string (d, "net.originating_device", hal_device_get_udi (parent_dev)); + hal_device_property_set_string (d, "net.physical_device", hal_device_get_udi (parent_dev)); ifname = hal_util_get_last_element (sysfs_path); hal_device_property_set_string (d, "net.interface", ifname); @@ -531,7 +518,6 @@ if (media_type == ARPHRD_ETHER) { const char *addr; const char *parent_subsys; - char bridge_path[HAL_PATH_MAX]; char wireless_path[HAL_PATH_MAX]; char wiphy_path[HAL_PATH_MAX]; struct stat s; @@ -553,11 +539,10 @@ } } - snprintf (bridge_path, HAL_PATH_MAX, "%s/bridge", sysfs_path); snprintf (wireless_path, HAL_PATH_MAX, "%s/wireless", sysfs_path); /* wireless dscape stack e.g. from rt2500pci driver*/ snprintf (wiphy_path, HAL_PATH_MAX, "%s/wiphy", sysfs_path); - parent_subsys = hal_device_property_get_string (parent_dev, "info.subsystem"); + parent_subsys = hal_device_property_get_string (parent_dev, "linux.subsystem"); if (parent_subsys && strcmp(parent_subsys, "bluetooth") == 0) { hal_device_property_set_string (d, "info.product", "Bluetooth Interface"); @@ -570,11 +555,6 @@ hal_device_property_set_string (d, "info.category", "net.80211"); hal_device_add_capability (d, "net.80211"); hal_device_property_set_uint64 (d, "net.80211.mac_address", mac_address); - } else if (stat (bridge_path, &s) == 0 && (s.st_mode & S_IFDIR)) { - hal_device_property_set_string (d, "info.product", "Bridge Interface"); - hal_device_property_set_string (d, "info.category", "net.bridge"); - hal_device_add_capability (d, "net.bridge"); - hal_device_property_set_uint64 (d, "net.bridge.mac_address", mac_address); } else { hal_device_property_set_string (d, "info.product", "Networking Interface"); hal_device_property_set_string (d, "info.category", "net.80203"); @@ -649,10 +629,11 @@ /* Need to fall back to something else if mac not available. */ id = hal_util_get_last_element(hal_device_property_get_string(d, "net.originating_device")); } - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/net_%s", - id); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/net_%s", + id); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -685,10 +666,11 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "%s_scsi_generic", - hal_device_property_get_string (d, "info.parent")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_scsi_generic", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -750,7 +732,7 @@ /* fake host event */ rc = TRUE; - host_event = g_slice_new0 (HotplugEvent); + host_event = g_new0 (HotplugEvent, 1); host_event->action = action; host_event->type = HOTPLUG_EVENT_SYSFS_DEVICE; g_strlcpy (host_event->sysfs.subsystem, "scsi_host", sizeof (host_event->sysfs.subsystem)); @@ -781,6 +763,10 @@ d = NULL; + if (parent_dev == NULL || parent_path == NULL) { + goto out; + } + /* ignore useless class device */ if (strstr(sysfs_path, "class/scsi_host") != NULL) goto out; @@ -792,10 +778,7 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); hal_device_property_set_int (d, "scsi_host.host", host_num); - if (parent_dev != NULL) - hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); - else - hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer"); + hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); hal_device_property_set_string (d, "info.category", "scsi_host"); hal_device_add_capability (d, "scsi_host"); hal_device_property_set_string (d, "info.product", "SCSI Host Adapter"); @@ -808,10 +791,11 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "%s_scsi_host", - hal_device_property_get_string (d, "info.parent")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_scsi_host", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -856,6 +840,7 @@ hal_device_property_set_string (d, "printer.device", device_file); hal_device_property_set_string (d, "printer.originating_device", hal_device_get_udi (parent_dev)); + hal_device_property_set_string (d, "printer.physical_device", hal_device_get_udi (parent_dev)); } out: @@ -879,19 +864,21 @@ gchar udi[256]; if (hal_device_has_capability (d, "hiddev")) { - hald_compute_udi (udi, sizeof (udi), - "%s_hiddev", - hal_device_property_get_string (d, "info.parent")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_hiddev", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); } else if (hal_device_has_capability (d, "printer")) { const char *serial; serial = hal_device_property_get_string (d, "printer.serial"); - hald_compute_udi (udi, sizeof (udi), - "%s_printer_%s", - hal_device_property_get_string (d, "info.parent"), - serial != NULL ? serial : "noserial"); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_printer_%s", + hal_device_property_get_string (d, "info.parent"), + serial != NULL ? serial : "noserial"); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); } return TRUE; @@ -926,9 +913,10 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), "%s_usbraw", - hal_device_property_get_string (d, "info.parent")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_usbraw", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -976,9 +964,10 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), "%s_video4linux", - hal_device_property_get_string (d, "info.parent")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_video4linux", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -1013,9 +1002,10 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), "%s_dvb", - hal_device_property_get_string (d, "info.parent")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_dvb", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -1068,6 +1058,7 @@ hal_device_property_set_string (d, "info.category", "sound"); hal_device_add_capability (d, "sound"); hal_device_property_set_string (d, "sound.originating_device", hal_device_get_udi (parent_dev)); + hal_device_property_set_string (d, "sound.physical_device", hal_device_get_udi (parent_dev)); hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); if (sscanf (device, "card%d", &cardnum) == 1) { @@ -1114,6 +1105,7 @@ hal_device_property_set_string (d, "alsa.device_file", device_file); hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); hal_device_property_set_string (d, "alsa.originating_device", hal_device_get_udi (parent_dev)); + hal_device_property_set_string (d, "alsa.physical_device", hal_device_get_udi (parent_dev)); hal_device_property_set_int (d, "alsa.card", cardnum); hal_device_property_set_string (d, "alsa.type", "control"); @@ -1130,6 +1122,7 @@ hal_device_property_set_string (d, "alsa.device_file", device_file); hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); hal_device_property_set_string (d, "alsa.originating_device", hal_device_get_udi (parent_dev)); + hal_device_property_set_string (d, "alsa.physical_device", hal_device_get_udi (parent_dev)); hal_device_property_set_int (d, "alsa.card", cardnum); hal_device_property_set_int (d, "alsa.device", devicenum); @@ -1175,6 +1168,7 @@ hal_device_property_set_string (d, "alsa.device_file", device_file); hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); hal_device_property_set_string (d, "alsa.originating_device", hal_device_get_udi (parent_dev)); + hal_device_property_set_string (d, "alsa.physical_device", hal_device_get_udi (parent_dev)); hal_device_property_set_int (d, "alsa.card", cardnum); hal_device_property_set_int (d, "alsa.device", devicenum); @@ -1224,6 +1218,7 @@ hal_device_property_set_string (d, "oss.device_file", device_file); hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); hal_device_property_set_string (d, "oss.originating_device", hal_device_get_udi (parent_dev)); + hal_device_property_set_string (d, "oss.physical_device", hal_device_get_udi (parent_dev)); hal_device_property_set_int (d, "oss.card", cardnum); asound_card_id_set (cardnum, d, "oss.card_id"); @@ -1303,42 +1298,43 @@ if (hal_device_has_property(d, "sound.card")) { /* don't include card number as it may not be persistent across reboots */ - hald_compute_udi (udi, sizeof (udi), - "%s_sound_card_%i", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "sound.card")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_sound_card_%i", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "sound.card")); } else if (hal_device_has_property(d, "alsa.card")) { /* don't include card number as it may not be persistent across reboots */ - hald_compute_udi (udi, sizeof (udi), - "%s_alsa_%s_%i", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "alsa.type"), - hal_device_property_get_int (d, "alsa.device")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_alsa_%s_%i", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "alsa.type"), + hal_device_property_get_int (d, "alsa.device")); } else if (hal_device_has_property(d, "oss.card")) { /* don't include card number as it may not be persistent across reboots */ - hald_compute_udi (udi, sizeof (udi), - "%s_oss_%s_%i", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "oss.type"), - hal_device_property_get_int (d, "oss.device")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_oss_%s_%i", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "oss.type"), + hal_device_property_get_int (d, "oss.device")); } else if (hal_device_has_property(d, "alsa.type")) { /* handle global ALSA devices */ - hald_compute_udi (udi, sizeof (udi), - "%s_alsa_%s", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "alsa.type")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_alsa_%s", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "alsa.type")); } else if (hal_device_has_property(d, "oss.type")) { /* handle global OSS devices */ - hald_compute_udi (udi, sizeof (udi), - "%s_oss_%s", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "oss.type")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_oss_%s", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "oss.type")); } else { /* fallback */ - hald_compute_udi (udi, sizeof (udi), "%s_sound_unknown", - hal_device_property_get_string (d, "info.parent")); - } + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_sound_unknown", + hal_device_property_get_string (d, "info.parent")); + } hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -1364,6 +1360,7 @@ hal_device_property_set_string (d, "info.category", "serial"); hal_device_add_capability (d, "serial"); hal_device_property_set_string (d, "serial.originating_device", hal_device_get_udi (parent_dev)); + hal_device_property_set_string (d, "serial.physical_device", hal_device_get_udi (parent_dev)); hal_device_property_set_string (d, "serial.device", device_file); last_elem = hal_util_get_last_element(sysfs_path); @@ -1427,12 +1424,13 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "%s_serial_%s_%d", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "serial.type"), - hal_device_property_get_int (d, "serial.port")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_serial_%s_%d", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "serial.type"), + hal_device_property_get_int (d, "serial.port")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -1478,10 +1476,11 @@ (d, "linux.sysfs_path")); if (!sysfs_name) return FALSE; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/tape_%s", - sysfs_name); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/tape_%s", + sysfs_name); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -1515,6 +1514,8 @@ sscanf (last_elem, "mmc%d", &host_num); hal_device_property_set_int (d, "mmc_host.host", host_num); + hal_util_set_string_from_file (d, "mmc_host.slot_name", sysfs_path, "slot_name"); + out: return d; } @@ -1524,10 +1525,11 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "%s_mmc_host", - hal_device_property_get_string (d, "info.parent")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_mmc_host", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -1541,6 +1543,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "pci"); + hal_device_property_set_string (d, "info.bus", "pci"); if (parent_dev != NULL) { hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); } else { @@ -1613,11 +1617,12 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pci_%x_%x", - hal_device_property_get_int (d, "pci.vendor_id"), - hal_device_property_get_int (d, "pci.product_id")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pci_%x_%x", + hal_device_property_get_int (d, "pci.vendor_id"), + hal_device_property_get_int (d, "pci.product_id")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -1704,8 +1709,10 @@ bus_id = hal_util_get_last_element (sysfs_path); if (strchr (bus_id, ':') == NULL) { gint bmAttributes; + char *s; hal_device_property_set_string (d, "info.subsystem", "usb_device"); + hal_device_property_set_string (d, "info.bus", "usb_device"); hal_util_set_driver (d, "info.linux.driver", sysfs_path); @@ -1772,7 +1779,11 @@ hal_util_set_int_from_file (d, "usb_device.linux.device_number", sysfs_path, "devnum", 10); hal_util_set_string_from_file (d, "usb_device.serial", sysfs_path, "serial"); + + hal_util_set_string_from_file (d, "usb_device.serial", sysfs_path, "serial"); + hal_util_set_bcd2_from_file (d, "usb_device.speed_bcd", sysfs_path, "speed"); hal_util_set_double_from_file (d, "usb_device.speed", sysfs_path, "speed"); + hal_util_set_bcd2_from_file (d, "usb_device.version_bcd", sysfs_path, "version"); hal_util_set_double_from_file (d, "usb_device.version", sysfs_path, "version"); hal_util_get_int_from_file (sysfs_path, "bmAttributes", &bmAttributes, 16); @@ -1784,10 +1795,18 @@ else hal_device_property_set_int (d, "usb_device.bus_number", atoi (bus_id)); + s = hal_util_get_string_from_file (sysfs_path, "../mode"); + if (s) { + hal_device_add_capability (d, "button"); + hal_device_property_set_string (d, "button.type", "usb.cable"); + hal_device_property_set_bool (d, "button.has_state", FALSE); + } + /* TODO: .level_number .parent_number */ } else { hal_device_property_set_string (d, "info.subsystem", "usb"); + hal_device_property_set_string (d, "info.bus", "usb"); /* take all usb_device.* properties from parent and make them usb.* on this object */ if (parent_dev != NULL) @@ -1819,20 +1838,22 @@ gchar udi[256]; if (hal_device_has_property (d, "usb.interface.number")) { - hald_compute_udi (udi, sizeof (udi), - "%s_if%d", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_int (d, "usb.interface.number")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_if%d", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_int (d, "usb.interface.number")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); } else { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/usb_device_%x_%x_%s", - hal_device_property_get_int (d, "usb_device.vendor_id"), - hal_device_property_get_int (d, "usb_device.product_id"), - hal_device_has_property (d, "usb_device.serial") ? - hal_device_property_get_string (d, "usb_device.serial") : - "noserial"); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/usb_device_%x_%x_%s", + hal_device_property_get_int (d, "usb_device.vendor_id"), + hal_device_property_get_int (d, "usb_device.product_id"), + hal_device_has_property (d, "usb_device.serial") ? + hal_device_property_get_string (d, "usb_device.serial") : + "noserial"); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); } return TRUE; @@ -1849,6 +1870,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "ide"); + hal_device_property_set_string (d, "info.bus", "ide"); if (parent_dev != NULL) { hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); } else { @@ -1877,47 +1900,29 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "%s_ide_%d_%d", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_int (d, "ide.host"), - hal_device_property_get_int (d, "ide.channel")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_ide_%d_%d", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_int (d, "ide.host"), + hal_device_property_get_int (d, "ide.channel")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } /*--------------------------------------------------------------------------------------------------------------*/ -static void -pnp_set_serial_info (const gchar *sysfs_path, HalDevice *d) { - - hal_util_set_int_elem_from_file (d, "pnp.serial.irq", sysfs_path, "resources", "irq", 0, 10, TRUE); - - if (hal_util_set_string_elem_from_file (d, "pnp.serial.port", sysfs_path, "resources", "io", 0, TRUE)) { - const char* port; - const char* _port; - _port = hal_device_property_get_string (d, "pnp.serial.port"); - if(_port == NULL) - return; - - port = strtok((char*) _port, "-"); - if(port == NULL) - return; - - hal_device_property_set_string (d, "pnp.serial.port", port); - } -} - static HalDevice * pnp_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, const gchar *parent_path) { HalDevice *d; - HalDevice *computer; d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "pnp"); + hal_device_property_set_string (d, "info.bus", "pnp"); if (parent_dev != NULL) { hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); } else { @@ -1929,29 +1934,11 @@ hal_util_set_string_from_file (d, "pnp.id", sysfs_path, "id"); if (hal_device_has_property (d, "pnp.id")) { gchar *pnp_description; - const char *pnp_id; ids_find_pnp (hal_device_property_get_string (d, "pnp.id"), &pnp_description); if (pnp_description != NULL) { hal_device_property_set_string (d, "pnp.description", pnp_description); hal_device_property_set_string (d, "info.product", pnp_description); } - pnp_id = hal_device_property_get_string (d, "pnp.id"); - if( !strncmp(pnp_id, "WACf00", 6) || !strcmp(pnp_id, "FUJ02e5") || - !strcmp(pnp_id, "FUJ02e6") || !strcmp(pnp_id, "FPI2004")) { - /* a internal serial tablet --> this should be a tablet pc */ - hal_device_add_capability (d, "input"); - hal_device_add_capability (d, "input.tablet"); - hal_device_add_capability (d, "input.tablet.tabletPC"); - - if ((computer = hal_device_store_find (hald_get_gdl (), "/org/freedesktop/Hal/devices/computer")) != NULL || - (computer = hal_device_store_find (hald_get_tdl (), "/org/freedesktop/Hal/devices/computer")) != NULL) { - - hal_device_property_set_string (computer, "system.formfactor", "laptop"); - hal_device_property_set_string (computer, "system.formfactor.subtype", "tabletpc"); - /* collect info about serial port and irq etc. */ - pnp_set_serial_info (sysfs_path, d); - } - } } if (!hal_device_has_property (d, "info.product")) { @@ -1969,10 +1956,11 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pnp_%s", - hal_device_property_get_string (d, "pnp.id")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pnp_%s", + hal_device_property_get_string (d, "pnp.id")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -1989,6 +1977,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "platform"); + hal_device_property_set_string (d, "info.bus", "platform"); if (parent_dev != NULL) { hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); } else { @@ -2004,13 +1994,6 @@ g_snprintf (buf, sizeof (buf), "Platform Device (%s)", hal_device_property_get_string (d, "platform.id")); hal_device_property_set_string (d, "info.product", buf); - if (strncmp (dev_id, "dock", 4) == 0) { - int docked; - - hal_util_get_int_from_file (sysfs_path, "docked", &docked, 0); - hal_device_property_set_bool (d, "info.docked", docked); - } - return d; } @@ -2019,63 +2002,14 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/platform_%s", - hal_device_property_get_string (d, "platform.id")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/platform_%s", + hal_device_property_get_string (d, "platform.id")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; -} - -static gboolean -platform_refresh_undock (gpointer data) -{ - HalDevice *d; - gint flags, docked; - const gchar *sysfs_path; - - if (data == NULL) - return FALSE; - d = (HalDevice *) data; - - sysfs_path = hal_device_property_get_string(d, "linux.sysfs_path"); - hal_util_get_int_from_file (sysfs_path, "flags", &flags, 0); - - /* check for != 0, maybe the user did an immediate dock */ - if (flags != 0) - return TRUE; - - hal_util_get_int_from_file (sysfs_path, "docked", &docked, 0); - hal_device_property_set_bool (d, "info.docked", docked); - return FALSE; -} - -static gboolean -platform_refresh (HalDevice *d) -{ - const gchar *id, *sysfs_path; - gint docked, flags; - - id = hal_device_property_get_string (d, "platform.id"); - if (strncmp (id, "dock", 4) != 0) - return TRUE; - - sysfs_path = hal_device_property_get_string(d, "linux.sysfs_path"); - hal_util_get_int_from_file (sysfs_path, "docked", &docked, 0); - - if (docked == 1) { - /* undock still in progress? */ - hal_util_get_int_from_file (sysfs_path, "flags", &flags, 0); - if (flags == 2) { - g_timeout_add (DOCK_STATION_UNDOCK_POLL_INTERVAL, - platform_refresh_undock, d); - return TRUE; - } - } - - hal_device_property_set_bool (d, "info.docked", docked); - return TRUE; } /*--------------------------------------------------------------------------------------------------------------*/ @@ -2088,6 +2022,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "serio"); + hal_device_property_set_string (d, "info.bus", "serio"); if (parent_dev != NULL) { hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); } else { @@ -2111,11 +2047,12 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "%s_%s", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "serio.description")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_%s", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "serio.description")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -2133,6 +2070,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "pcmcia"); + hal_device_property_set_string (d, "info.bus", "pcmcia"); if (parent_dev != NULL) { hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); } else { @@ -2187,11 +2126,12 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pcmcia_%d_%d", - hal_device_property_get_int (d, "pcmcia.manfid1"), - hal_device_property_get_int (d, "pcmcia.manfid2")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pcmcia_%d_%d", + hal_device_property_get_int (d, "pcmcia.manfid1"), + hal_device_property_get_int (d, "pcmcia.manfid2")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -2215,6 +2155,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "scsi"); + hal_device_property_set_string (d, "info.bus", "scsi"); hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); hal_device_property_set_int (d, "scsi.host", host_num); hal_device_property_set_int (d, "scsi.bus", bus_num); @@ -2277,11 +2219,12 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "%s_scsi_device_lun%d", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_int (d, "scsi.lun")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_scsi_device_lun%d", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_int (d, "scsi.lun")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -2294,7 +2237,7 @@ HalDevice *d; const gchar *bus_id; gint host_num, rca, manfid, oemid; - gchar *scr, *type; + gchar *scr; if (parent_dev == NULL) { d = NULL; @@ -2303,6 +2246,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "mmc"); + hal_device_property_set_string (d, "info.bus", "mmc"); hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); hal_util_set_driver (d, "info.linux.driver", sysfs_path); @@ -2314,11 +2259,6 @@ hal_util_set_string_from_file (d, "mmc.cid", sysfs_path, "cid"); hal_util_set_string_from_file (d, "mmc.csd", sysfs_path, "csd"); - type = hal_util_get_string_from_file (sysfs_path, "type"); - if (type != NULL) - /* Possible MMC/SD/SDIO */ - hal_device_property_set_string (d, "mmc.type", type); - scr = hal_util_get_string_from_file (sysfs_path, "scr"); if (scr != NULL) { if (strcmp (scr, "0000000000000000") == 0) @@ -2328,17 +2268,12 @@ } if (!hal_util_set_string_from_file (d, "info.product", sysfs_path, "name")) { - gchar buf[64]; - if (type != NULL) { - g_snprintf(buf, sizeof(buf), "%s Card", type); - hal_device_property_set_string (d, "info.product", buf); - } else if (scr != NULL) { - g_snprintf(buf, sizeof(buf), "SD Card"); - hal_device_property_set_string (d, "info.product", buf); + if (scr != NULL) { + hal_device_property_set_string (d, "info.product", "SD Card"); + hal_device_property_set_string (d, "mmc.product", "SD Card"); } else { - g_snprintf(buf, sizeof(buf), "MMC Card"); + hal_device_property_set_string (d, "mmc.product", "MMC Card"); } - hal_device_property_set_string (d, "mmc.product", buf); } if (hal_util_get_int_from_file (sysfs_path, "manfid", &manfid, 16)) { @@ -2369,11 +2304,12 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "%s_mmc_card_rca%d", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_int (d, "mmc.rca")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_mmc_card_rca%d", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_int (d, "mmc.rca")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -2381,57 +2317,48 @@ /*--------------------------------------------------------------------------------------------------------------*/ static HalDevice * -sdio_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, const gchar *parent_path) +mtd_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, const gchar *parent_path) { HalDevice *d; - const gchar *bus_id; - gchar buf[256]; - gint host_num, rca, card_id; - - if (parent_dev == NULL) - return NULL; + const gchar *host; + guint host_num; d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); - hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); + hal_device_property_set_string (d, "info.subsystem", "mtd"); + hal_device_property_set_string (d, "info.bus", "mtd"); + if (parent_dev != NULL) { + hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); + } else { + hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer"); + } hal_util_set_driver (d, "info.linux.driver", sysfs_path); - bus_id = hal_util_get_last_element (sysfs_path); - sscanf (bus_id, "mmc%d:%x:%d", &host_num, &rca, &card_id); - hal_device_property_set_int (d, "sdio.rca", rca); - hal_device_property_set_int (d, "sdio.card_id", card_id); - - hal_util_set_int_from_file (d, "sdio.vendor_id", sysfs_path, "vendor", 16); - hal_util_set_int_from_file (d, "sdio.product_id", sysfs_path, "device", 16); - hal_util_set_int_from_file (d, "sdio.class_id", sysfs_path, "class", 16); - - /* TODO: Here we should have a mapping to a name */ - g_snprintf (buf, sizeof (buf), "Unknown (0x%04x)", hal_device_property_get_int (d, "sdio.vendor_id")); - hal_device_property_set_string (d, "info.vendor", buf); - hal_device_property_set_string (d, "sdio.vendor", buf); + host = hal_util_get_last_element (sysfs_path); + sscanf (host, "mtdblock%d", &host_num); + hal_device_property_set_int (d, "mtd.host", host_num); - /* TODO: Here we should have a mapping to a name */ - g_snprintf (buf, sizeof (buf), "Unknown (0x%04x)", hal_device_property_get_int (d, "sdio.product_id")); - hal_device_property_set_string (d, "info.product", buf); - hal_device_property_set_string (d, "sdio.product", buf); + hal_device_property_set_string (d, "info.product", "MTD Device"); return d; } static gboolean -sdio_compute_udi (HalDevice *d) +mtd_compute_udi (HalDevice *d) { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "%s_sdio%d", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_int (d, "sdio.card_id")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_mtd_%d", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_int (d, "mtd.host")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } + /*--------------------------------------------------------------------------------------------------------------*/ static HalDevice * @@ -2442,6 +2369,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "xen"); + hal_device_property_set_string (d, "info.bus", "xen"); if (parent_dev != NULL) { hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); } else { @@ -2484,10 +2413,11 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/xen_%s", - hal_device_property_get_string (d, "xen.bus_id")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/xen_%s", + hal_device_property_get_string (d, "xen.bus_id")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -2521,6 +2451,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "ieee1394"); + hal_device_property_set_string (d, "info.bus", "ieee1394"); hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); hal_util_set_driver (d, "info.linux.driver", sysfs_path); @@ -2563,10 +2495,11 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/ieee1394_guid_%0llx", - hal_device_property_get_uint64 (d, "ieee1394.guid")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/ieee1394_guid_%0llx", + hal_device_property_get_uint64 (d, "ieee1394.guid")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -2585,6 +2518,7 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); hal_device_property_set_string (d, "info.subsystem", "ieee1394"); + hal_device_property_set_string (d, "info.bus", "ieee1394"); hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); hal_device_add_capability (d, "ieee1394"); hal_device_property_set_string (d, "ieee1394.device", device_file); @@ -2620,6 +2554,7 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); hal_device_property_set_string (d, "info.subsystem", "ieee1394_unit"); + hal_device_property_set_string (d, "info.bus", "ieee1394_unit"); hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); hal_device_property_set_string (d, "ieee1394_unit.originating_device", @@ -2702,17 +2637,18 @@ gchar udi[256]; if (hal_device_has_capability (d, "ieee1394")) { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/ieee1394_guid%0llx", - hal_device_property_get_uint64 (d, "ieee1394.guid")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/ieee1394_guid%0llx", + hal_device_property_get_uint64 (d, "ieee1394.guid")); } else { - hald_compute_udi (udi, sizeof (udi), - "%s_unit%d", - hal_device_property_get_string (d, "ieee1394_unit.originating_device"), - hal_device_property_get_int (d, "ieee1394_unit.unit_index")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_unit%d", + hal_device_property_get_string (d, "ieee1394_unit.originating_device"), + hal_device_property_get_int (d, "ieee1394_unit.unit_index")); } hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -2801,6 +2737,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "ccw"); + hal_device_property_set_string (d, "info.bus", "ccw"); if (parent_dev != NULL) hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); else @@ -2861,11 +2799,12 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/ccw_%s", - hal_device_property_get_string - (d, "ccw.bus_id")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/ccw_%s", + hal_device_property_get_string + (d, "ccw.bus_id")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -2969,6 +2908,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "ccwgroup"); + hal_device_property_set_string (d, "info.bus", "ccwgroup"); if (parent_dev != NULL) hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); else @@ -3001,11 +2942,12 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/ccwgroup_%s", - hal_device_property_get_string - (d, "ccwgroup.bus_id")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/ccwgroup_%s", + hal_device_property_get_string + (d, "ccwgroup.bus_id")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -3032,6 +2974,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "iucv"); + hal_device_property_set_string (d, "info.bus", "iucv"); if (parent_dev != NULL) hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); else @@ -3055,11 +2999,12 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/iucv_%s", - hal_device_property_get_string - (d, "iucv.bus_id")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/iucv_%s", + hal_device_property_get_string + (d, "iucv.bus_id")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -3090,11 +3035,17 @@ backlight_compute_udi (HalDevice *d) { gchar udi[256]; + const char *dir; + const char *name; + + dir = hal_device_property_get_string (d, "linux.sysfs_path"); - hald_compute_udi (udi, sizeof (udi), - "%s_backlight", - hal_device_property_get_string (d, "info.parent")); + name = hal_util_get_last_element(dir); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_backlight", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -3123,12 +3074,15 @@ { gint percentage = 0; gint voltage_now = 0; + gint voltage_design = 0; gint current = 0; gint time = 0; gint value_now = 0; gint value_last_full = 0; + gint value_full_design = 0; gboolean present = FALSE; - gboolean unknown_unit = TRUE; + gboolean could_be_mah = TRUE; + gboolean could_be_mwh = TRUE; gboolean is_mah = FALSE; gboolean is_mwh = FALSE; gboolean is_charging = FALSE; @@ -3166,12 +3120,15 @@ } else if (hal_util_get_int_from_file (path, "voltage_now", &voltage_now, 10)) { hal_device_property_set_int (d, "battery.voltage.current", voltage_now / 1000); } + if (hal_util_get_int_from_file (path, "voltage_max_design", &voltage_design, 10)) { + hal_device_property_set_int (d, "battery.voltage.design", voltage_design / 1000); + } /* CURRENT: we prefer the average if it exists, although present is still pretty good */ if (hal_util_get_int_from_file (path, "current_avg", ¤t, 10)) { - hal_device_property_set_int (d, "battery.reporting.rate", current / 1000); + hal_device_property_set_int (d, "battery.current", current / 1000); } else if (hal_util_get_int_from_file (path, "current_now", ¤t, 10)) { - hal_device_property_set_int (d, "battery.reporting.rate", current / 1000); + hal_device_property_set_int (d, "battery.current", current / 1000); } /* STATUS: Convert to charging/discharging state */ @@ -3182,7 +3139,6 @@ } else if (strcasecmp (status, "discharging") == 0) { is_discharging = TRUE; } - hal_device_property_set_bool (d, "battery.is_rechargeable", TRUE); hal_device_property_set_bool (d, "battery.rechargeable.is_charging", is_charging); hal_device_property_set_bool (d, "battery.rechargeable.is_discharging", is_discharging); } @@ -3205,16 +3161,14 @@ reporting_unit = hal_device_property_get_string (d, "battery.reporting.unit"); if (reporting_unit != NULL) { if (strcasecmp (reporting_unit, "mah") == 0) { - is_mah = TRUE; - unknown_unit = FALSE; + could_be_mwh = FALSE; } else if (strcasecmp (reporting_unit, "mwh") == 0) { - is_mwh = TRUE; - unknown_unit = FALSE; + could_be_mah = FALSE; } } /* ENERGY (reported in uWh, so need to convert to mWh) */ - if (unknown_unit || is_mwh) { + if (could_be_mwh) { if (hal_util_get_int_from_file (path, "energy_avg", &value_now, 10)) { hal_device_property_set_int (d, "battery.reporting.current", value_now / 1000); is_mwh = TRUE; @@ -3226,10 +3180,14 @@ hal_device_property_set_int (d, "battery.reporting.last_full", value_last_full / 1000); is_mwh = TRUE; } + if (hal_util_get_int_from_file (path, "energy_full_design", &value_full_design, 10)) { + hal_device_property_set_int (d, "battery.reporting.design", value_full_design / 1000); + is_mwh = TRUE; + } } /* CHARGE (reported in uAh, so need to convert to mAh) */ - if ((unknown_unit && !is_mwh) || is_mah) { + if (could_be_mah) { if (hal_util_get_int_from_file (path, "charge_avg", &value_now, 10)) { hal_device_property_set_int (d, "battery.reporting.current", value_now / 1000); is_mah = TRUE; @@ -3241,15 +3199,17 @@ hal_device_property_set_int (d, "battery.reporting.last_full", value_last_full / 1000); is_mah = TRUE; } + if (hal_util_get_int_from_file (path, "charge_full_design", &value_full_design, 10)) { + hal_device_property_set_int (d, "battery.reporting.design", value_full_design / 1000); + is_mah = TRUE; + } } /* record these for future savings */ - if (unknown_unit) { - if (is_mwh == TRUE) { - hal_device_property_set_string (d, "battery.reporting.unit", "mWh"); - } else if (is_mah == TRUE) { - hal_device_property_set_string (d, "battery.reporting.unit", "mAh"); - } + if (is_mwh == TRUE) { + hal_device_property_set_string (d, "battery.reporting.unit", "mWh"); + } else if (is_mah == TRUE) { + hal_device_property_set_string (d, "battery.reporting.unit", "mAh"); } /* we've now got the 'reporting' keys, now we need to populate the @@ -3279,12 +3239,10 @@ static void refresh_battery_slow (HalDevice *d) { - gint voltage_design = 0; - gint value_full_design = 0; + const char *technology; char *technology_raw; char *model_name; char *manufacturer; - char *serial; const gchar *path; path = hal_device_property_get_string (d, "linux.sysfs_path"); @@ -3296,12 +3254,13 @@ if (technology_raw != NULL) { hal_device_property_set_string (d, "battery.reporting.technology", technology_raw); } - hal_device_property_set_string (d, "battery.technology", util_get_battery_technology (technology_raw)); + /* we set this, even if it's unknown */ + technology = util_get_battery_technology (technology_raw); + hal_device_property_set_string (d, "battery.technology", technology); /* get product name */ - model_name = hal_util_get_string_from_file (path, "model_name"); + model_name = hal_util_get_string_from_file (path, "technology"); if (model_name != NULL) { - hal_device_property_set_string (d, "battery.model", model_name); hal_device_property_set_string (d, "info.product", model_name); } else { hal_device_property_set_string (d, "info.product", "Generic Battery Device"); @@ -3313,30 +3272,6 @@ hal_device_property_set_string (d, "battery.vendor", manufacturer); } - /* get stuff that never changes */ - if (hal_util_get_int_from_file (path, "voltage_max_design", &voltage_design, 10)) { - hal_device_property_set_int (d, "battery.voltage.design", voltage_design / 1000); - hal_device_property_set_string (d, "battery.voltage.unit", "mV"); - } else if (hal_util_get_int_from_file (path, "voltage_min_design", &voltage_design, 10)) { - hal_device_property_set_int (d, "battery.voltage.design", voltage_design / 1000); - hal_device_property_set_string (d, "battery.voltage.unit", "mV"); - } - - /* try to get the design info and set the units */ - if (hal_util_get_int_from_file (path, "energy_full_design", &value_full_design, 10)) { - hal_device_property_set_int (d, "battery.reporting.design", value_full_design / 1000); - hal_device_property_set_string (d, "battery.reporting.unit", "mWh"); - } else if (hal_util_get_int_from_file (path, "charge_full_design", &value_full_design, 10)) { - hal_device_property_set_int (d, "battery.reporting.design", value_full_design / 1000); - hal_device_property_set_string (d, "battery.reporting.unit", "mAh"); - } - - /* get serial */ - serial = hal_util_get_string_from_file (path, "serial_number"); - if (serial != NULL) { - hal_device_property_set_string (d, "battery.serial", serial); - } - /* now do stuff that happens quickly */ refresh_battery_fast (d); } @@ -3355,7 +3290,7 @@ device_property_atomic_update_end (); } else if (strcmp (type, "battery") == 0) { device_property_atomic_update_begin (); - refresh_battery_fast (d); + refresh_battery_slow (d); device_property_atomic_update_end (); } else { HAL_WARNING (("Could not recognise power_supply type!")); @@ -3364,37 +3299,6 @@ return TRUE; } - -static gboolean -power_supply_battery_poll (gpointer data) { - - GSList *i; - GSList *battery_devices; - HalDevice *d; - - /* for now do it only for primary batteries and extend if neede for the other types */ - battery_devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (), - "battery.type", - "primary"); - - if (battery_devices) { - for (i = battery_devices; i != NULL; i = g_slist_next (i)) { - const char *subsys; - - d = HAL_DEVICE (i->data); - subsys = hal_device_property_get_string (d, "info.subsystem"); - if (subsys && (strcmp(subsys, "power_supply") == 0)) { - hal_util_grep_discard_existing_data(); - device_property_atomic_update_begin (); - refresh_battery_fast(d); - device_property_atomic_update_end (); - } - } - } - g_slist_free (battery_devices); - return TRUE; -} - static HalDevice * power_supply_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *physdev, const gchar *sysfs_path_in_devices) @@ -3437,18 +3341,6 @@ hal_device_property_set_string (d, "battery.type", battery_type); refresh_battery_slow (d); hal_device_add_capability (d, "battery"); - - /* setup timer for things that we need to poll */ -#ifdef HAVE_GLIB_2_14 - g_timeout_add_seconds (POWER_SUPPLY_BATTERY_POLL_INTERVAL, - power_supply_battery_poll, - NULL); -#else - g_timeout_add (1000 * POWER_SUPPLY_BATTERY_POLL_INTERVAL, - power_supply_battery_poll, - NULL); -#endif - } if (is_ac_adapter == TRUE) { @@ -3457,8 +3349,6 @@ refresh_ac_adapter (d); hal_device_add_capability (d, "ac_adapter"); } - - _have_sysfs_power_supply = TRUE; finish: return d; } @@ -3473,19 +3363,11 @@ dir = hal_device_property_get_string (d, "linux.sysfs_path"); name = hal_util_get_last_element(dir); - if (name) - hald_compute_udi (udi, sizeof (udi), - "%s_power_supply_%s_%s", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "info.category"), - name); - else - hald_compute_udi (udi, sizeof (udi), - "%s_power_supply_%s", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "info.category")); - + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "%s_power_supply", + hal_device_property_get_string (d, "info.parent")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -3510,6 +3392,7 @@ hal_device_property_set_string (d, "info.product", "Direct Rendering Manager Device"); hal_device_property_set_string (d, "info.category", "drm"); hal_device_property_set_string (d, "linux.device_file", device_file); + hal_device_property_set_string (d, "linux.subsystem", "drm"); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); hal_util_set_driver (d, "info.linux.driver", sysfs_path); /* not sure if this is needed/set */ @@ -3531,267 +3414,12 @@ name = hal_util_get_last_element(dir); /* generate e.g.: /org/freedesktop/Hal/devices/pci_8086_2a02_drm_i915_card0 */ - hald_compute_udi (udi, sizeof (udi), - "%s_drm_%s_%s", - hal_device_property_get_string (d, "info.parent"), - hal_device_property_get_string (d, "drm.dri_library"), - name); - - hal_device_set_udi (d, udi); - - return TRUE; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -static HalDevice * -ps3_system_bus_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, - const gchar *sysfs_path_in_devices) -{ - HalDevice *d; - const gchar *dev_id; - gchar buf[64]; - - d = hal_device_new (); - hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); - if (parent_dev != NULL) { - hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); - } else { - hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer"); - } - - hal_util_set_driver (d, "info.linux.driver", sysfs_path); - - dev_id = hal_util_get_last_element (sysfs_path); - - hal_device_property_set_string (d, "ps3_system_bus.id", dev_id); - - g_snprintf (buf, sizeof (buf), "PS3 Device (%s)", hal_device_property_get_string (d, "ps3_system_bus.id")); - hal_device_property_set_string (d, "info.product", buf); - - return d; -} - -static gboolean -ps3_system_bus_compute_udi (HalDevice *d) -{ - gchar udi[256]; - - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/ps3_system_bus_%s", - hal_device_property_get_string (d, "ps3_system_bus.id")); - hal_device_set_udi (d, udi); - - return TRUE; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -static HalDevice * -virtio_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, - const gchar *sysfs_path_in_devices) -{ - HalDevice *d; - const gchar *dev_id; - gchar buf[64]; - - d = hal_device_new (); - hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); - if (parent_dev != NULL) { - hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); - } else { - hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer"); - } - - hal_util_set_driver (d, "info.linux.driver", sysfs_path); - - dev_id = hal_util_get_last_element (sysfs_path); - - hal_device_property_set_string (d, "virtio.id", dev_id); - - g_snprintf (buf, sizeof (buf), "VirtIO Device (%s)", hal_device_property_get_string (d, "virtio.id")); - hal_device_property_set_string (d, "info.product", buf); - - return d; -} - -static gboolean -virtio_compute_udi (HalDevice *d) -{ - gchar udi[256]; - - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/virtio_%s", - hal_device_property_get_string (d, "virtio.id")); - hal_device_set_udi (d, udi); - - return TRUE; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -static HalDevice * -vio_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, - const gchar *sysfs_path_in_devices) -{ - HalDevice *d; - const gchar *dev_id; - const gchar *dev_type; - gchar buf[64]; - - d = hal_device_new (); - hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); - if (parent_dev != NULL) { - hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); - } else { - hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer"); - } - - hal_util_set_driver (d, "info.linux.driver", sysfs_path); - - dev_id = hal_util_get_last_element (sysfs_path); - hal_device_property_set_string (d, "vio.id", dev_id); - - dev_type = hal_util_get_string_from_file (sysfs_path, "name"); - - if (dev_type) { - hal_device_property_set_string (d, "vio.type", dev_type); - g_snprintf (buf, sizeof (buf), "Vio %s Device (%s)", dev_type, dev_id); - hal_device_property_set_string (d, "info.product", buf); - } else { - hal_device_property_set_string (d, "info.product", "Vio Device (unknown)"); - } - - return d; -} - -static gboolean -vio_compute_udi (HalDevice *d) -{ - gchar udi[256]; - const char *type; - - type = hal_device_property_get_string (d, "vio.type"); - - if (type) { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/vio_%s_%s", - type, - hal_device_property_get_string (d, "vio.id")); - } else { - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/vio_%s", - hal_device_property_get_string (d, "vio.id")); - } - - hal_device_set_udi (d, udi); - - return TRUE; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -static HalDevice * -vmbus_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, const gchar *parent_path) -{ - HalDevice *d; - const gchar *bus_id; - const gchar *class_id; - const gchar *device_id; - - HAL_INFO (("vmbus_add: sysfs_path=%s device_file=%s parent_dev=0x%08x parent_path=%s", sysfs_path, device_file, parent_dev, parent_path)); - - d = hal_device_new (); - hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); - hal_device_property_set_string (d, "info.vendor", "Microsoft/Citrix"); - hal_util_set_driver (d, "info.linux.driver", sysfs_path); - - if (parent_dev != NULL) { - hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); - } else { - hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer"); - } - - bus_id = hal_util_get_last_element (sysfs_path); - hal_device_property_set_string (d, "vmbus.bus_id", bus_id); - device_id = hal_util_get_string_from_file (sysfs_path, "device_id"); - hal_device_property_set_string (d, "vmbus.device_id", device_id); - class_id = hal_util_get_string_from_file (sysfs_path, "class_id"); - hal_device_property_set_string (d, "vmbus.class_id", class_id); - - if (class_id != NULL) { - if (strcmp (class_id, "{f8615163-df3e-46c5-913ff2d2f965ed0e}") == 0) { - hal_device_property_set_string (d, "info.product", "Network Virtualization Service Client Device"); - } else if (strcmp (class_id, "{ba6163d9-04a1-4d29-b60572e2ffb1dc7f}") == 0) { - hal_device_property_set_string (d, "info.product", "Storage Virtualization Service Client Device"); - } else if (strcmp (class_id, "{c5295816-f63a-4d5f-8d1a4daf999ca185}") == 0) { - // root device of the bus - hal_device_property_set_string (d, "info.product", "Vmbus Device"); - } - } - - if (!hal_device_has_property(d, "info.product")) { - char buf[64]; - g_snprintf (buf, sizeof (buf), "Virtualization Service Client Device (%s)", bus_id); - hal_device_property_set_string (d, "info.product", buf); - } - - return d; -} - -static gboolean -vmbus_compute_udi (HalDevice *d) -{ - gchar udi[256]; - - hal_util_compute_udi (hald_get_gdl(), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/_%s", - hal_device_property_get_string (d, "vmbus.bus_id")); - - hal_device_set_udi (d, udi); - - return TRUE; -} - - -/*--------------------------------------------------------------------------------------------------------------*/ - -static HalDevice * -of_platform_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, - const gchar *sysfs_path_in_devices) -{ - HalDevice *d; - const gchar *dev_id; - gchar buf[64]; - - d = hal_device_new (); - hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); - if (parent_dev != NULL) { - hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); - } else { - hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer"); - } - - hal_util_set_driver (d, "info.linux.driver", sysfs_path); - - dev_id = hal_util_get_last_element (sysfs_path); - - hal_device_property_set_string (d, "of_platform.id", dev_id); - - g_snprintf (buf, sizeof (buf), "OpenFirmware Platform Device (%s)", hal_device_property_get_string (d, "of_platform.id")); - hal_device_property_set_string (d, "info.product", buf); - - return d; -} - -static gboolean -of_platform_compute_udi (HalDevice *d) -{ - gchar udi[256]; - hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), - "/org/freedesktop/Hal/devices/of_platform_%s", - hal_device_property_get_string (d, "of_platform.id")); + "%s_drm_%s_%s", + hal_device_property_get_string (d, "info.parent"), + hal_device_property_get_string (d, "drm.dri_library"), + name); + hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); @@ -3809,6 +3437,8 @@ d = hal_device_new (); hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path); + hal_device_property_set_string (d, "info.subsystem", "pseudo"); + hal_device_property_set_string (d, "info.bus", "pseudo"); if (parent_dev != NULL) { hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev)); } else { @@ -3831,10 +3461,11 @@ { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pseudo", - hal_device_property_get_string (d, "platform.id")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pseudo", + hal_device_property_get_string (d, "platform.id")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; @@ -4039,7 +3670,6 @@ static DevHandler dev_handler_platform = { .subsystem = "platform", .add = platform_add, - .refresh = platform_refresh, .compute_udi = platform_compute_udi, .remove = dev_remove }; @@ -4072,10 +3702,10 @@ .remove = dev_remove }; -static DevHandler dev_handler_sdio = { - .subsystem = "sdio", - .add = sdio_add, - .compute_udi = sdio_compute_udi, +static DevHandler dev_handler_mtd = { + .subsystem = "mtd", + .add = mtd_add, + .compute_udi = mtd_compute_udi, .remove = dev_remove }; @@ -4150,47 +3780,6 @@ .remove = dev_remove }; -static DevHandler dev_handler_ps3_system_bus = -{ - .subsystem = "ps3_system_bus", - .add = ps3_system_bus_add, - .compute_udi = ps3_system_bus_compute_udi, - .remove = dev_remove -}; - -static DevHandler dev_handler_virtio = -{ - .subsystem = "virtio", - .add = virtio_add, - .compute_udi = virtio_compute_udi, - .remove = dev_remove -}; - -static DevHandler dev_handler_vio = -{ - .subsystem = "vio", - .add = vio_add, - .compute_udi = vio_compute_udi, - .remove = dev_remove -}; - -static DevHandler dev_handler_vmbus = -{ - .subsystem = "vmbus", - .add = vmbus_add, - .compute_udi = vmbus_compute_udi, - .remove = dev_remove -}; - - -static DevHandler dev_handler_of_platform = -{ - .subsystem = "of_platform", - .add = of_platform_add, - .compute_udi = of_platform_compute_udi, - .remove = dev_remove -}; - /* SCSI debug, to test thousends of fake devices */ static DevHandler dev_handler_pseudo = { .subsystem = "pseudo", @@ -4212,7 +3801,7 @@ &dev_handler_pcmcia, &dev_handler_scsi, &dev_handler_mmc, - &dev_handler_sdio, + &dev_handler_mtd, &dev_handler_ieee1394, &dev_handler_xen, &dev_handler_ccw, @@ -4236,11 +3825,6 @@ &dev_handler_firewire, &dev_handler_power_supply, &dev_handler_drm, - &dev_handler_ps3_system_bus, - &dev_handler_virtio, - &dev_handler_vio, - &dev_handler_vmbus, - &dev_handler_of_platform, NULL }; @@ -4437,11 +4021,6 @@ hal_device_property_set_int (d, "linux.hotplug_type", HOTPLUG_EVENT_SYSFS_DEVICE); hal_device_property_set_string (d, "linux.subsystem", subsystem); - - /* only set info.subsystem if it's not set already to prevent trouble with usb/usb_device and other */ - if (!hal_device_has_property(d, "info.subsystem")) { - hal_device_property_set_string (d, "info.subsystem", subsystem); - } if (device_file != NULL && strlen (device_file) > 0) hal_device_property_set_string (d, "linux.device_file", device_file); @@ -4583,11 +4162,11 @@ const char *device_file; HotplugEvent *hotplug_event; - subsystem = hal_device_property_get_string (d, "info.subsystem"); + subsystem = hal_device_property_get_string (d, "linux.subsystem"); sysfs_path = hal_device_property_get_string (d, "linux.sysfs_path"); device_file = hal_device_property_get_string (d, "linux.device_file"); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_ADD; hotplug_event->type = HOTPLUG_EVENT_SYSFS; g_strlcpy (hotplug_event->sysfs.subsystem, subsystem, sizeof (hotplug_event->sysfs.subsystem)); @@ -4608,11 +4187,10 @@ const char *sysfs_path; HotplugEvent *hotplug_event; - /* be sure that we use linux.subsystem here because info.subsystem can differ see e.g. usb/usb_device */ subsystem = hal_device_property_get_string (d, "linux.subsystem"); sysfs_path = hal_device_property_get_string (d, "linux.sysfs_path"); - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->action = HOTPLUG_ACTION_REMOVE; hotplug_event->type = HOTPLUG_EVENT_SYSFS; g_strlcpy (hotplug_event->sysfs.subsystem, subsystem, sizeof (hotplug_event->sysfs.subsystem)); diff -ur hal-0.5.11/hald/linux/device.h hal-0.5.11~git20080402/hald/linux/device.h --- hal-0.5.11/hald/linux/device.h 2008-05-08 00:23:42.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/device.h 2008-03-14 19:57:37.000000000 +0000 @@ -52,6 +52,5 @@ extern gboolean _have_sysfs_lid_button; extern gboolean _have_sysfs_power_button; extern gboolean _have_sysfs_sleep_button; -extern gboolean _have_sysfs_power_supply; #endif diff -ur hal-0.5.11/hald/linux/hal-file-monitor.c hal-0.5.11~git20080402/hald/linux/hal-file-monitor.c --- hal-0.5.11/hald/linux/hal-file-monitor.c 2008-05-08 00:23:40.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/hal-file-monitor.c 2007-10-10 17:28:44.000000000 +0100 @@ -410,8 +410,6 @@ if (ievent->mask & IN_IGNORED) { file_monitor_remove_watch (monitor, watch); } - - g_free(freeme); } static gboolean diff -ur hal-0.5.11/hald/linux/hotplug.c hal-0.5.11~git20080402/hald/linux/hotplug.c --- hal-0.5.11/hald/linux/hotplug.c 2008-05-08 00:23:32.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/hotplug.c 2008-03-14 19:57:37.000000000 +0000 @@ -50,10 +50,10 @@ #include "hotplug.h" /** Queue of ordered hotplug events */ -static GQueue *hotplug_event_queue; +GQueue *hotplug_event_queue; /** List of HotplugEvent objects we are currently processing */ -static GSList *hotplug_events_in_progress = NULL; +GSList *hotplug_events_in_progress = NULL; void hotplug_event_end (void *end_token) @@ -62,7 +62,11 @@ hotplug_events_in_progress = g_slist_remove (hotplug_events_in_progress, hotplug_event); - g_slice_free (HotplugEvent, hotplug_event); + if (hotplug_event->free_function != NULL) { + hotplug_event->free_function (hotplug_event); + } else { + g_free (hotplug_event); + } } void @@ -109,7 +113,7 @@ if (hotplug_event->type == HOTPLUG_EVENT_SYSFS && d != NULL) { HotplugEventType type; - type = (HotplugEventType) hal_device_property_get_int (d, "linux.hotplug_type"); + type = hal_device_property_get_int (d, "linux.hotplug_type"); if (type == HOTPLUG_EVENT_SYSFS_DEVICE) { HAL_INFO (("%s is a device (store)", hotplug_event->sysfs.sysfs_path)); hotplug_event->type = HOTPLUG_EVENT_SYSFS_DEVICE; diff -ur hal-0.5.11/hald/linux/hotplug.h hal-0.5.11~git20080402/hald/linux/hotplug.h --- hal-0.5.11/hald/linux/hotplug.h 2008-05-08 00:23:32.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/hotplug.h 2008-03-14 19:57:37.000000000 +0000 @@ -57,6 +57,9 @@ HotplugActionType action; /* Whether the event is add or remove */ HotplugEventType type; /* Type of event */ gboolean reposted; /* Avoid loops */ + + void (*free_function) (gpointer data); + union { struct { char subsystem[HAL_NAME_MAX]; /* Kernel subsystem the device belongs to */ Only in hal-0.5.11~git20080402/hald/linux: input_local.h diff -ur hal-0.5.11/hald/linux/osspec.c hal-0.5.11~git20080402/hald/linux/osspec.c --- hal-0.5.11/hald/linux/osspec.c 2008-05-08 00:23:34.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/osspec.c 2008-03-14 19:57:37.000000000 +0000 @@ -121,7 +121,7 @@ goto out; } - hotplug_event = g_slice_new0 (HotplugEvent); + hotplug_event = g_new0 (HotplugEvent, 1); hotplug_event->type = HOTPLUG_EVENT_SYSFS; while (bufpos < sizeof (buf)) { @@ -226,16 +226,6 @@ goto invalid; } - /* This is a workaround for temporary cryptsetup devices, HAL should ignore them. - * There is already a fix for this issue in the udev git master as soon as a new - * udev release is available and HAL starts to depend on the new version we should - * remove this again. (added 2008-03-04) - */ - if (strncmp (hotplug_event->sysfs.device_file, "/dev/mapper/temporary-cryptsetup-", 33) == 0) { - HAL_INFO (("Temporary workaround: ignoring temporary cryptsetup file")); - goto invalid; - } - HAL_INFO (("SEQNUM=%lld, ACTION=%s, SUBSYSTEM=%s, DEVPATH=%s, DEVNAME=%s, IFINDEX=%d", hotplug_event->sysfs.seqnum, action, hotplug_event->sysfs.subsystem, hotplug_event->sysfs.sysfs_path, hotplug_event->sysfs.device_file, hotplug_event->sysfs.net_ifindex)); @@ -273,7 +263,7 @@ } invalid: - g_slice_free (HotplugEvent, hotplug_event); + g_free (hotplug_event); out: return TRUE; @@ -396,9 +386,6 @@ /* * setup socket for listening from messages from udev */ - - hal_device_store_index_property (hald_get_gdl (), "linux.sysfs_path"); - memset(&saddr, 0x00, sizeof(saddr)); saddr.sun_family = AF_LOCAL; /* use abstract namespace for socket path */ @@ -507,8 +494,7 @@ /* Map the chassis type from dmidecode.c to a sensible type used in hal * * See also 3.3.4.1 of the "System Management BIOS Reference Specification, - * Version 2.6.1" (Preliminary Standard) document, available from - * http://www.dmtf.org/standards/smbios. + * Version 2.3.4" document, available from http://www.dmtf.org/standards/smbios. * * TODO: figure out WTF the mapping should be; "Lunch Box"? Give me a break :-) */ @@ -527,7 +513,7 @@ "Docking Station", "laptop", "All In One", "unknown", "Sub Notebook", "laptop", - "Space-saving", "desktop", + "Space-saving", "unknown", "Lunch Box", "unknown", "Main Server Chassis", "server", "Expansion Chassis", "unknown", @@ -539,9 +525,7 @@ "Sealed-case PC", "unknown", "Multi-system", "unknown", "CompactPCI", "unknonw", - "AdvancedTCA", "unknown", - "Blade", "server", - "Blade Enclosure" "unknown", /* 0x1D */ + "AdvancedTCA", "unknown", /* 0x1B */ NULL }; @@ -552,7 +536,7 @@ const char *chassis_type; /* now map the smbios.* properties to our generic system.formfactor property */ - if ((chassis_type = hal_device_property_get_string (d, "system.chassis.type")) != NULL) { + if ((chassis_type = hal_device_property_get_string (d, "smbios.chassis.type")) != NULL) { for (i = 0; chassis_map[i] != NULL; i += 2) { if (strcmp (chassis_map[i], chassis_type) == 0) { @@ -599,6 +583,9 @@ (system_version = hal_device_property_get_string (d, "system.hardware.version")) != NULL) { char buf[128]; + /* depricated 2008-02-28 */ + hal_device_property_set_string (d, "system.vendor", system_manufacturer); + if (strcmp(system_version, "Not Specified" ) != 0 ) { g_snprintf (buf, sizeof (buf), "%s %s", system_product, system_version); hal_device_property_set_string (d, "system.product", buf); @@ -659,6 +646,12 @@ hal_device_property_set_bool (d, "power_management.can_suspend", can_suspend); hal_device_property_set_bool (d, "power_management.can_suspend_hybrid", FALSE); hal_device_property_set_bool (d, "power_management.can_hibernate", can_hibernate); + + /* WARNING: These keys are depreciated and power_management.can_suspend + * and power_management.can_hibernate should be used instead. + * These properties will be removed, but not before May 1st 2007. */ + hal_device_property_set_bool (d, "power_management.can_suspend_to_ram", can_suspend); + hal_device_property_set_bool (d, "power_management.can_suspend_to_disk", can_hibernate); } static void @@ -742,6 +735,18 @@ hal_util_set_string_from_file(d, "system.chassis.manufacturer", DMI_SYSFS_PATH, "chassis_vendor"); computer_dmi_map (d, FALSE); + /* compatibility keys, remove 28 Feb 2008 */ + hal_device_copy_property (d, "system.hardware.vendor", d , "smbios.system.manufacturer"); + hal_device_copy_property (d, "system.hardware.product", d , "smbios.system.product"); + hal_device_copy_property (d, "system.hardware.version", d , "smbios.system.version"); + hal_device_copy_property (d, "system.hardware.serial", d , "smbios.system.serial"); + hal_device_copy_property (d, "system.hardware.uuid", d , "smbios.system.uuid"); + hal_device_copy_property (d, "system.firmware.vendor", d , "smbios.bios.vendor"); + hal_device_copy_property (d, "system.firmware.version", d , "smbios.bios.version"); + hal_device_copy_property (d, "system.firmware.release_date", d , "smbios.bios.release_date"); + hal_device_copy_property (d, "system.chassis.manufacturer", d , "smbios.chassis.manufacturer"); + hal_device_copy_property (d, "system.chassis.type", d , "smbios.chassis.type"); + computer_probing_helper_done (d); return TRUE; @@ -811,6 +816,33 @@ ; } +#if defined(__arm__) +static void +computer_probing_omap_helper_done (HalDevice *d, guint32 exit_type, + gint return_code, gchar **error, + gpointer data1, gpointer data2) +{ + if (exit_type == HALD_RUN_FAILED) { + /* set a default value */ + } +} + +static void +probe_omap (HalDevice *root) +{ + if (access ("/proc/component_version", F_OK) == 0) + hald_runner_run (root, "hald-probe-omap", NULL, + HAL_HELPER_TIMEOUT, + computer_probing_omap_helper_done, + NULL, NULL); +} +#else +static void +probe_omap (HalDevice *root) +{ +} +#endif + void osspec_probe (void) { @@ -820,7 +852,9 @@ hald_runner_set_method_run_notify ((HaldRunnerRunNotify) hotplug_event_process_queue, NULL); root = hal_device_new (); hal_device_property_set_string (root, "info.subsystem", "unknown"); + hal_device_property_set_string (root, "info.bus", "unknown"); hal_device_property_set_string (root, "info.product", "Computer"); + hal_device_property_set_string (root, "info.udi", "/org/freedesktop/Hal/devices/computer"); hal_device_set_udi (root, "/org/freedesktop/Hal/devices/computer"); if (uname (&un) >= 0) { @@ -843,6 +877,8 @@ /* set the vendor/product of primary video card */ get_primary_videocard (root); + probe_omap (root); + /* Try and set the suspend/hibernate keys using pm-is-supported */ if (g_file_test ("/usr/bin/pm-is-supported", G_FILE_TEST_IS_EXECUTABLE)) { diff -ur hal-0.5.11/hald/linux/pmu.c hal-0.5.11~git20080402/hald/linux/pmu.c --- hal-0.5.11/hald/linux/pmu.c 2008-05-08 00:23:33.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/pmu.c 2008-03-14 19:57:37.000000000 +0000 @@ -68,7 +68,7 @@ #define PMU_BATT_TYPE_HOOPER 0x00000020 /* 3400/3500 */ #define PMU_BATT_TYPE_COMET 0x00000030 /* 2400 */ -#define PMU_POLL_INTERVAL 2 /* in seconds */ +#define PMU_POLL_INTERVAL 2000 #define PMUDEV "/dev/pmu" @@ -78,6 +78,7 @@ { const char *path; int flags; + int last_full; path = hal_device_property_get_string (d, "linux.pmu_path"); if (path == NULL) @@ -122,6 +123,9 @@ else hal_device_property_set_int (d, "battery.charge_level.rate", -current); + current = hal_device_property_get_int (d, "battery.charge_level.current"); + last_full = hal_device_property_get_int (d, "battery.charge_level.last_full"); + /* TODO: could read some pmu file? */ device_pm_calculate_time (d); device_pm_calculate_percentage (d); @@ -208,9 +212,10 @@ pmu_lid_compute_udi (HalDevice *d, PMUDevHandler *handler) { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pmu_lid"); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pmu_lid"); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -218,9 +223,10 @@ pmu_laptop_panel_compute_udi (HalDevice *d, PMUDevHandler *handler) { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pmu_lcd"); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pmu_lcd"); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } @@ -358,15 +364,9 @@ } /* setup timer for things that we need to poll */ -#ifdef HAVE_GLIB_2_14 - g_timeout_add_seconds (PMU_POLL_INTERVAL, - pmu_poll, - NULL); -#else - g_timeout_add (1000 * PMU_POLL_INTERVAL, + g_timeout_add (PMU_POLL_INTERVAL, pmu_poll, NULL); -#endif out: return ret; @@ -394,11 +394,12 @@ pmu_generic_compute_udi (HalDevice *d, PMUDevHandler *handler) { gchar udi[256]; - hald_compute_udi (udi, sizeof (udi), - "/org/freedesktop/Hal/devices/pmu_%s_%d", - hal_util_get_last_element (hal_device_property_get_string (d, "linux.pmu_path")), - hal_device_property_get_int (d, "linux.pmu_type")); + hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), + "/org/freedesktop/Hal/devices/pmu_%s_%d", + hal_util_get_last_element (hal_device_property_get_string (d, "linux.pmu_path")), + hal_device_property_get_int (d, "linux.pmu_type")); hal_device_set_udi (d, udi); + hal_device_property_set_string (d, "info.udi", udi); return TRUE; } diff -ur hal-0.5.11/hald/linux/probing/probe-input.c hal-0.5.11~git20080402/hald/linux/probing/probe-input.c --- hal-0.5.11/hald/linux/probing/probe-input.c 2008-05-08 00:23:43.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/probing/probe-input.c 2008-03-14 19:57:37.000000000 +0000 @@ -81,10 +81,6 @@ sw = SW_TABLET_MODE; else if (strcmp (button_type, "headphone_insert") == 0) sw = SW_HEADPHONE_INSERT; -#ifdef SW_RADIO - else if (strcmp (button_type, "radio") == 0) - sw = SW_RADIO; -#endif else goto out; Only in hal-0.5.11~git20080402/hald/linux/probing: probe-omap.c diff -ur hal-0.5.11/hald/linux/probing/probe-pc-floppy.c hal-0.5.11~git20080402/hald/linux/probing/probe-pc-floppy.c --- hal-0.5.11/hald/linux/probing/probe-pc-floppy.c 2008-05-08 00:23:44.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/probing/probe-pc-floppy.c 2007-10-10 17:28:44.000000000 +0100 @@ -46,6 +46,7 @@ { int fd; int ret; + char *udi; char *device_file; char name[256]; struct floppy_drive_struct ds; @@ -55,7 +56,7 @@ /* assume failure */ ret = 1; - if (getenv ("UDI") == NULL) + if ((udi = getenv ("UDI")) == NULL) goto out; if ((device_file = getenv ("HAL_PROP_BLOCK_DEVICE")) == NULL) goto out; diff -ur hal-0.5.11/hald/linux/probing/probe-serial.c hal-0.5.11~git20080402/hald/linux/probing/probe-serial.c --- hal-0.5.11/hald/linux/probing/probe-serial.c 2008-05-08 00:23:43.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/probing/probe-serial.c 2007-10-10 17:28:44.000000000 +0100 @@ -46,6 +46,7 @@ { int fd; int ret; + char *udi; char *device_file; struct serial_struct ss; @@ -56,7 +57,7 @@ setup_logger (); - if (getenv ("UDI") == NULL) { + if ((udi = getenv ("UDI")) == NULL) { HAL_ERROR (("UDI not set")); goto out; } diff -ur hal-0.5.11/hald/linux/probing/probe-smbios.c hal-0.5.11~git20080402/hald/linux/probing/probe-smbios.c --- hal-0.5.11/hald/linux/probing/probe-smbios.c 2008-05-08 00:23:43.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/probing/probe-smbios.c 2008-03-14 19:57:37.000000000 +0000 @@ -29,7 +29,6 @@ #endif #include -#include #include #include #include @@ -49,8 +48,8 @@ #define strbegin(buf, str) (strncmp (buf, str, strlen (str)) == 0) /* global */ -static char *udi = NULL; -static LibHalContext *ctx = NULL; +char *udi = NULL; +LibHalContext *ctx = NULL; /** * setstr: @@ -83,6 +82,24 @@ return FALSE; } +/** + * copykeyval: + * @key: The new HAL key + * @compat_key: The compatibility key, to be copied if key exists + * + * Copies a key value into the compatibility value, if it exists. + */ +static void +copykeyval (char *key, char *compat_key) +{ + char *value; + + value = libhal_device_get_property_string (ctx, udi, key, NULL); + if (value != NULL) { + HAL_DEBUG (("Copying %s -> %s", key, compat_key)); + libhal_device_set_property_string (ctx, udi, compat_key, value, NULL); + } +} /** * main: @@ -102,6 +119,7 @@ char *nbuf; int dmipipe[2]; int nullfd; + int tmp_ret; FILE *f; int dmiparser_state = DMIPARSER_STATE_IGNORE; @@ -153,20 +171,9 @@ exit(1); } - if(pipe (dmipipe) == -1) { - HAL_ERROR(("Could not create pipe (error: '%s'), exit!", strerror(errno))); - exit(1); - } - - if ((f = fdopen (dmipipe[0], "r")) == NULL) { - HAL_ERROR(("Could not open file (error: '%s'), exit!", strerror(errno))); - exit(1); - } - - if ((nullfd = open ("/dev/null", O_RDONLY)) == -1){ - HAL_ERROR(("Could not open /dev/null (error: '%s'), exit!", strerror(errno))); - exit(1); - } + tmp_ret = pipe (dmipipe); + f = fdopen (dmipipe[0], "r"); + nullfd = open ("/dev/null", O_RDONLY); /* fork the child process */ switch (fork ()) { @@ -198,7 +205,7 @@ /* read the output of the child */ while(fgets (buf, sizeof(buf), f) != NULL) { - int j; + int i; unsigned int len; unsigned int tabs = 0; @@ -254,8 +261,8 @@ nbuf = &buf[1]; /* removes the trailing spaces */ - for (j = len - 2; isspace (nbuf[j]) && j >= 0; --j) - nbuf[j] = '\0'; + for (i = len - 2; isspace (nbuf[i]) && i >= 0; --i) + nbuf[i] = '\0'; if (dmiparser_state == DMIPARSER_STATE_BIOS) { setstr (nbuf, "Vendor:", "system.firmware.vendor"); @@ -279,6 +286,18 @@ /* as read to EOF, close */ fclose (f); + /* compatibility keys, remove 28 Feb 2008 */ + copykeyval ("system.hardware.vendor", "smbios.system.manufacturer"); + copykeyval ("system.hardware.product", "smbios.system.product"); + copykeyval ("system.hardware.version", "smbios.system.version"); + copykeyval ("system.hardware.serial", "smbios.system.serial"); + copykeyval ("system.hardware.uuid", "smbios.system.uuid"); + copykeyval ("system.firmware.vendor", "smbios.bios.vendor"); + copykeyval ("system.firmware.version", "smbios.bios.version"); + copykeyval ("system.firmware.release_date", "smbios.bios.release_date"); + copykeyval ("system.chassis.manufacturer", "smbios.chassis.manufacturer"); + copykeyval ("system.chassis.type", "smbios.chassis.type"); + out: /* free ctx */ if (ctx != NULL) { diff -ur hal-0.5.11/hald/linux/probing/probe-video4linux.c hal-0.5.11~git20080402/hald/linux/probing/probe-video4linux.c --- hal-0.5.11/hald/linux/probing/probe-video4linux.c 2008-05-08 00:23:45.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/probing/probe-video4linux.c 2008-03-14 19:57:37.000000000 +0000 @@ -30,8 +30,8 @@ #include #include #include -#include -#include +#include /* for Video4Linux */ +#include /* for Video4Linux2 */ #include #include #include @@ -43,7 +43,7 @@ #include "libhal/libhal.h" #include "../../logger.h" -int +int main (int argc, char *argv[]) { int fd = -1; @@ -81,12 +81,12 @@ goto out; } - if (ioctl (fd, VIDIOC_QUERYCAP, &v2cap) == 0) { + if (ioctl(fd, VIDIOC_QUERYCAP, &v2cap) == 0) { libhal_changeset_set_property_string (cset, "video4linux.version", "2"); libhal_changeset_set_property_string (cset, - "info.product", (const char *)v2cap.card); + "info.product", v2cap.card); if ((v2cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) > 0) libhal_device_add_capability (ctx, udi, "video4linux.video_capture", &error); @@ -103,7 +103,7 @@ } else HAL_DEBUG (("ioctl VIDIOC_QUERYCAP failed")); - if (ioctl (fd, VIDIOCGCAP, &v1cap) == 0) { + if (ioctl(fd, VIDIOCGCAP, &v1cap) == 0) { libhal_changeset_set_property_string (cset, "video4linux.version", "1"); diff -ur hal-0.5.11/hald/linux/probing/probe-volume.c hal-0.5.11~git20080402/hald/linux/probing/probe-volume.c --- hal-0.5.11/hald/linux/probing/probe-volume.c 2008-05-08 00:23:44.000000000 +0100 +++ hal-0.5.11~git20080402/hald/linux/probing/probe-volume.c 2007-11-05 21:45:47.000000000 +0000 @@ -89,7 +89,7 @@ static void -set_volume_id_values (LibHalChangeSet *cs, struct volume_id *vid) +set_volume_id_values (LibHalContext *ctx, const char *udi, LibHalChangeSet *cs, struct volume_id *vid) { char buf[256]; const char *usage; @@ -153,7 +153,8 @@ } static void -advanced_disc_detect (LibHalChangeSet *cs, int fd, const char *device_file) +advanced_disc_detect (LibHalContext *ctx, const char *udi, LibHalChangeSet *cs, + int fd, const char *device_file) { /* the discs block size */ unsigned short bs; @@ -311,6 +312,7 @@ LibHalContext *ctx = NULL; DBusError error; char *parent_udi; + char *sysfs_path; struct volume_id *vid; char *stordev_dev_file; char *partition_number_str; @@ -344,7 +346,7 @@ goto out; if ((parent_udi = getenv ("HAL_PROP_INFO_PARENT")) == NULL) goto out; - if (getenv ("HAL_PROP_LINUX_SYSFS_PATH") == NULL) + if ((sysfs_path = getenv ("HAL_PROP_LINUX_SYSFS_PATH")) == NULL) goto out; partition_number_str = getenv ("HAL_PROP_VOLUME_PARTITION_NUMBER"); if (partition_number_str != NULL) @@ -434,7 +436,7 @@ case CDS_XA_2_2: libhal_changeset_set_property_bool (cs, "volume.disc.has_data", TRUE); HAL_DEBUG(("Disc in %s has data", device_file)); - advanced_disc_detect (cs, fd, device_file); + advanced_disc_detect (ctx, udi, cs, fd, device_file); break; case CDS_NO_INFO: /* blank or invalid CD */ libhal_changeset_set_property_bool (cs, "volume.disc.is_blank", TRUE); @@ -631,7 +633,7 @@ } if (vid_ret == 0) { - set_volume_id_values(cs, vid); + set_volume_id_values(ctx, udi, cs, vid); if (disc_may_have_data) { libhal_changeset_set_property_bool (cs, "volume.disc.is_blank", FALSE); libhal_changeset_set_property_bool (cs, "volume.disc.has_data", TRUE); @@ -668,7 +670,7 @@ if (volume_id_probe_all ( vid, vol_probe_offset + part_offset, 0) == 0) { - set_volume_id_values(cs, vid); + set_volume_id_values(ctx, udi, cs, vid); } /* and we're done */ diff -ur hal-0.5.11/hald/mmap_cache.c hal-0.5.11~git20080402/hald/mmap_cache.c --- hal-0.5.11/hald/mmap_cache.c 2008-05-08 00:24:09.000000000 +0100 +++ hal-0.5.11~git20080402/hald/mmap_cache.c 2008-03-14 19:57:37.000000000 +0000 @@ -91,6 +91,7 @@ return 0; } +static gboolean regen_cache_done; static gint regen_cache_success; static void @@ -109,6 +110,8 @@ } else { regen_cache_success = FALSE; } + + regen_cache_done = TRUE; } @@ -137,8 +140,10 @@ } } + regen_cache_done = FALSE; + hald_runner_run_sync (NULL, - "hald-generate-fdi-cache", + "hald-generate-fdi-cache --force", extra_env, 60000, regen_cache_cb, @@ -174,6 +179,7 @@ struct dirent **namelist; struct stat st; int n; + char cpath[PATH_MAX]; if (setup_watches) { HalFileMonitor *file_monitor; @@ -200,13 +206,15 @@ return; else { while(n--) { - gchar *cpath; - cpath = g_build_filename(path, namelist[n]->d_name, NULL); +#ifdef HAVE_SNPRINTF + snprintf(cpath, PATH_MAX, "%s/%s", path, namelist[n]->d_name); +#else + sprintf(cpath, "%s/%s", path, namelist[n]->d_name); +#endif if(namelist[n]->d_name[0] != '.') dir_mtime(cpath, mt, setup_watches); free(namelist[n]); - g_free(cpath); } free(namelist); } diff -ur hal-0.5.11/hald/util.c hal-0.5.11~git20080402/hald/util.c --- hal-0.5.11/hald/util.c 2008-05-08 00:24:10.000000000 +0100 +++ hal-0.5.11~git20080402/hald/util.c 2008-03-14 19:57:37.000000000 +0000 @@ -179,7 +179,6 @@ char buf[64]; gchar path[HAL_PATH_MAX]; gboolean ret; - gint _result; f = NULL; ret = FALSE; @@ -188,21 +187,18 @@ f = fopen (path, "rb"); if (f == NULL) { - //HAL_ERROR (("Cannot open '%s'", path)); + HAL_ERROR (("Cannot open '%s'", path)); goto out; } if (fgets (buf, sizeof (buf), f) == NULL) { - //HAL_ERROR (("Cannot read from '%s'", path)); + HAL_ERROR (("Cannot read from '%s'", path)); goto out; } - errno = 0; - _result = strtol (buf, NULL, base); - if (errno == 0) { - ret = TRUE; - *result = _result; - } + /* TODO: handle error condition */ + *result = strtol (buf, NULL, base); + ret = TRUE; out: if (f != NULL) @@ -233,7 +229,6 @@ char buf[64]; gchar path[HAL_PATH_MAX]; gboolean ret; - guint64 _result; f = NULL; ret = FALSE; @@ -242,21 +237,19 @@ f = fopen (path, "rb"); if (f == NULL) { - //HAL_ERROR (("Cannot open '%s'", path)); + HAL_ERROR (("Cannot open '%s'", path)); goto out; } if (fgets (buf, sizeof (buf), f) == NULL) { - //HAL_ERROR (("Cannot read from '%s'", path)); + HAL_ERROR (("Cannot read from '%s'", path)); goto out; } - errno = 0; - _result = strtoll (buf, NULL, base); - if (errno == 0) { - ret = TRUE; - *result = _result; - } + /* TODO: handle error condition */ + *result = strtoll (buf, NULL, base); + + ret = TRUE; out: if (f != NULL) @@ -279,6 +272,96 @@ return ret; } +gboolean +hal_util_get_bcd2_from_file (const gchar *directory, const gchar *file, gint *result) +{ + FILE *f; + char buf[64]; + gchar path[HAL_PATH_MAX]; + gboolean ret; + gint digit; + gint left, right; + gboolean passed_white_space; + gint num_prec; + gsize len; + gchar c; + guint i; + + f = NULL; + ret = FALSE; + + g_snprintf (path, sizeof (path), "%s/%s", directory, file); + + f = fopen (path, "rb"); + if (f == NULL) { + HAL_ERROR (("Cannot open '%s'", path)); + goto out; + } + + if (fgets (buf, sizeof (buf), f) == NULL) { + HAL_ERROR (("Cannot read from '%s'", path)); + goto out; + } + + left = 0; + len = strlen (buf); + passed_white_space = FALSE; + for (i = 0; i < len && buf[i] != '.'; i++) { + if (g_ascii_isspace (buf[i])) { + if (passed_white_space) + break; + else + continue; + } + passed_white_space = TRUE; + left *= 16; + c = buf[i]; + digit = (int) (c - '0'); + left += digit; + } + i++; + right = 0; + num_prec = 0; + for (; i < len; i++) { + if (g_ascii_isspace (buf[i])) + break; + if (num_prec == 2) /* Only care about two digits + * of precision */ + break; + right *= 16; + c = buf[i]; + digit = (int) (c - '0'); + right += digit; + num_prec++; + } + + for (; num_prec < 2; num_prec++) + right *= 16; + + *result = left * 256 + (right & 255); + ret = TRUE; + +out: + if (f != NULL) + fclose (f); + + return ret; +} + +gboolean +hal_util_set_bcd2_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file) +{ + gint value; + gboolean ret; + + ret = FALSE; + + if (hal_util_get_bcd2_from_file (directory, file, &value)) + ret = hal_device_property_set_int (d, key, value); + + return ret; +} + gchar * hal_util_get_string_from_file (const gchar *directory, const gchar *file) { @@ -296,13 +379,13 @@ f = fopen (path, "rb"); if (f == NULL) { - //HAL_ERROR (("Cannot open '%s'", path)); + HAL_ERROR (("Cannot open '%s'", path)); goto out; } buf[0] = '\0'; if (fgets (buf, sizeof (buf), f) == NULL) { - //HAL_ERROR (("Cannot read from '%s'", path)); + HAL_ERROR (("Cannot read from '%s'", path)); goto out; } @@ -368,7 +451,6 @@ ret = FALSE; if ((buf = hal_util_get_string_from_file (directory, file)) != NULL) { - errno = 0; value = strtod(buf, &end); if (errno != ERANGE) { ret = hal_device_property_set_double (d, key, value); @@ -379,47 +461,34 @@ } void -hal_util_make_udi_unique (HalDeviceStore *store, gchar *udi, gsize udisize, const char *original_udi) +hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...) { - int i; - - if (hal_device_store_find (store, original_udi) == NULL) { - g_strlcpy (udi, original_udi, udisize); - goto out; - } - - for (i = 0; ; i++) { - g_snprintf (udi, udisize, "%s_%d", original_udi, i); - if (hal_device_store_find (store, udi) == NULL) { - goto out; - } - } - -out: - ; -} + guint i; + va_list args; + gchar buf[256]; -void -hal_util_compute_udi_valist (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, va_list args) -{ - g_vsnprintf (dst, dstsize, format, args); + va_start (args, format); + g_vsnprintf (buf, sizeof (buf), format, args); + va_end (args); - g_strcanon (dst, + g_strcanon (buf, "/_" "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "1234567890", '_'); -} + g_strlcpy (dst, buf, dstsize); + if (hal_device_store_find (store, dst) == NULL) + goto out; -void -hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...) -{ - va_list args; + for (i = 0; ; i++) { + g_snprintf (dst, dstsize, "%s_%d", buf, i); + if (hal_device_store_find (store, dst) == NULL) + goto out; + } - va_start (args, format); - hal_util_compute_udi_valist (store, dst, dstsize, format, args); - va_end (args); +out: + ; } @@ -1056,7 +1125,7 @@ const char *buf = (const char *) mem; n = 0; - printf ("Dumping %u=0x%x bytes\n", size, size); + printf ("Dumping %d=0x%x bytes\n", size, size); while (n < size) { printf ("0x%04x: ", n); diff -ur hal-0.5.11/hald/util.h hal-0.5.11~git20080402/hald/util.h --- hal-0.5.11/hald/util.h 2008-05-08 00:24:10.000000000 +0100 +++ hal-0.5.11~git20080402/hald/util.h 2008-03-14 19:57:37.000000000 +0000 @@ -62,11 +62,11 @@ gboolean hal_util_set_string_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file); -gboolean hal_util_set_double_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file); +gboolean hal_util_get_bcd2_from_file (const gchar *directory, const gchar *file, gint *result); -void hal_util_make_udi_unique (HalDeviceStore *store, gchar *udi, gsize udisize, const char *original_udi); +gboolean hal_util_set_bcd2_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file); -void hal_util_compute_udi_valist (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, va_list args); +gboolean hal_util_set_double_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file); void hal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...); diff -ur hal-0.5.11/hald/util_pm.c hal-0.5.11~git20080402/hald/util_pm.c --- hal-0.5.11/hald/util_pm.c 2008-05-08 00:24:13.000000000 +0100 +++ hal-0.5.11~git20080402/hald/util_pm.c 2008-03-14 19:57:37.000000000 +0000 @@ -43,7 +43,7 @@ time_t last_time; } batteryInfo; -static GHashTable *saved_battery_info = NULL; +GHashTable *saved_battery_info = NULL; /** * util_get_battery_technology_ @@ -143,8 +143,10 @@ chargeRate = battery_info->last_chargeRate; } else { chargeRate = ((chargeLevel - battery_info->last_level) * 60 * 60) / (cur_time - battery_info->last_time); - /* During discharging chargeRate would be negative, which would mess - * up the the calculation below, so we make sure it's always positive. + /* + * During discharging chargeRate would be negative, which would + * mess up the the calculation below, so we make sure it's always + * positive. */ chargeRate = (chargeRate > 0) ? chargeRate : -chargeRate; @@ -190,10 +192,6 @@ else if (remaining_time > 60*60*60) { batteryInfo *battery_info; - /* to be sure saved_battery_info is initialised */ - if (!saved_battery_info) - saved_battery_info = g_hash_table_new(g_str_hash, g_str_equal); - if (!(battery_info = g_hash_table_lookup(saved_battery_info, id))) { battery_info = g_new0(batteryInfo, 1); g_hash_table_insert(saved_battery_info, (char*) id, battery_info);