diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-09-28 22:34:46 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-09-28 22:34:46 +0000 |
commit | 1fec64812228f61d415c401a3bc8919ae28f98a1 (patch) | |
tree | 1d309a3e0fc1c6ee254a77ea4d000b503c7a214a | |
parent | f64b811576ab7c80cc80dd4d33f8ecc9fbc2e84d (diff) | |
download | busybox-w32-1fec64812228f61d415c401a3bc8919ae28f98a1.tar.gz busybox-w32-1fec64812228f61d415c401a3bc8919ae28f98a1.tar.bz2 busybox-w32-1fec64812228f61d415c401a3bc8919ae28f98a1.zip |
dpkg: reduce bss usage by ~130 kbytes (yes, kilobytes!)
at the cost of ~100 bytes of text.
Improves friendliness to nommu systems.
(Dunno whether nommu people ever use dpkg, though...)
git-svn-id: svn://busybox.net/trunk/busybox@16253 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | archival/dpkg.c | 163 | ||||
-rwxr-xr-x | scripts/objsizes | 2 |
2 files changed, 88 insertions, 77 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c index b7b1ef4a2..304400c84 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c | |||
@@ -42,7 +42,6 @@ | |||
42 | * I estimate it should be at least 50% bigger than PACKAGE_HASH_PRIME, | 42 | * I estimate it should be at least 50% bigger than PACKAGE_HASH_PRIME, |
43 | * as there a lot of duplicate version numbers */ | 43 | * as there a lot of duplicate version numbers */ |
44 | #define NAME_HASH_PRIME 16381 | 44 | #define NAME_HASH_PRIME 16381 |
45 | static char *name_hashtable[NAME_HASH_PRIME + 1]; | ||
46 | 45 | ||
47 | /* PACKAGE_HASH_PRIME, Maximum number of unique packages, | 46 | /* PACKAGE_HASH_PRIME, Maximum number of unique packages, |
48 | * It must not be smaller than STATUS_HASH_PRIME, | 47 | * It must not be smaller than STATUS_HASH_PRIME, |
@@ -66,7 +65,6 @@ typedef struct common_node_s { | |||
66 | unsigned int num_of_edges:14; | 65 | unsigned int num_of_edges:14; |
67 | edge_t **edge; | 66 | edge_t **edge; |
68 | } common_node_t; | 67 | } common_node_t; |
69 | static common_node_t *package_hashtable[PACKAGE_HASH_PRIME + 1]; | ||
70 | 68 | ||
71 | /* Currently it doesnt store packages that have state-status of not-installed | 69 | /* Currently it doesnt store packages that have state-status of not-installed |
72 | * So it only really has to be the size of the maximum number of packages | 70 | * So it only really has to be the size of the maximum number of packages |
@@ -76,7 +74,11 @@ typedef struct status_node_s { | |||
76 | unsigned int package:14; /* has to fit PACKAGE_HASH_PRIME */ | 74 | unsigned int package:14; /* has to fit PACKAGE_HASH_PRIME */ |
77 | unsigned int status:14; /* has to fit STATUS_HASH_PRIME */ | 75 | unsigned int status:14; /* has to fit STATUS_HASH_PRIME */ |
78 | } status_node_t; | 76 | } status_node_t; |
79 | static status_node_t *status_hashtable[STATUS_HASH_PRIME + 1]; | 77 | |
78 | /* Were statically declared here, but such a big bss is nommu-unfriendly */ | ||
79 | static char **name_hashtable; /* [NAME_HASH_PRIME + 1] */ | ||
80 | static common_node_t **package_hashtable; /* [PACKAGE_HASH_PRIME + 1] */ | ||
81 | static status_node_t **status_hashtable; /* [STATUS_HASH_PRIME + 1] */ | ||
80 | 82 | ||
81 | /* Even numbers are for 'extras', like ored dependencies or null */ | 83 | /* Even numbers are for 'extras', like ored dependencies or null */ |
82 | enum edge_type_e { | 84 | enum edge_type_e { |
@@ -129,7 +131,7 @@ static void make_hash(const char *key, unsigned int *start, unsigned int *decrem | |||
129 | 131 | ||
130 | /* Maybe i should have uses a "proper" hashing algorithm here instead | 132 | /* Maybe i should have uses a "proper" hashing algorithm here instead |
131 | * of making one up myself, seems to be working ok though. */ | 133 | * of making one up myself, seems to be working ok though. */ |
132 | for(i = 1; i < len; i++) { | 134 | for (i = 1; i < len; i++) { |
133 | /* shifts the ascii based value and adds it to previous value | 135 | /* shifts the ascii based value and adds it to previous value |
134 | * shift amount is mod 24 because long int is 32 bit and data | 136 | * shift amount is mod 24 because long int is 32 bit and data |
135 | * to be shifted is 8, don't want to shift data to where it has | 137 | * to be shifted is 8, don't want to shift data to where it has |
@@ -148,7 +150,7 @@ static int search_name_hashtable(const char *key) | |||
148 | // char *temp; | 150 | // char *temp; |
149 | 151 | ||
150 | make_hash(key, &probe_address, &probe_decrement, NAME_HASH_PRIME); | 152 | make_hash(key, &probe_address, &probe_decrement, NAME_HASH_PRIME); |
151 | while(name_hashtable[probe_address] != NULL) { | 153 | while (name_hashtable[probe_address] != NULL) { |
152 | if (strcmp(name_hashtable[probe_address], key) == 0) { | 154 | if (strcmp(name_hashtable[probe_address], key) == 0) { |
153 | return(probe_address); | 155 | return(probe_address); |
154 | } else { | 156 | } else { |
@@ -171,7 +173,7 @@ static unsigned int search_status_hashtable(const char *key) | |||
171 | unsigned int probe_decrement = 0; | 173 | unsigned int probe_decrement = 0; |
172 | 174 | ||
173 | make_hash(key, &probe_address, &probe_decrement, STATUS_HASH_PRIME); | 175 | make_hash(key, &probe_address, &probe_decrement, STATUS_HASH_PRIME); |
174 | while(status_hashtable[probe_address] != NULL) { | 176 | while (status_hashtable[probe_address] != NULL) { |
175 | if (strcmp(key, name_hashtable[package_hashtable[status_hashtable[probe_address]->package]->name]) == 0) { | 177 | if (strcmp(key, name_hashtable[package_hashtable[status_hashtable[probe_address]->package]->name]) == 0) { |
176 | break; | 178 | break; |
177 | } else { | 179 | } else { |
@@ -356,7 +358,7 @@ static int search_package_hashtable(const unsigned int name, const unsigned int | |||
356 | unsigned int probe_decrement = 0; | 358 | unsigned int probe_decrement = 0; |
357 | 359 | ||
358 | make_hash(name_hashtable[name], &probe_address, &probe_decrement, PACKAGE_HASH_PRIME); | 360 | make_hash(name_hashtable[name], &probe_address, &probe_decrement, PACKAGE_HASH_PRIME); |
359 | while(package_hashtable[probe_address] != NULL) { | 361 | while (package_hashtable[probe_address] != NULL) { |
360 | if (package_hashtable[probe_address]->name == name) { | 362 | if (package_hashtable[probe_address]->name == name) { |
361 | if (operator == VER_ANY) { | 363 | if (operator == VER_ANY) { |
362 | return(probe_address); | 364 | return(probe_address); |
@@ -394,9 +396,9 @@ static int search_for_provides(int needle, int start_at) { | |||
394 | common_node_t *p; | 396 | common_node_t *p; |
395 | for (i = start_at + 1; i < PACKAGE_HASH_PRIME; i++) { | 397 | for (i = start_at + 1; i < PACKAGE_HASH_PRIME; i++) { |
396 | p = package_hashtable[i]; | 398 | p = package_hashtable[i]; |
397 | if ( p == NULL ) continue; | 399 | if (p == NULL) continue; |
398 | for(j = 0; j < p->num_of_edges; j++) | 400 | for (j = 0; j < p->num_of_edges; j++) |
399 | if ( p->edge[j]->type == EDGE_PROVIDES && p->edge[j]->name == needle ) | 401 | if (p->edge[j]->type == EDGE_PROVIDES && p->edge[j]->name == needle) |
400 | return i; | 402 | return i; |
401 | } | 403 | } |
402 | return -1; | 404 | return -1; |
@@ -441,15 +443,15 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole | |||
441 | field += strspn(field, " "); | 443 | field += strspn(field, " "); |
442 | line2 = xstrdup(field); | 444 | line2 = xstrdup(field); |
443 | field2 = strtok_r(line2, "|", &line_ptr2); | 445 | field2 = strtok_r(line2, "|", &line_ptr2); |
444 | if ( (edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS) && | 446 | if ((edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS) && |
445 | (strcmp(field, field2) != 0)) { | 447 | (strcmp(field, field2) != 0)) { |
446 | or_edge = (edge_t *)xmalloc(sizeof(edge_t)); | 448 | or_edge = (edge_t *)xmalloc(sizeof(edge_t)); |
447 | or_edge->type = edge_type + 1; | 449 | or_edge->type = edge_type + 1; |
448 | } else { | 450 | } else { |
449 | or_edge = NULL; | 451 | or_edge = NULL; |
450 | } | 452 | } |
451 | 453 | ||
452 | if ( or_edge ) { | 454 | if (or_edge) { |
453 | or_edge->name = search_name_hashtable(field); | 455 | or_edge->name = search_name_hashtable(field); |
454 | or_edge->version = 0; // tracks the number of altenatives | 456 | or_edge->version = 0; // tracks the number of altenatives |
455 | 457 | ||
@@ -492,7 +494,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole | |||
492 | else if (strncmp(version, ">=", offset_ch) == 0) { | 494 | else if (strncmp(version, ">=", offset_ch) == 0) { |
493 | edge->operator = VER_MORE_EQUAL; | 495 | edge->operator = VER_MORE_EQUAL; |
494 | } else { | 496 | } else { |
495 | bb_error_msg_and_die("Illegal operator"); | 497 | bb_error_msg_and_die("illegal operator"); |
496 | } | 498 | } |
497 | } | 499 | } |
498 | /* skip to start of version numbers */ | 500 | /* skip to start of version numbers */ |
@@ -509,7 +511,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole | |||
509 | field2[strcspn(field2, " (")] = '\0'; | 511 | field2[strcspn(field2, " (")] = '\0'; |
510 | edge->name = search_name_hashtable(field2); | 512 | edge->name = search_name_hashtable(field2); |
511 | 513 | ||
512 | if ( or_edge ) | 514 | if (or_edge) |
513 | or_edge->version++; | 515 | or_edge->version++; |
514 | 516 | ||
515 | add_edge_to_node(parent_node, edge); | 517 | add_edge_to_node(parent_node, edge); |
@@ -756,23 +758,23 @@ static void set_status(const unsigned int status_node_num, const char *new_value | |||
756 | 758 | ||
757 | static const char *describe_status(int status_num) { | 759 | static const char *describe_status(int status_num) { |
758 | int status_want, status_state ; | 760 | int status_want, status_state ; |
759 | if ( status_hashtable[status_num] == NULL || status_hashtable[status_num]->status == 0 ) | 761 | if (status_hashtable[status_num] == NULL || status_hashtable[status_num]->status == 0) |
760 | return "is not installed or flagged to be installed\n"; | 762 | return "is not installed or flagged to be installed\n"; |
761 | 763 | ||
762 | status_want = get_status(status_num, 1); | 764 | status_want = get_status(status_num, 1); |
763 | status_state = get_status(status_num, 3); | 765 | status_state = get_status(status_num, 3); |
764 | 766 | ||
765 | if ( status_state == search_name_hashtable("installed") ) { | 767 | if (status_state == search_name_hashtable("installed")) { |
766 | if ( status_want == search_name_hashtable("install") ) | 768 | if (status_want == search_name_hashtable("install")) |
767 | return "is installed"; | 769 | return "is installed"; |
768 | if ( status_want == search_name_hashtable("deinstall") ) | 770 | if (status_want == search_name_hashtable("deinstall")) |
769 | return "is marked to be removed"; | 771 | return "is marked to be removed"; |
770 | if ( status_want == search_name_hashtable("purge") ) | 772 | if (status_want == search_name_hashtable("purge")) |
771 | return "is marked to be purged"; | 773 | return "is marked to be purged"; |
772 | } | 774 | } |
773 | if ( status_want == search_name_hashtable("unknown") ) | 775 | if (status_want == search_name_hashtable("unknown")) |
774 | return "is in an indeterminate state"; | 776 | return "is in an indeterminate state"; |
775 | if ( status_want == search_name_hashtable("install") ) | 777 | if (status_want == search_name_hashtable("install")) |
776 | return "is marked to be installed"; | 778 | return "is marked to be installed"; |
777 | 779 | ||
778 | return "is not installed or flagged to be installed"; | 780 | return "is not installed or flagged to be installed"; |
@@ -873,7 +875,7 @@ static void write_status_file(deb_file_t **deb_file) | |||
873 | (strcmp("unpacked", name_hashtable[state_status]) == 0)) { | 875 | (strcmp("unpacked", name_hashtable[state_status]) == 0)) { |
874 | /* We need to add the control file from the package */ | 876 | /* We need to add the control file from the package */ |
875 | i = 0; | 877 | i = 0; |
876 | while(deb_file[i] != NULL) { | 878 | while (deb_file[i] != NULL) { |
877 | if (strcmp(package_name, name_hashtable[package_hashtable[deb_file[i]->package]->name]) == 0) { | 879 | if (strcmp(package_name, name_hashtable[package_hashtable[deb_file[i]->package]->name]) == 0) { |
878 | /* Write a status file entry with a modified status */ | 880 | /* Write a status file entry with a modified status */ |
879 | /* remove trailing \n's */ | 881 | /* remove trailing \n's */ |
@@ -942,7 +944,7 @@ static void write_status_file(deb_file_t **deb_file) | |||
942 | } | 944 | } |
943 | 945 | ||
944 | /* Write any new packages */ | 946 | /* Write any new packages */ |
945 | for(i = 0; deb_file[i] != NULL; i++) { | 947 | for (i = 0; deb_file[i] != NULL; i++) { |
946 | status_num = search_status_hashtable(name_hashtable[package_hashtable[deb_file[i]->package]->name]); | 948 | status_num = search_status_hashtable(name_hashtable[package_hashtable[deb_file[i]->package]->name]); |
947 | if (strcmp("reinstreq", name_hashtable[get_status(status_num, 2)]) == 0) { | 949 | if (strcmp("reinstreq", name_hashtable[get_status(status_num, 2)]) == 0) { |
948 | write_buffer_no_status(new_status_file, deb_file[i]->control_file); | 950 | write_buffer_no_status(new_status_file, deb_file[i]->control_file); |
@@ -960,11 +962,11 @@ static void write_status_file(deb_file_t **deb_file) | |||
960 | xstat("/var/lib/dpkg/status", &stat_buf); | 962 | xstat("/var/lib/dpkg/status", &stat_buf); |
961 | /* Its ok if renaming the status file fails because status | 963 | /* Its ok if renaming the status file fails because status |
962 | * file doesnt exist, maybe we are starting from scratch */ | 964 | * file doesnt exist, maybe we are starting from scratch */ |
963 | bb_error_msg("No status file found, creating new one"); | 965 | bb_error_msg("no status file found, creating new one"); |
964 | } | 966 | } |
965 | 967 | ||
966 | if (rename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status") == -1) { | 968 | if (rename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status") == -1) { |
967 | bb_error_msg_and_die("DANGER: Couldnt create status file, you need to manually repair your status file"); | 969 | bb_error_msg_and_die("DANGER: Cannot create status file, you need to manually repair your status file"); |
968 | } | 970 | } |
969 | } | 971 | } |
970 | 972 | ||
@@ -982,7 +984,7 @@ static int package_satisfies_dependency(int package, int depend_type) | |||
982 | /* status could be unknown if package is a pure virtual | 984 | /* status could be unknown if package is a pure virtual |
983 | * provides which cannot satisfy any dependency by itself. | 985 | * provides which cannot satisfy any dependency by itself. |
984 | */ | 986 | */ |
985 | if ( status_hashtable[status_num] == NULL ) | 987 | if (status_hashtable[status_num] == NULL) |
986 | return 0; | 988 | return 0; |
987 | 989 | ||
988 | switch (depend_type) { | 990 | switch (depend_type) { |
@@ -1066,7 +1068,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count) | |||
1066 | } | 1068 | } |
1067 | 1069 | ||
1068 | if (result) { | 1070 | if (result) { |
1069 | bb_error_msg_and_die("Package %s conflicts with %s", | 1071 | bb_error_msg_and_die("package %s conflicts with %s", |
1070 | name_hashtable[package_node->name], | 1072 | name_hashtable[package_node->name], |
1071 | name_hashtable[package_edge->name]); | 1073 | name_hashtable[package_edge->name]); |
1072 | } | 1074 | } |
@@ -1087,7 +1089,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count) | |||
1087 | * package is a virtual one. In which case there are | 1089 | * package is a virtual one. In which case there are |
1088 | * no dependencies to check. | 1090 | * no dependencies to check. |
1089 | */ | 1091 | */ |
1090 | if ( package_node == NULL ) continue; | 1092 | if (package_node == NULL) continue; |
1091 | 1093 | ||
1092 | status_num = search_status_hashtable(name_hashtable[package_node->name]); | 1094 | status_num = search_status_hashtable(name_hashtable[package_node->name]); |
1093 | 1095 | ||
@@ -1095,7 +1097,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count) | |||
1095 | * virtual one provided by something else. In which | 1097 | * virtual one provided by something else. In which |
1096 | * case there are no dependencies to check. | 1098 | * case there are no dependencies to check. |
1097 | */ | 1099 | */ |
1098 | if ( status_hashtable[status_num] == NULL ) continue; | 1100 | if (status_hashtable[status_num] == NULL) continue; |
1099 | 1101 | ||
1100 | /* If we don't want this package installed then we may | 1102 | /* If we don't want this package installed then we may |
1101 | * as well ignore it's dependencies. | 1103 | * as well ignore it's dependencies. |
@@ -1112,12 +1114,12 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count) | |||
1112 | const edge_t *package_edge = package_node->edge[j]; | 1114 | const edge_t *package_edge = package_node->edge[j]; |
1113 | unsigned int package_num; | 1115 | unsigned int package_num; |
1114 | 1116 | ||
1115 | if ( package_edge->type == EDGE_OR_PRE_DEPENDS || | 1117 | if (package_edge->type == EDGE_OR_PRE_DEPENDS || |
1116 | package_edge->type == EDGE_OR_DEPENDS ) { /* start an EDGE_OR_ list */ | 1118 | package_edge->type == EDGE_OR_DEPENDS) { /* start an EDGE_OR_ list */ |
1117 | number_of_alternatives = package_edge->version; | 1119 | number_of_alternatives = package_edge->version; |
1118 | root_of_alternatives = package_edge; | 1120 | root_of_alternatives = package_edge; |
1119 | continue; | 1121 | continue; |
1120 | } else if ( number_of_alternatives == 0 ) { /* not in the middle of an EDGE_OR_ list */ | 1122 | } else if (number_of_alternatives == 0) { /* not in the middle of an EDGE_OR_ list */ |
1121 | number_of_alternatives = 1; | 1123 | number_of_alternatives = 1; |
1122 | root_of_alternatives = NULL; | 1124 | root_of_alternatives = NULL; |
1123 | } | 1125 | } |
@@ -1125,7 +1127,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count) | |||
1125 | package_num = search_package_hashtable(package_edge->name, package_edge->version, package_edge->operator); | 1127 | package_num = search_package_hashtable(package_edge->name, package_edge->version, package_edge->operator); |
1126 | 1128 | ||
1127 | if (package_edge->type == EDGE_PRE_DEPENDS || | 1129 | if (package_edge->type == EDGE_PRE_DEPENDS || |
1128 | package_edge->type == EDGE_DEPENDS ) { | 1130 | package_edge->type == EDGE_DEPENDS) { |
1129 | int result=1; | 1131 | int result=1; |
1130 | status_num = 0; | 1132 | status_num = 0; |
1131 | 1133 | ||
@@ -1135,8 +1137,8 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count) | |||
1135 | * EDGE_DEPENDS == OR_DEPENDS -1 | 1137 | * EDGE_DEPENDS == OR_DEPENDS -1 |
1136 | * EDGE_PRE_DEPENDS == OR_PRE_DEPENDS -1 | 1138 | * EDGE_PRE_DEPENDS == OR_PRE_DEPENDS -1 |
1137 | */ | 1139 | */ |
1138 | if ( root_of_alternatives && package_edge->type != root_of_alternatives->type - 1) | 1140 | if (root_of_alternatives && package_edge->type != root_of_alternatives->type - 1) |
1139 | bb_error_msg_and_die("Fatal error. Package dependencies corrupt: %d != %d - 1", | 1141 | bb_error_msg_and_die("fatal error, package dependencies corrupt: %d != %d - 1", |
1140 | package_edge->type, root_of_alternatives->type); | 1142 | package_edge->type, root_of_alternatives->type); |
1141 | 1143 | ||
1142 | if (package_hashtable[package_num] != NULL) | 1144 | if (package_hashtable[package_num] != NULL) |
@@ -1145,14 +1147,14 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count) | |||
1145 | if (result) { /* check for other package which provide what we are looking for */ | 1147 | if (result) { /* check for other package which provide what we are looking for */ |
1146 | int provider = -1; | 1148 | int provider = -1; |
1147 | 1149 | ||
1148 | while ( (provider = search_for_provides(package_edge->name, provider) ) > -1 ) { | 1150 | while ((provider = search_for_provides(package_edge->name, provider)) > -1) { |
1149 | if ( package_hashtable[provider] == NULL ) { | 1151 | if (package_hashtable[provider] == NULL) { |
1150 | printf("Have a provider but no package information for it\n"); | 1152 | puts("Have a provider but no package information for it"); |
1151 | continue; | 1153 | continue; |
1152 | } | 1154 | } |
1153 | result = !package_satisfies_dependency(provider, package_edge->type); | 1155 | result = !package_satisfies_dependency(provider, package_edge->type); |
1154 | 1156 | ||
1155 | if ( result == 0 ) | 1157 | if (result == 0) |
1156 | break; | 1158 | break; |
1157 | } | 1159 | } |
1158 | } | 1160 | } |
@@ -1160,21 +1162,21 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count) | |||
1160 | /* It must be already installed, or to be installed */ | 1162 | /* It must be already installed, or to be installed */ |
1161 | number_of_alternatives--; | 1163 | number_of_alternatives--; |
1162 | if (result && number_of_alternatives == 0) { | 1164 | if (result && number_of_alternatives == 0) { |
1163 | if ( root_of_alternatives ) | 1165 | if (root_of_alternatives) |
1164 | bb_error_msg_and_die( | 1166 | bb_error_msg_and_die( |
1165 | "Package %s %sdepends on %s, " | 1167 | "package %s %sdepends on %s, " |
1166 | "which cannot be satisfied", | 1168 | "which cannot be satisfied", |
1167 | name_hashtable[package_node->name], | 1169 | name_hashtable[package_node->name], |
1168 | package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "", | 1170 | package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "", |
1169 | name_hashtable[root_of_alternatives->name]); | 1171 | name_hashtable[root_of_alternatives->name]); |
1170 | else | 1172 | else |
1171 | bb_error_msg_and_die( | 1173 | bb_error_msg_and_die( |
1172 | "Package %s %sdepends on %s, which %s\n", | 1174 | "package %s %sdepends on %s, which %s\n", |
1173 | name_hashtable[package_node->name], | 1175 | name_hashtable[package_node->name], |
1174 | package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "", | 1176 | package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "", |
1175 | name_hashtable[package_edge->name], | 1177 | name_hashtable[package_edge->name], |
1176 | describe_status(status_num)); | 1178 | describe_status(status_num)); |
1177 | } else if ( result == 0 && number_of_alternatives ) { | 1179 | } else if (result == 0 && number_of_alternatives) { |
1178 | /* we've found a package which | 1180 | /* we've found a package which |
1179 | * satisfies the dependency, | 1181 | * satisfies the dependency, |
1180 | * so skip over the rest of | 1182 | * so skip over the rest of |
@@ -1310,8 +1312,8 @@ static void list_packages(void) | |||
1310 | { | 1312 | { |
1311 | int i; | 1313 | int i; |
1312 | 1314 | ||
1313 | printf(" Name Version\n"); | 1315 | puts(" Name Version"); |
1314 | printf("+++-==============-==============\n"); | 1316 | puts("+++-==============-=============="); |
1315 | 1317 | ||
1316 | /* go through status hash, dereference package hash and finally strings */ | 1318 | /* go through status hash, dereference package hash and finally strings */ |
1317 | for (i=0; i<STATUS_HASH_PRIME+1; i++) { | 1319 | for (i=0; i<STATUS_HASH_PRIME+1; i++) { |
@@ -1355,8 +1357,8 @@ static void remove_package(const unsigned int package_num, int noisy) | |||
1355 | char conffile_name[package_name_length + 30]; | 1357 | char conffile_name[package_name_length + 30]; |
1356 | int return_value; | 1358 | int return_value; |
1357 | 1359 | ||
1358 | if ( noisy ) | 1360 | if (noisy) |
1359 | printf("Removing %s (%s) ...\n", package_name, package_version); | 1361 | printf("Removing %s (%s)...\n", package_name, package_version); |
1360 | 1362 | ||
1361 | /* run prerm script */ | 1363 | /* run prerm script */ |
1362 | return_value = run_package_script(package_name, "prerm"); | 1364 | return_value = run_package_script(package_name, "prerm"); |
@@ -1404,7 +1406,7 @@ static void purge_package(const unsigned int package_num) | |||
1404 | char **exclude_files; | 1406 | char **exclude_files; |
1405 | char list_name[strlen(package_name) + 25]; | 1407 | char list_name[strlen(package_name) + 25]; |
1406 | 1408 | ||
1407 | printf("Purging %s (%s) ...\n", package_name, package_version); | 1409 | printf("Purging %s (%s)...\n", package_name, package_version); |
1408 | 1410 | ||
1409 | /* run prerm script */ | 1411 | /* run prerm script */ |
1410 | if (run_package_script(package_name, "prerm") != 0) { | 1412 | if (run_package_script(package_name, "prerm") != 0) { |
@@ -1531,12 +1533,12 @@ static void unpack_package(deb_file_t *deb_file) | |||
1531 | /* If existing version, remove it first */ | 1533 | /* If existing version, remove it first */ |
1532 | if (strcmp(name_hashtable[get_status(status_num, 3)], "installed") == 0) { | 1534 | if (strcmp(name_hashtable[get_status(status_num, 3)], "installed") == 0) { |
1533 | /* Package is already installed, remove old version first */ | 1535 | /* Package is already installed, remove old version first */ |
1534 | printf("Preparing to replace %s %s (using %s) ...\n", package_name, | 1536 | printf("Preparing to replace %s %s (using %s)...\n", package_name, |
1535 | name_hashtable[package_hashtable[status_package_num]->version], | 1537 | name_hashtable[package_hashtable[status_package_num]->version], |
1536 | deb_file->filename); | 1538 | deb_file->filename); |
1537 | remove_package(status_package_num, 0); | 1539 | remove_package(status_package_num, 0); |
1538 | } else { | 1540 | } else { |
1539 | printf("Unpacking %s (from %s) ...\n", package_name, deb_file->filename); | 1541 | printf("Unpacking %s (from %s)...\n", package_name, deb_file->filename); |
1540 | } | 1542 | } |
1541 | 1543 | ||
1542 | /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */ | 1544 | /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */ |
@@ -1544,7 +1546,7 @@ static void unpack_package(deb_file_t *deb_file) | |||
1544 | archive_handle = init_archive_deb_ar(deb_file->filename); | 1546 | archive_handle = init_archive_deb_ar(deb_file->filename); |
1545 | init_archive_deb_control(archive_handle); | 1547 | init_archive_deb_control(archive_handle); |
1546 | 1548 | ||
1547 | while(all_control_files[i]) { | 1549 | while (all_control_files[i]) { |
1548 | char *c = xasprintf("./%s", all_control_files[i]); | 1550 | char *c = xasprintf("./%s", all_control_files[i]); |
1549 | llist_add_to(&accept_list, c); | 1551 | llist_add_to(&accept_list, c); |
1550 | i++; | 1552 | i++; |
@@ -1559,7 +1561,7 @@ static void unpack_package(deb_file_t *deb_file) | |||
1559 | /* Run the preinst prior to extracting */ | 1561 | /* Run the preinst prior to extracting */ |
1560 | if (run_package_script(package_name, "preinst") != 0) { | 1562 | if (run_package_script(package_name, "preinst") != 0) { |
1561 | /* when preinst returns exit code != 0 then quit installation process */ | 1563 | /* when preinst returns exit code != 0 then quit installation process */ |
1562 | bb_error_msg_and_die("subprocess pre-installation script returned error."); | 1564 | bb_error_msg_and_die("subprocess pre-installation script returned error"); |
1563 | } | 1565 | } |
1564 | 1566 | ||
1565 | /* Extract data.tar.gz to the root directory */ | 1567 | /* Extract data.tar.gz to the root directory */ |
@@ -1595,7 +1597,7 @@ static void configure_package(deb_file_t *deb_file) | |||
1595 | const char *package_version = name_hashtable[package_hashtable[deb_file->package]->version]; | 1597 | const char *package_version = name_hashtable[package_hashtable[deb_file->package]->version]; |
1596 | const int status_num = search_status_hashtable(package_name); | 1598 | const int status_num = search_status_hashtable(package_name); |
1597 | 1599 | ||
1598 | printf("Setting up %s (%s) ...\n", package_name, package_version); | 1600 | printf("Setting up %s (%s)...\n", package_name, package_version); |
1599 | 1601 | ||
1600 | /* Run the postinst script */ | 1602 | /* Run the postinst script */ |
1601 | if (run_package_script(package_name, "postinst") != 0) { | 1603 | if (run_package_script(package_name, "postinst") != 0) { |
@@ -1619,6 +1621,10 @@ int dpkg_main(int argc, char **argv) | |||
1619 | int status_num; | 1621 | int status_num; |
1620 | int i; | 1622 | int i; |
1621 | 1623 | ||
1624 | name_hashtable = xzalloc(sizeof(name_hashtable[0]) * (NAME_HASH_PRIME + 1)); | ||
1625 | package_hashtable = xzalloc(sizeof(package_hashtable[0]) * (PACKAGE_HASH_PRIME + 1)); | ||
1626 | status_hashtable = xzalloc(sizeof(status_hashtable[0]) * (STATUS_HASH_PRIME + 1)); | ||
1627 | |||
1622 | while ((opt = getopt(argc, argv, "CF:ilPru")) != -1) { | 1628 | while ((opt = getopt(argc, argv, "CF:ilPru")) != -1) { |
1623 | switch (opt) { | 1629 | switch (opt) { |
1624 | case 'C': // equivalent to --configure in official dpkg | 1630 | case 'C': // equivalent to --configure in official dpkg |
@@ -1682,13 +1688,13 @@ int dpkg_main(int argc, char **argv) | |||
1682 | init_archive_deb_control(archive_handle); | 1688 | init_archive_deb_control(archive_handle); |
1683 | deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list); | 1689 | deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list); |
1684 | if (deb_file[deb_count]->control_file == NULL) { | 1690 | if (deb_file[deb_count]->control_file == NULL) { |
1685 | bb_error_msg_and_die("Couldnt extract control file"); | 1691 | bb_error_msg_and_die("cannot extract control file"); |
1686 | } | 1692 | } |
1687 | deb_file[deb_count]->filename = xstrdup(argv[optind]); | 1693 | deb_file[deb_count]->filename = xstrdup(argv[optind]); |
1688 | package_num = fill_package_struct(deb_file[deb_count]->control_file); | 1694 | package_num = fill_package_struct(deb_file[deb_count]->control_file); |
1689 | 1695 | ||
1690 | if (package_num == -1) { | 1696 | if (package_num == -1) { |
1691 | bb_error_msg("Invalid control file in %s", argv[optind]); | 1697 | bb_error_msg("invalid control file in %s", argv[optind]); |
1692 | optind++; | 1698 | optind++; |
1693 | continue; | 1699 | continue; |
1694 | } | 1700 | } |
@@ -1718,7 +1724,7 @@ int dpkg_main(int argc, char **argv) | |||
1718 | search_name_hashtable(argv[optind]), | 1724 | search_name_hashtable(argv[optind]), |
1719 | search_name_hashtable("ANY"), VER_ANY); | 1725 | search_name_hashtable("ANY"), VER_ANY); |
1720 | if (package_hashtable[deb_file[deb_count]->package] == NULL) { | 1726 | if (package_hashtable[deb_file[deb_count]->package] == NULL) { |
1721 | bb_error_msg_and_die("Package %s is uninstalled or unknown", argv[optind]); | 1727 | bb_error_msg_and_die("package %s is uninstalled or unknown", argv[optind]); |
1722 | } | 1728 | } |
1723 | package_num = deb_file[deb_count]->package; | 1729 | package_num = deb_file[deb_count]->package; |
1724 | status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]); | 1730 | status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]); |
@@ -1728,14 +1734,14 @@ int dpkg_main(int argc, char **argv) | |||
1728 | if (dpkg_opt & dpkg_opt_remove) { | 1734 | if (dpkg_opt & dpkg_opt_remove) { |
1729 | if ((strcmp(name_hashtable[state_status], "not-installed") == 0) || | 1735 | if ((strcmp(name_hashtable[state_status], "not-installed") == 0) || |
1730 | (strcmp(name_hashtable[state_status], "config-files") == 0)) { | 1736 | (strcmp(name_hashtable[state_status], "config-files") == 0)) { |
1731 | bb_error_msg_and_die("%s is already removed.", name_hashtable[package_hashtable[package_num]->name]); | 1737 | bb_error_msg_and_die("%s is already removed", name_hashtable[package_hashtable[package_num]->name]); |
1732 | } | 1738 | } |
1733 | set_status(status_num, "deinstall", 1); | 1739 | set_status(status_num, "deinstall", 1); |
1734 | } | 1740 | } |
1735 | else if (dpkg_opt & dpkg_opt_purge) { | 1741 | else if (dpkg_opt & dpkg_opt_purge) { |
1736 | /* if package status is "conf-files" then its ok */ | 1742 | /* if package status is "conf-files" then its ok */ |
1737 | if (strcmp(name_hashtable[state_status], "not-installed") == 0) { | 1743 | if (strcmp(name_hashtable[state_status], "not-installed") == 0) { |
1738 | bb_error_msg_and_die("%s is already purged.", name_hashtable[package_hashtable[package_num]->name]); | 1744 | bb_error_msg_and_die("%s is already purged", name_hashtable[package_hashtable[package_num]->name]); |
1739 | } | 1745 | } |
1740 | set_status(status_num, "purge", 1); | 1746 | set_status(status_num, "purge", 1); |
1741 | } | 1747 | } |
@@ -1748,7 +1754,7 @@ int dpkg_main(int argc, char **argv) | |||
1748 | /* Check that the deb file arguments are installable */ | 1754 | /* Check that the deb file arguments are installable */ |
1749 | if ((dpkg_opt & dpkg_opt_force_ignore_depends) != dpkg_opt_force_ignore_depends) { | 1755 | if ((dpkg_opt & dpkg_opt_force_ignore_depends) != dpkg_opt_force_ignore_depends) { |
1750 | if (!check_deps(deb_file, 0, deb_count)) { | 1756 | if (!check_deps(deb_file, 0, deb_count)) { |
1751 | bb_error_msg_and_die("Dependency check failed"); | 1757 | bb_error_msg_and_die("dependency check failed"); |
1752 | } | 1758 | } |
1753 | } | 1759 | } |
1754 | 1760 | ||
@@ -1780,28 +1786,33 @@ int dpkg_main(int argc, char **argv) | |||
1780 | 1786 | ||
1781 | write_status_file(deb_file); | 1787 | write_status_file(deb_file); |
1782 | 1788 | ||
1783 | for (i = 0; i < deb_count; i++) { | 1789 | if (ENABLE_FEATURE_CLEAN_UP) { |
1784 | free(deb_file[i]->control_file); | 1790 | for (i = 0; i < deb_count; i++) { |
1785 | free(deb_file[i]->filename); | 1791 | free(deb_file[i]->control_file); |
1786 | free(deb_file[i]); | 1792 | free(deb_file[i]->filename); |
1787 | } | 1793 | free(deb_file[i]); |
1794 | } | ||
1788 | 1795 | ||
1789 | free(deb_file); | 1796 | free(deb_file); |
1790 | 1797 | ||
1791 | for (i = 0; i < NAME_HASH_PRIME; i++) { | 1798 | for (i = 0; i < NAME_HASH_PRIME; i++) { |
1792 | free(name_hashtable[i]); | 1799 | free(name_hashtable[i]); |
1793 | } | 1800 | } |
1794 | 1801 | ||
1795 | for (i = 0; i < PACKAGE_HASH_PRIME; i++) { | 1802 | for (i = 0; i < PACKAGE_HASH_PRIME; i++) { |
1796 | if (package_hashtable[i] != NULL) { | 1803 | if (package_hashtable[i] != NULL) { |
1797 | free_package(package_hashtable[i]); | 1804 | free_package(package_hashtable[i]); |
1805 | } | ||
1798 | } | 1806 | } |
1799 | } | ||
1800 | 1807 | ||
1801 | for (i = 0; i < STATUS_HASH_PRIME; i++) { | 1808 | for (i = 0; i < STATUS_HASH_PRIME; i++) { |
1802 | free(status_hashtable[i]); | 1809 | free(status_hashtable[i]); |
1810 | } | ||
1811 | |||
1812 | free(status_hashtable); | ||
1813 | free(package_hashtable); | ||
1814 | free(name_hashtable); | ||
1803 | } | 1815 | } |
1804 | 1816 | ||
1805 | return(EXIT_SUCCESS); | 1817 | return(EXIT_SUCCESS); |
1806 | } | 1818 | } |
1807 | |||
diff --git a/scripts/objsizes b/scripts/objsizes index ec9928238..4f6576d9a 100755 --- a/scripts/objsizes +++ b/scripts/objsizes | |||
@@ -4,4 +4,4 @@ printf "%9s %11s %9s %9s %s\n" "text+data" text+rodata rwdata bss filename | |||
4 | find -name '*.o' | sed 's:^\./::' | xargs size | grep '^ *[0-9]' \ | 4 | find -name '*.o' | sed 's:^\./::' | xargs size | grep '^ *[0-9]' \ |
5 | | while read text data bss dec hex filename; do | 5 | | while read text data bss dec hex filename; do |
6 | printf "%9d %11d %9d %9d %s\n" $((text+data)) $text $data $bss "$filename" | 6 | printf "%9d %11d %9d %9d %s\n" $((text+data)) $text $data $bss "$filename" |
7 | done | 7 | done | sort -r |