aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-21 22:46:58 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-21 22:46:58 +0000
commitd235f58ac27d6eda32e5106700e76352e31aa511 (patch)
tree8fe8eea866f60e6725f8a26c5ea15ab23ff4e864
parent20273138fcd7b93a7743ea7fcbef775c5af2908c (diff)
downloadbusybox-w32-d235f58ac27d6eda32e5106700e76352e31aa511.tar.gz
busybox-w32-d235f58ac27d6eda32e5106700e76352e31aa511.tar.bz2
busybox-w32-d235f58ac27d6eda32e5106700e76352e31aa511.zip
dpkg: code shrink
dpkg: add documentation from bug 3644 function old new delta remove_package 318 333 +15 unpack_package 541 552 +11 purge_package 242 247 +5 all_control_list 55 53 -2 all_control_files 44 40 -4 add_split_dependencies 709 703 -6 search_status_hashtable 148 133 -15 search_package_hashtable 137 122 -15 search_name_hashtable 134 118 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/6 up/down: 31/-58) Total: -27 bytes text data bss dec hex filename 808093 611 6924 815628 c720c busybox_old 807972 611 6924 815507 c7193 busybox_unstripped
-rw-r--r--archival/dpkg.c94
1 files changed, 61 insertions, 33 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c
index 0b473b05b..ac5f76a47 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -124,7 +124,7 @@ static void make_hash(const char *key, unsigned *start, unsigned *decrement, con
124 * shift amount is mod 24 because long int is 32 bit and data 124 * shift amount is mod 24 because long int is 32 bit and data
125 * to be shifted is 8, don't want to shift data to where it has 125 * to be shifted is 8, don't want to shift data to where it has
126 * no effect*/ 126 * no effect*/
127 hash_num += ((key[i] + key[i-1]) << ((key[i] * i) % 24)); 127 hash_num += (key[i] + key[i-1]) << ((key[i] * i) % 24);
128 } 128 }
129 *start = (unsigned) hash_num % hash_prime; 129 *start = (unsigned) hash_num % hash_prime;
130 *decrement = (unsigned) 1 + (hash_num % (hash_prime - 1)); 130 *decrement = (unsigned) 1 + (hash_num % (hash_prime - 1));
@@ -133,8 +133,8 @@ static void make_hash(const char *key, unsigned *start, unsigned *decrement, con
133/* this adds the key to the hash table */ 133/* this adds the key to the hash table */
134static int search_name_hashtable(const char *key) 134static int search_name_hashtable(const char *key)
135{ 135{
136 unsigned probe_address = 0; 136 unsigned probe_address;
137 unsigned probe_decrement = 0; 137 unsigned probe_decrement;
138 138
139 make_hash(key, &probe_address, &probe_decrement, NAME_HASH_PRIME); 139 make_hash(key, &probe_address, &probe_decrement, NAME_HASH_PRIME);
140 while (name_hashtable[probe_address] != NULL) { 140 while (name_hashtable[probe_address] != NULL) {
@@ -155,8 +155,8 @@ static int search_name_hashtable(const char *key)
155 */ 155 */
156static unsigned search_status_hashtable(const char *key) 156static unsigned search_status_hashtable(const char *key)
157{ 157{
158 unsigned probe_address = 0; 158 unsigned probe_address;
159 unsigned probe_decrement = 0; 159 unsigned probe_decrement;
160 160
161 make_hash(key, &probe_address, &probe_decrement, STATUS_HASH_PRIME); 161 make_hash(key, &probe_address, &probe_decrement, STATUS_HASH_PRIME);
162 while (status_hashtable[probe_address] != NULL) { 162 while (status_hashtable[probe_address] != NULL) {
@@ -315,8 +315,8 @@ static int test_version(const unsigned version1, const unsigned version2, const
315 315
316static int search_package_hashtable(const unsigned name, const unsigned version, const unsigned operator) 316static int search_package_hashtable(const unsigned name, const unsigned version, const unsigned operator)
317{ 317{
318 unsigned probe_address = 0; 318 unsigned probe_address;
319 unsigned probe_decrement = 0; 319 unsigned probe_decrement;
320 320
321 make_hash(name_hashtable[name], &probe_address, &probe_decrement, PACKAGE_HASH_PRIME); 321 make_hash(name_hashtable[name], &probe_address, &probe_decrement, PACKAGE_HASH_PRIME);
322 while (package_hashtable[probe_address] != NULL) { 322 while (package_hashtable[probe_address] != NULL) {
@@ -410,10 +410,10 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
410 if ((edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS) 410 if ((edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS)
411 && (strcmp(field, field2) != 0) 411 && (strcmp(field, field2) != 0)
412 ) { 412 ) {
413 or_edge = xmalloc(sizeof(edge_t)); 413 or_edge = xzalloc(sizeof(edge_t));
414 or_edge->type = edge_type + 1; 414 or_edge->type = edge_type + 1;
415 or_edge->name = search_name_hashtable(field); 415 or_edge->name = search_name_hashtable(field);
416 or_edge->version = 0; // tracks the number of alternatives 416 //or_edge->version = 0; // tracks the number of alternatives
417 add_edge_to_node(parent_node, or_edge); 417 add_edge_to_node(parent_node, or_edge);
418 } 418 }
419 419
@@ -439,17 +439,13 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
439 if (offset_ch > 0) { 439 if (offset_ch > 0) {
440 if (strncmp(version, "=", offset_ch) == 0) { 440 if (strncmp(version, "=", offset_ch) == 0) {
441 edge->operator = VER_EQUAL; 441 edge->operator = VER_EQUAL;
442 } 442 } else if (strncmp(version, "<<", offset_ch) == 0) {
443 else if (strncmp(version, "<<", offset_ch) == 0) {
444 edge->operator = VER_LESS; 443 edge->operator = VER_LESS;
445 } 444 } else if (strncmp(version, "<=", offset_ch) == 0) {
446 else if (strncmp(version, "<=", offset_ch) == 0) {
447 edge->operator = VER_LESS_EQUAL; 445 edge->operator = VER_LESS_EQUAL;
448 } 446 } else if (strncmp(version, ">>", offset_ch) == 0) {
449 else if (strncmp(version, ">>", offset_ch) == 0) {
450 edge->operator = VER_MORE; 447 edge->operator = VER_MORE;
451 } 448 } else if (strncmp(version, ">=", offset_ch) == 0) {
452 else if (strncmp(version, ">=", offset_ch) == 0) {
453 edge->operator = VER_MORE_EQUAL; 449 edge->operator = VER_MORE_EQUAL;
454 } else { 450 } else {
455 bb_error_msg_and_die("illegal operator"); 451 bb_error_msg_and_die("illegal operator");
@@ -1221,10 +1217,40 @@ static int run_package_script(const char *package_name, const char *script_type)
1221 return result; 1217 return result;
1222} 1218}
1223 1219
1220/*
1221The policy manual defines what scripts get called when and with
1222what arguments. I realize that busybox does not support all of
1223these scenarios, but it does support some of them; it does not,
1224however, run them with any parameters in run_package_script().
1225Here are the scripts:
1226
1227preinst install
1228preinst install <old_version>
1229preinst upgrade <old_version>
1230preinst abort_upgrade <new_version>
1231postinst configure <most_recent_version>
1232postinst abort-upgade <new_version>
1233postinst abort-remove
1234postinst abort-remove in-favour <package> <version>
1235postinst abort-deconfigure in-favor <failed_install_package> removing <conflicting_package> <version>
1236prerm remove
1237prerm upgrade <new_version>
1238prerm failed-upgrade <old_version>
1239prerm remove in-favor <package> <new_version>
1240prerm deconfigure in-favour <package> <version> removing <package> <version>
1241postrm remove
1242postrm purge
1243postrm upgrade <new_version>
1244postrm failed-upgrade <old_version>
1245postrm abort-install
1246postrm abort-install <old_version>
1247postrm abort-upgrade <old_version>
1248postrm disappear <overwriter> <version>
1249*/
1224static const char *const all_control_files[] = { 1250static const char *const all_control_files[] = {
1225 "preinst", "postinst", "prerm", "postrm", 1251 "preinst", "postinst", "prerm", "postrm",
1226 "list", "md5sums", "shlibs", "conffiles", 1252 "list", "md5sums", "shlibs", "conffiles",
1227 "config", "templates", NULL 1253 "config", "templates"
1228}; 1254};
1229 1255
1230static char **all_control_list(const char *package_name) 1256static char **all_control_list(const char *package_name)
@@ -1233,9 +1259,10 @@ static char **all_control_list(const char *package_name)
1233 char **remove_files; 1259 char **remove_files;
1234 1260
1235 /* Create a list of all /var/lib/dpkg/info/<package> files */ 1261 /* Create a list of all /var/lib/dpkg/info/<package> files */
1236 remove_files = xzalloc(sizeof(all_control_files)); 1262 remove_files = xzalloc(sizeof(all_control_files) + sizeof(char*));
1237 while (all_control_files[i]) { 1263 while (i < ARRAY_SIZE(all_control_files)) {
1238 remove_files[i] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]); 1264 remove_files[i] = xasprintf("/var/lib/dpkg/info/%s.%s",
1265 package_name, all_control_files[i]);
1239 i++; 1266 i++;
1240 } 1267 }
1241 1268
@@ -1314,10 +1341,10 @@ static void remove_package(const unsigned package_num, int noisy)
1314 } 1341 }
1315 1342
1316 /* Create a list of files to remove, and a separate list of those to keep */ 1343 /* Create a list of files to remove, and a separate list of those to keep */
1317 sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name); 1344 sprintf(list_name, "/var/lib/dpkg/info/%s.%s", package_name, "list");
1318 remove_files = create_list(list_name); 1345 remove_files = create_list(list_name);
1319 1346
1320 sprintf(conffile_name, "/var/lib/dpkg/info/%s.conffiles", package_name); 1347 sprintf(conffile_name, "/var/lib/dpkg/info/%s.%s", package_name, "conffiles");
1321 exclude_files = create_list(conffile_name); 1348 exclude_files = create_list(conffile_name);
1322 1349
1323 /* Some directories can't be removed straight away, so do multiple passes */ 1350 /* Some directories can't be removed straight away, so do multiple passes */
@@ -1328,7 +1355,7 @@ static void remove_package(const unsigned package_num, int noisy)
1328 /* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */ 1355 /* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
1329 exclude_files = xzalloc(sizeof(char*) * 3); 1356 exclude_files = xzalloc(sizeof(char*) * 3);
1330 exclude_files[0] = xstrdup(conffile_name); 1357 exclude_files[0] = xstrdup(conffile_name);
1331 exclude_files[1] = xasprintf("/var/lib/dpkg/info/%s.postrm", package_name); 1358 exclude_files[1] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "postrm");
1332 1359
1333 /* Create a list of all /var/lib/dpkg/info/<package> files */ 1360 /* Create a list of all /var/lib/dpkg/info/<package> files */
1334 remove_files = all_control_list(package_name); 1361 remove_files = all_control_list(package_name);
@@ -1363,7 +1390,7 @@ static void purge_package(const unsigned package_num)
1363 } 1390 }
1364 1391
1365 /* Create a list of files to remove */ 1392 /* Create a list of files to remove */
1366 sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name); 1393 sprintf(list_name, "/var/lib/dpkg/info/%s.%s", package_name, "list");
1367 remove_files = create_list(list_name); 1394 remove_files = create_list(list_name);
1368 1395
1369 exclude_files = xzalloc(sizeof(char*)); 1396 exclude_files = xzalloc(sizeof(char*));
@@ -1471,8 +1498,8 @@ static void unpack_package(deb_file_t *deb_file)
1471 char *list_filename; 1498 char *list_filename;
1472 archive_handle_t *archive_handle; 1499 archive_handle_t *archive_handle;
1473 FILE *out_stream; 1500 FILE *out_stream;
1474 llist_t *accept_list = NULL; 1501 llist_t *accept_list;
1475 int i = 0; 1502 int i;
1476 1503
1477 /* If existing version, remove it first */ 1504 /* If existing version, remove it first */
1478 if (strcmp(name_hashtable[get_status(status_num, 3)], "installed") == 0) { 1505 if (strcmp(name_hashtable[get_status(status_num, 3)], "installed") == 0) {
@@ -1486,11 +1513,13 @@ static void unpack_package(deb_file_t *deb_file)
1486 } 1513 }
1487 1514
1488 /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */ 1515 /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */
1489 info_prefix = xasprintf("/var/lib/dpkg/info/%s.", package_name); 1516 info_prefix = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "");
1490 archive_handle = init_archive_deb_ar(deb_file->filename); 1517 archive_handle = init_archive_deb_ar(deb_file->filename);
1491 init_archive_deb_control(archive_handle); 1518 init_archive_deb_control(archive_handle);
1492 1519
1493 while (all_control_files[i]) { 1520 accept_list = NULL;
1521 i = 0;
1522 while (i < ARRAY_SIZE(all_control_files)) {
1494 char *c = xasprintf("./%s", all_control_files[i]); 1523 char *c = xasprintf("./%s", all_control_files[i]);
1495 llist_add_to(&accept_list, c); 1524 llist_add_to(&accept_list, c);
1496 i++; 1525 i++;
@@ -1517,7 +1546,7 @@ static void unpack_package(deb_file_t *deb_file)
1517 unpack_ar_archive(archive_handle); 1546 unpack_ar_archive(archive_handle);
1518 1547
1519 /* Create the list file */ 1548 /* Create the list file */
1520 list_filename = xasprintf("/var/lib/dpkg/info/%s.list", package_name); 1549 list_filename = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "list");
1521 out_stream = xfopen(list_filename, "w"); 1550 out_stream = xfopen(list_filename, "w");
1522 while (archive_handle->sub_archive->passed) { 1551 while (archive_handle->sub_archive->passed) {
1523 /* the leading . has been stripped by data_extract_all_prefix already */ 1552 /* the leading . has been stripped by data_extract_all_prefix already */
@@ -1554,7 +1583,7 @@ static void configure_package(deb_file_t *deb_file)
1554} 1583}
1555 1584
1556int dpkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1585int dpkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1557int dpkg_main(int argc, char **argv) 1586int dpkg_main(int argc ATTRIBUTE_UNUSED, char **argv)
1558{ 1587{
1559 deb_file_t **deb_file = NULL; 1588 deb_file_t **deb_file = NULL;
1560 status_node_t *status_node; 1589 status_node_t *status_node;
@@ -1586,10 +1615,9 @@ int dpkg_main(int argc, char **argv)
1586 //if (opt & OPT_purge) ... // -P 1615 //if (opt & OPT_purge) ... // -P
1587 //if (opt & OPT_remove) ... // -r 1616 //if (opt & OPT_remove) ... // -r
1588 //if (opt & OPT_unpack) ... // -u (--unpack in official dpkg) 1617 //if (opt & OPT_unpack) ... // -u (--unpack in official dpkg)
1589 argc -= optind;
1590 argv += optind; 1618 argv += optind;
1591 /* check for non-option argument if expected */ 1619 /* check for non-option argument if expected */
1592 if (!opt || (!argc && !(opt && OPT_list_installed))) 1620 if (!opt || (!argv[0] && !(opt && OPT_list_installed)))
1593 bb_show_usage(); 1621 bb_show_usage();
1594 1622
1595 name_hashtable = xzalloc(sizeof(name_hashtable[0]) * (NAME_HASH_PRIME + 1)); 1623 name_hashtable = xzalloc(sizeof(name_hashtable[0]) * (NAME_HASH_PRIME + 1));