aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-21 23:15:43 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-21 23:15:43 +0000
commitc87339d5848ef63cd2968cb20ca007b3c8978773 (patch)
tree2429e4fc4c908cefd4398c14d576d548eb232f39
parentd235f58ac27d6eda32e5106700e76352e31aa511 (diff)
downloadbusybox-w32-c87339d5848ef63cd2968cb20ca007b3c8978773.tar.gz
busybox-w32-c87339d5848ef63cd2968cb20ca007b3c8978773.tar.bz2
busybox-w32-c87339d5848ef63cd2968cb20ca007b3c8978773.zip
dpkg: trivial code shrinkage, and redo G trick correctly.
function old new delta run_package_script_or_die - 72 +72 fill_package_struct 303 309 +6 search_package_hashtable 122 125 +3 get_status 112 111 -1 status_hashtable 4 - -4 set_status 162 158 -4 package_hashtable 4 - -4 name_hashtable 4 - -4 package_satisfies_dependency 112 106 -6 search_name_hashtable 118 110 -8 configure_package 121 106 -15 remove_package 333 317 -16 search_status_hashtable 133 111 -22 purge_package 247 217 -30 unpack_package 552 521 -31 run_package_script 62 - -62 dpkg_main 3991 3867 -124 ------------------------------------------------------------------------------ (add/remove: 1/4 grow/shrink: 2/10 up/down: 81/-331) Total: -250 bytes text data bss dec hex filename 807972 611 6924 815507 c7193 busybox_old 807603 611 6908 815122 c7012 busybox_unstripped
-rw-r--r--archival/dpkg.c72
1 files changed, 35 insertions, 37 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c
index ac5f76a47..ee5bd7aff 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -75,10 +75,21 @@ typedef struct status_node_s {
75 unsigned status:16; /* was:14 */ /* has to fit STATUS_HASH_PRIME */ 75 unsigned status:16; /* was:14 */ /* has to fit STATUS_HASH_PRIME */
76} status_node_t; 76} status_node_t;
77 77
78/* Were statically declared here, but such a big bss is nommu-unfriendly */ 78
79static char **name_hashtable; /* [NAME_HASH_PRIME + 1] */ 79/* Globals */
80static common_node_t **package_hashtable; /* [PACKAGE_HASH_PRIME + 1] */ 80struct globals {
81static status_node_t **status_hashtable; /* [STATUS_HASH_PRIME + 1] */ 81 char *name_hashtable[NAME_HASH_PRIME + 1];
82 common_node_t *package_hashtable[PACKAGE_HASH_PRIME + 1];
83 status_node_t *status_hashtable[STATUS_HASH_PRIME + 1];
84};
85#define G (*ptr_to_globals)
86#define name_hashtable (G.name_hashtable )
87#define package_hashtable (G.package_hashtable)
88#define status_hashtable (G.status_hashtable )
89#define INIT_G() do { \
90 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
91} while (0)
92
82 93
83/* Even numbers are for 'extras', like ored dependencies or null */ 94/* Even numbers are for 'extras', like ored dependencies or null */
84enum edge_type_e { 95enum edge_type_e {
@@ -312,7 +323,6 @@ static int test_version(const unsigned version1, const unsigned version2, const
312 return FALSE; 323 return FALSE;
313} 324}
314 325
315
316static int search_package_hashtable(const unsigned name, const unsigned version, const unsigned operator) 326static int search_package_hashtable(const unsigned name, const unsigned version, const unsigned operator)
317{ 327{
318 unsigned probe_address; 328 unsigned probe_address;
@@ -731,7 +741,6 @@ static const char *describe_status(int status_num)
731 return "is not installed or flagged to be installed"; 741 return "is not installed or flagged to be installed";
732} 742}
733 743
734
735static void index_status_file(const char *filename) 744static void index_status_file(const char *filename)
736{ 745{
737 FILE *status_file; 746 FILE *status_file;
@@ -1203,25 +1212,25 @@ static int remove_file_array(char **remove_names, char **exclude_names)
1203 return (remove_flag == 0); 1212 return (remove_flag == 0);
1204} 1213}
1205 1214
1206static int run_package_script(const char *package_name, const char *script_type) 1215static void run_package_script_or_die(const char *package_name, const char *script_type)
1207{ 1216{
1208 struct stat path_stat;
1209 char *script_path; 1217 char *script_path;
1210 int result; 1218 int result;
1211 1219
1212 script_path = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type); 1220 script_path = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
1213 1221
1214 /* If the file doesnt exist is isnt a fatal */ 1222 /* If the file doesnt exist is isnt fatal */
1215 result = lstat(script_path, &path_stat) < 0 ? EXIT_SUCCESS : system(script_path); 1223 result = access(script_path, F_OK) ? EXIT_SUCCESS : system(script_path);
1216 free(script_path); 1224 free(script_path);
1217 return result; 1225 if (result)
1226 bb_error_msg_and_die("%s failed, exit code %d", script_type, result);
1218} 1227}
1219 1228
1220/* 1229/*
1221The policy manual defines what scripts get called when and with 1230The policy manual defines what scripts get called when and with
1222what arguments. I realize that busybox does not support all of 1231what arguments. I realize that busybox does not support all of
1223these scenarios, but it does support some of them; it does not, 1232these scenarios, but it does support some of them; it does not,
1224however, run them with any parameters in run_package_script(). 1233however, run them with any parameters in run_package_script_or_die().
1225Here are the scripts: 1234Here are the scripts:
1226 1235
1227preinst install 1236preinst install
@@ -1335,10 +1344,8 @@ static void remove_package(const unsigned package_num, int noisy)
1335 if (noisy) 1344 if (noisy)
1336 printf("Removing %s (%s)...\n", package_name, package_version); 1345 printf("Removing %s (%s)...\n", package_name, package_version);
1337 1346
1338 /* run prerm script */ 1347 /* Run prerm script */
1339 if (run_package_script(package_name, "prerm") != 0) { 1348 run_package_script_or_die(package_name, "prerm");
1340 bb_error_msg_and_die("script failed, prerm failure");
1341 }
1342 1349
1343 /* Create a list of files to remove, and a separate list of those to keep */ 1350 /* Create a list of files to remove, and a separate list of those to keep */
1344 sprintf(list_name, "/var/lib/dpkg/info/%s.%s", package_name, "list"); 1351 sprintf(list_name, "/var/lib/dpkg/info/%s.%s", package_name, "list");
@@ -1348,7 +1355,8 @@ static void remove_package(const unsigned package_num, int noisy)
1348 exclude_files = create_list(conffile_name); 1355 exclude_files = create_list(conffile_name);
1349 1356
1350 /* Some directories can't be removed straight away, so do multiple passes */ 1357 /* Some directories can't be removed straight away, so do multiple passes */
1351 while (remove_file_array(remove_files, exclude_files)) /*repeat */; 1358 while (remove_file_array(remove_files, exclude_files))
1359 continue;
1352 free_array(exclude_files); 1360 free_array(exclude_files);
1353 free_array(remove_files); 1361 free_array(remove_files);
1354 1362
@@ -1384,10 +1392,8 @@ static void purge_package(const unsigned package_num)
1384 1392
1385 printf("Purging %s (%s)...\n", package_name, package_version); 1393 printf("Purging %s (%s)...\n", package_name, package_version);
1386 1394
1387 /* run prerm script */ 1395 /* Run prerm script */
1388 if (run_package_script(package_name, "prerm") != 0) { 1396 run_package_script_or_die(package_name, "prerm");
1389 bb_error_msg_and_die("script failed, prerm failure");
1390 }
1391 1397
1392 /* Create a list of files to remove */ 1398 /* Create a list of files to remove */
1393 sprintf(list_name, "/var/lib/dpkg/info/%s.%s", package_name, "list"); 1399 sprintf(list_name, "/var/lib/dpkg/info/%s.%s", package_name, "list");
@@ -1405,10 +1411,8 @@ static void purge_package(const unsigned package_num)
1405 free_array(remove_files); 1411 free_array(remove_files);
1406 free(exclude_files); 1412 free(exclude_files);
1407 1413
1408 /* run postrm script */ 1414 /* Run postrm script */
1409 if (run_package_script(package_name, "postrm") != 0) { 1415 run_package_script_or_die(package_name, "postrm");
1410 bb_error_msg_and_die("postrm failure.. set status to what?");
1411 }
1412 1416
1413 /* Change package status */ 1417 /* Change package status */
1414 set_status(status_num, "not-installed", 3); 1418 set_status(status_num, "not-installed", 3);
@@ -1532,10 +1536,7 @@ static void unpack_package(deb_file_t *deb_file)
1532 unpack_ar_archive(archive_handle); 1536 unpack_ar_archive(archive_handle);
1533 1537
1534 /* Run the preinst prior to extracting */ 1538 /* Run the preinst prior to extracting */
1535 if (run_package_script(package_name, "preinst") != 0) { 1539 run_package_script_or_die(package_name, "preinst");
1536 /* when preinst returns exit code != 0 then quit installation process */
1537 bb_error_msg_and_die("subprocess pre-installation script returned error");
1538 }
1539 1540
1540 /* Extract data.tar.gz to the root directory */ 1541 /* Extract data.tar.gz to the root directory */
1541 archive_handle = init_archive_deb_ar(deb_file->filename); 1542 archive_handle = init_archive_deb_ar(deb_file->filename);
@@ -1573,10 +1574,9 @@ static void configure_package(deb_file_t *deb_file)
1573 printf("Setting up %s (%s)...\n", package_name, package_version); 1574 printf("Setting up %s (%s)...\n", package_name, package_version);
1574 1575
1575 /* Run the postinst script */ 1576 /* Run the postinst script */
1576 if (run_package_script(package_name, "postinst") != 0) { 1577 /* TODO: handle failure gracefully */
1577 /* TODO: handle failure gracefully */ 1578 run_package_script_or_die(package_name, "postinst");
1578 bb_error_msg_and_die("postinst failure.. set status to what?"); 1579
1579 }
1580 /* Change status to reflect success */ 1580 /* Change status to reflect success */
1581 set_status(status_num, "install", 1); 1581 set_status(status_num, "install", 1);
1582 set_status(status_num, "installed", 3); 1582 set_status(status_num, "installed", 3);
@@ -1604,6 +1604,8 @@ int dpkg_main(int argc ATTRIBUTE_UNUSED, char **argv)
1604 OPT_unpack = 0x40, 1604 OPT_unpack = 0x40,
1605 }; 1605 };
1606 1606
1607 INIT_G();
1608
1607 opt = getopt32(argv, "CF:ilPru", &str_f); 1609 opt = getopt32(argv, "CF:ilPru", &str_f);
1608 //if (opt & OPT_configure) ... // -C 1610 //if (opt & OPT_configure) ... // -C
1609 if (opt & OPT_force_ignore_depends) { // -F (--force in official dpkg) 1611 if (opt & OPT_force_ignore_depends) { // -F (--force in official dpkg)
@@ -1620,10 +1622,6 @@ int dpkg_main(int argc ATTRIBUTE_UNUSED, char **argv)
1620 if (!opt || (!argv[0] && !(opt && OPT_list_installed))) 1622 if (!opt || (!argv[0] && !(opt && OPT_list_installed)))
1621 bb_show_usage(); 1623 bb_show_usage();
1622 1624
1623 name_hashtable = xzalloc(sizeof(name_hashtable[0]) * (NAME_HASH_PRIME + 1));
1624 package_hashtable = xzalloc(sizeof(package_hashtable[0]) * (PACKAGE_HASH_PRIME + 1));
1625 status_hashtable = xzalloc(sizeof(status_hashtable[0]) * (STATUS_HASH_PRIME + 1));
1626
1627/* puts("(Reading database ... xxxxx files and directories installed.)"); */ 1625/* puts("(Reading database ... xxxxx files and directories installed.)"); */
1628 index_status_file("/var/lib/dpkg/status"); 1626 index_status_file("/var/lib/dpkg/status");
1629 1627