1.1 --- a/librazor/rpm.c Thu Jul 02 11:31:03 2009 +0100
1.2 +++ b/librazor/rpm.c Mon Jul 06 18:19:13 2009 +0100
1.3 @@ -509,7 +509,7 @@
1.4 }
1.5
1.6 static const char *
1.7 -razor_rpm_get_details_type(struct razor_rpm *rpm, enum razor_detail_type type)
1.8 +razor_rpm_get_details_string(struct razor_rpm *rpm, enum razor_detail_type type)
1.9 {
1.10 switch(type) {
1.11 case RAZOR_DETAIL_NAME:
1.12 @@ -553,19 +553,39 @@
1.13 }
1.14 }
1.15
1.16 +static const char *const *
1.17 +razor_rpm_get_details_array(struct razor_rpm *rpm, enum razor_detail_type type)
1.18 +{
1.19 + switch(type) {
1.20 + case RAZOR_DETAIL_PREFIXES:
1.21 + return rpm->prefixes;
1.22 +
1.23 + default:
1.24 + /* Impossible */
1.25 + fprintf(stderr, "type %u not found\n", type);
1.26 + return NULL;
1.27 + }
1.28 +}
1.29 +
1.30 void
1.31 razor_rpm_get_details_varg(struct razor_rpm *rpm, va_list args)
1.32 {
1.33 int i;
1.34 enum razor_detail_type type;
1.35 - const char **data;
1.36 + const char **string;
1.37 + const char *const **array;
1.38
1.39 for (i = 0;; i += 2) {
1.40 type = va_arg(args, enum razor_detail_type);
1.41 if (type == RAZOR_DETAIL_LAST)
1.42 break;
1.43 - data = va_arg(args, const char **);
1.44 - *data = razor_rpm_get_details_type(rpm, type);
1.45 + if (type == RAZOR_DETAIL_PREFIXES) {
1.46 + array = va_arg(args, const char *const **);
1.47 + *array = razor_rpm_get_details_array(rpm, type);
1.48 + } else {
1.49 + string = va_arg(args, const char **);
1.50 + *string = razor_rpm_get_details_string(rpm, type);
1.51 + }
1.52 }
1.53 }
1.54
1.55 @@ -635,11 +655,12 @@
1.56
1.57 prefix = razor_rpm_get_indirect(rpm, RPMTAG_PREFIXES, &count);
1.58 if (prefix) {
1.59 - rpm->prefixes = calloc(count, sizeof *rpm->prefixes);
1.60 + rpm->prefixes = calloc(count + 1, sizeof *rpm->prefixes);
1.61 for (i = 0; i < count; i++) {
1.62 rpm->prefixes[i] = prefix;
1.63 prefix += strlen(prefix) + 1;
1.64 }
1.65 + rpm->prefixes[i] = NULL;
1.66 rpm->n_prefixes = count;
1.67 } else {
1.68 prefix = razor_rpm_get_indirect(rpm, RPMTAG_DEFAULTPREFIX,
1.69 @@ -935,7 +956,7 @@
1.70 struct razor_rpm *rpm = installer->rpm;
1.71 const char *script = NULL, *program = NULL, *prefix;
1.72 char buf[32], *p;
1.73 - struct array prefix_pool;
1.74 + struct environment env;
1.75
1.76 program = razor_rpm_get_indirect(rpm, program_tag, NULL);
1.77 script = razor_rpm_get_indirect(rpm, script_tag, NULL);
1.78 @@ -943,16 +964,14 @@
1.79 return 0;
1.80
1.81 if (rpm->relocations) {
1.82 - array_init(&prefix_pool);
1.83 + environment_init(&env);
1.84 for(i = 0; i < rpm->n_prefixes; i++) {
1.85 prefix = razor_relocations_apply(rpm->relocations,
1.86 rpm->prefixes[i]);
1.87 sprintf(buf, "RPM_INSTALL_PREFIX%d", i);
1.88 - p = array_add(&prefix_pool,
1.89 - strlen(buf) + strlen(prefix) + 2);
1.90 - sprintf(p, "%s=%s", buf, prefix);
1.91 - putenv(p);
1.92 + environment_add_variable(&env, buf, prefix);
1.93 }
1.94 + environment_set(&env);
1.95 }
1.96
1.97 if (program && strcmp(program, "<lua>") == 0)
1.98 @@ -961,11 +980,8 @@
1.99 retval = run_script_external(installer->root, program, script);
1.100
1.101 if (rpm->relocations) {
1.102 - for(i = 0; i < rpm->n_prefixes; i++) {
1.103 - sprintf(buf, "RPM_INSTALL_PREFIX%d=", i);
1.104 - putenv(buf);
1.105 - }
1.106 - array_release(&prefix_pool);
1.107 + environment_unset(&env);
1.108 + environment_release(&env);
1.109 }
1.110
1.111 return retval;