static char *uuid_parse_dmidecode(FILE *file) { char line[1024]; while (fgets(line, sizeof(line), file) != NULL) { char *fields[4]; int fields_num; strstripnewline(line); /* Look for a line reading: * UUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX */ fields_num = strsplit(line, fields, STATIC_ARRAY_SIZE(fields)); if (fields_num != 2) continue; if (strcmp("UUID:", fields[0]) != 0) continue; if (!looks_like_a_uuid(fields[1])) continue; return strdup(fields[1]); } return NULL; }
static char * uuid_parse_dmidecode(FILE *file) { char line[1024]; int inSysInfo = 0; for (;;) { if (!fgets(line, sizeof(line)/sizeof(char), file)) { return NULL; } if (strncmp(line, HANDLE_PREFIX, (sizeof(HANDLE_PREFIX)/sizeof(char))-1) == 0) { /*printf("Got handle %s\n", line);*/ inSysInfo = 0; } else if (strncmp(line, SYSINFO_PREFIX, (sizeof(SYSINFO_PREFIX)/sizeof(char))-1) == 0) { /*printf("Got system info %s\n", line);*/ inSysInfo = 1; } else if (strncmp(line, ALT_SYSINFO_PREFIX, (sizeof(ALT_SYSINFO_PREFIX)/sizeof(char))-1) == 0) { /*printf("Got alt system info %s\n", line);*/ inSysInfo = 1; } if (inSysInfo) { if (strncmp(line, UUID_PREFIX, (sizeof(UUID_PREFIX)/sizeof(char))-1) == 0) { char *uuid = line + (sizeof(UUID_PREFIX)/sizeof(char)); /*printf("Got uuid [%s]\n", uuid);*/ if (looks_like_a_uuid (uuid)) return strdup (uuid); } if (strncmp(line, ALT_UUID_PREFIX, (sizeof(ALT_UUID_PREFIX)/sizeof(char))-1) == 0) { char *uuid = line + (sizeof(ALT_UUID_PREFIX)/sizeof(char)); /*printf("Got alt uuid [%s]\n", uuid);*/ if (looks_like_a_uuid (uuid)) return strdup (uuid); } } } return NULL; }
static char * uuid_get_from_hal(void) { LibHalContext *ctx; DBusError error; DBusConnection *con; dbus_error_init(&error); if (!(con = dbus_bus_get(DBUS_BUS_SYSTEM, &error)) ) { goto bailout_nobus; } ctx = libhal_ctx_new(); libhal_ctx_set_dbus_connection(ctx, con); if (!libhal_ctx_init(ctx, &error)) { goto bailout; } if (!libhal_device_property_exists(ctx, UUID_PATH, UUID_PROPERTY, &error)) { goto bailout; } char *uuid = libhal_device_get_property_string(ctx, UUID_PATH, UUID_PROPERTY, &error); if (looks_like_a_uuid (uuid)) { return uuid; } bailout: { DBusError ctxerror; dbus_error_init(&ctxerror); if (!(libhal_ctx_shutdown(ctx, &ctxerror))) { dbus_error_free(&ctxerror); } } libhal_ctx_free(ctx); //dbus_connection_unref(con); bailout_nobus: if (dbus_error_is_set(&error)) { /*printf("Error %s\n", error.name);*/ dbus_error_free(&error); } return NULL; }