diff -r a3e288343fe7 -r c903635ae422 librazor/rpm.c --- a/librazor/rpm.c Thu Jul 02 11:31:03 2009 +0100 +++ b/librazor/rpm.c Mon Jul 06 18:19:13 2009 +0100 @@ -509,7 +509,7 @@ } static const char * -razor_rpm_get_details_type(struct razor_rpm *rpm, enum razor_detail_type type) +razor_rpm_get_details_string(struct razor_rpm *rpm, enum razor_detail_type type) { switch(type) { case RAZOR_DETAIL_NAME: @@ -553,19 +553,39 @@ } } +static const char *const * +razor_rpm_get_details_array(struct razor_rpm *rpm, enum razor_detail_type type) +{ + switch(type) { + case RAZOR_DETAIL_PREFIXES: + return rpm->prefixes; + + default: + /* Impossible */ + fprintf(stderr, "type %u not found\n", type); + return NULL; + } +} + void razor_rpm_get_details_varg(struct razor_rpm *rpm, va_list args) { int i; enum razor_detail_type type; - const char **data; + const char **string; + const char *const **array; for (i = 0;; i += 2) { type = va_arg(args, enum razor_detail_type); if (type == RAZOR_DETAIL_LAST) break; - data = va_arg(args, const char **); - *data = razor_rpm_get_details_type(rpm, type); + if (type == RAZOR_DETAIL_PREFIXES) { + array = va_arg(args, const char *const **); + *array = razor_rpm_get_details_array(rpm, type); + } else { + string = va_arg(args, const char **); + *string = razor_rpm_get_details_string(rpm, type); + } } } @@ -635,11 +655,12 @@ prefix = razor_rpm_get_indirect(rpm, RPMTAG_PREFIXES, &count); if (prefix) { - rpm->prefixes = calloc(count, sizeof *rpm->prefixes); + rpm->prefixes = calloc(count + 1, sizeof *rpm->prefixes); for (i = 0; i < count; i++) { rpm->prefixes[i] = prefix; prefix += strlen(prefix) + 1; } + rpm->prefixes[i] = NULL; rpm->n_prefixes = count; } else { prefix = razor_rpm_get_indirect(rpm, RPMTAG_DEFAULTPREFIX, @@ -935,7 +956,7 @@ struct razor_rpm *rpm = installer->rpm; const char *script = NULL, *program = NULL, *prefix; char buf[32], *p; - struct array prefix_pool; + struct environment env; program = razor_rpm_get_indirect(rpm, program_tag, NULL); script = razor_rpm_get_indirect(rpm, script_tag, NULL); @@ -943,16 +964,14 @@ return 0; if (rpm->relocations) { - array_init(&prefix_pool); + environment_init(&env); for(i = 0; i < rpm->n_prefixes; i++) { prefix = razor_relocations_apply(rpm->relocations, rpm->prefixes[i]); sprintf(buf, "RPM_INSTALL_PREFIX%d", i); - p = array_add(&prefix_pool, - strlen(buf) + strlen(prefix) + 2); - sprintf(p, "%s=%s", buf, prefix); - putenv(p); + environment_add_variable(&env, buf, prefix); } + environment_set(&env); } if (program && strcmp(program, "") == 0) @@ -961,11 +980,8 @@ retval = run_script_external(installer->root, program, script); if (rpm->relocations) { - for(i = 0; i < rpm->n_prefixes; i++) { - sprintf(buf, "RPM_INSTALL_PREFIX%d=", i); - putenv(buf); - } - array_release(&prefix_pool); + environment_unset(&env); + environment_release(&env); } return retval;