Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mini dpkg implementation for busybox. |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 3 | * This is not meant as a replacement for dpkg |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 4 | * |
Glenn L McGrath | 3563654 | 2001-10-03 03:10:35 +0000 | [diff] [blame] | 5 | * Written By Glenn McGrath with the help of others |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 6 | * Copyright (C) 2001 by Glenn McGrath |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 7 | * |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 8 | * Started life as a busybox implementation of udpkg |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU Library General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 | */ |
Glenn L McGrath | 649968c | 2001-02-10 14:26:48 +0000 | [diff] [blame] | 24 | |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 25 | /* |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 26 | * Known difference between busybox dpkg and the official dpkg that i don't |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 27 | * consider important, its worth keeping a note of differences anyway, just to |
| 28 | * make it easier to maintain. |
| 29 | * - The first value for the Confflile: field isnt placed on a new line. |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 30 | * - When installing a package the Status: field is placed at the end of the |
| 31 | * section, rather than just after the Package: field. |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 32 | * |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 33 | * Bugs that need to be fixed |
| 34 | * - (unknown, please let me know when you find any) |
| 35 | * |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 36 | */ |
| 37 | |
Glenn L McGrath | 61b7904 | 2002-10-19 10:40:55 +0000 | [diff] [blame] | 38 | #include <fcntl.h> |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 39 | #include <getopt.h> |
| 40 | #include <stdlib.h> |
| 41 | #include <string.h> |
| 42 | #include <unistd.h> |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 43 | #include "unarchive.h" |
Glenn L McGrath | c900575 | 2001-02-10 02:05:24 +0000 | [diff] [blame] | 44 | #include "busybox.h" |
| 45 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 46 | /* NOTE: If you vary HASH_PRIME sizes be aware, |
| 47 | * 1) Tweaking these will have a big effect on how much memory this program uses. |
| 48 | * 2) For computational efficiency these hash tables should be at least 20% |
| 49 | * larger than the maximum number of elements stored in it. |
| 50 | * 3) All _HASH_PRIME's must be a prime number or chaos is assured, if your looking |
| 51 | * for a prime, try http://www.utm.edu/research/primes/lists/small/10000.txt |
| 52 | * 4) If you go bigger than 15 bits you may get into trouble (untested) as its |
| 53 | * sometimes cast to an unsigned int, if you go to 16 bit you will overlap |
| 54 | * int's and chaos is assured, 16381 is the max prime for 14 bit field |
| 55 | */ |
| 56 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 57 | /* NAME_HASH_PRIME, Stores package names and versions, |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 58 | * I estimate it should be at least 50% bigger than PACKAGE_HASH_PRIME, |
| 59 | * as there a lot of duplicate version numbers */ |
| 60 | #define NAME_HASH_PRIME 16381 |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 61 | static char *name_hashtable[NAME_HASH_PRIME + 1]; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 62 | |
| 63 | /* PACKAGE_HASH_PRIME, Maximum number of unique packages, |
| 64 | * It must not be smaller than STATUS_HASH_PRIME, |
| 65 | * Currently only packages from status_hashtable are stored in here, but in |
| 66 | * future this may be used to store packages not only from a status file, |
| 67 | * but an available_hashtable, and even multiple packages files. |
| 68 | * Package can be stored more than once if they have different versions. |
| 69 | * e.g. The same package may have different versions in the status file |
| 70 | * and available file */ |
| 71 | #define PACKAGE_HASH_PRIME 10007 |
| 72 | typedef struct edge_s { |
| 73 | unsigned int operator:3; |
| 74 | unsigned int type:4; |
| 75 | unsigned int name:14; |
| 76 | unsigned int version:14; |
| 77 | } edge_t; |
| 78 | |
| 79 | typedef struct common_node_s { |
| 80 | unsigned int name:14; |
| 81 | unsigned int version:14; |
| 82 | unsigned int num_of_edges:14; |
| 83 | edge_t **edge; |
| 84 | } common_node_t; |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 85 | static common_node_t *package_hashtable[PACKAGE_HASH_PRIME + 1]; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 86 | |
| 87 | /* Currently it doesnt store packages that have state-status of not-installed |
| 88 | * So it only really has to be the size of the maximum number of packages |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 89 | * likely to be installed at any one time, so there is a bit of leeway here */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 90 | #define STATUS_HASH_PRIME 8191 |
| 91 | typedef struct status_node_s { |
| 92 | unsigned int package:14; /* has to fit PACKAGE_HASH_PRIME */ |
| 93 | unsigned int status:14; /* has to fit STATUS_HASH_PRIME */ |
| 94 | } status_node_t; |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 95 | static status_node_t *status_hashtable[STATUS_HASH_PRIME + 1]; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 96 | |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 97 | /* Even numbers are for 'extras', like ored dependencies or null */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 98 | enum edge_type_e { |
| 99 | EDGE_NULL = 0, |
| 100 | EDGE_PRE_DEPENDS = 1, |
| 101 | EDGE_OR_PRE_DEPENDS = 2, |
| 102 | EDGE_DEPENDS = 3, |
| 103 | EDGE_OR_DEPENDS = 4, |
| 104 | EDGE_REPLACES = 5, |
| 105 | EDGE_PROVIDES = 7, |
| 106 | EDGE_CONFLICTS = 9, |
| 107 | EDGE_SUGGESTS = 11, |
| 108 | EDGE_RECOMMENDS = 13, |
| 109 | EDGE_ENHANCES = 15 |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 110 | }; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 111 | enum operator_e { |
| 112 | VER_NULL = 0, |
| 113 | VER_EQUAL = 1, |
| 114 | VER_LESS = 2, |
| 115 | VER_LESS_EQUAL = 3, |
| 116 | VER_MORE = 4, |
| 117 | VER_MORE_EQUAL = 5, |
| 118 | VER_ANY = 6 |
| 119 | }; |
| 120 | |
| 121 | enum dpkg_opt_e { |
| 122 | dpkg_opt_purge = 1, |
| 123 | dpkg_opt_remove = 2, |
| 124 | dpkg_opt_unpack = 4, |
| 125 | dpkg_opt_configure = 8, |
| 126 | dpkg_opt_install = 16, |
| 127 | dpkg_opt_package_name = 32, |
| 128 | dpkg_opt_filename = 64, |
| 129 | dpkg_opt_list_installed = 128, |
| 130 | dpkg_opt_force_ignore_depends = 256 |
| 131 | }; |
| 132 | |
| 133 | typedef struct deb_file_s { |
| 134 | char *control_file; |
| 135 | char *filename; |
| 136 | unsigned int package:14; |
| 137 | } deb_file_t; |
| 138 | |
| 139 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 140 | static void make_hash(const char *key, unsigned int *start, unsigned int *decrement, const int hash_prime) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 141 | { |
| 142 | unsigned long int hash_num = key[0]; |
| 143 | int len = strlen(key); |
| 144 | int i; |
| 145 | |
| 146 | /* Maybe i should have uses a "proper" hashing algorithm here instead |
| 147 | * of making one up myself, seems to be working ok though. */ |
| 148 | for(i = 1; i < len; i++) { |
| 149 | /* shifts the ascii based value and adds it to previous value |
| 150 | * shift amount is mod 24 because long int is 32 bit and data |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 151 | * to be shifted is 8, don't want to shift data to where it has |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 152 | * no effect*/ |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 153 | hash_num += ((key[i] + key[i-1]) << ((key[i] * i) % 24)); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 154 | } |
| 155 | *start = (unsigned int) hash_num % hash_prime; |
| 156 | *decrement = (unsigned int) 1 + (hash_num % (hash_prime - 1)); |
| 157 | } |
| 158 | |
| 159 | /* this adds the key to the hash table */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 160 | static int search_name_hashtable(const char *key) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 161 | { |
| 162 | unsigned int probe_address = 0; |
| 163 | unsigned int probe_decrement = 0; |
| 164 | // char *temp; |
| 165 | |
| 166 | make_hash(key, &probe_address, &probe_decrement, NAME_HASH_PRIME); |
| 167 | while(name_hashtable[probe_address] != NULL) { |
| 168 | if (strcmp(name_hashtable[probe_address], key) == 0) { |
| 169 | return(probe_address); |
| 170 | } else { |
| 171 | probe_address -= probe_decrement; |
| 172 | if ((int)probe_address < 0) { |
| 173 | probe_address += NAME_HASH_PRIME; |
| 174 | } |
| 175 | } |
| 176 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 177 | name_hashtable[probe_address] = bb_xstrdup(key); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 178 | return(probe_address); |
| 179 | } |
| 180 | |
| 181 | /* this DOESNT add the key to the hashtable |
| 182 | * TODO make it consistent with search_name_hashtable |
| 183 | */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 184 | static unsigned int search_status_hashtable(const char *key) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 185 | { |
| 186 | unsigned int probe_address = 0; |
| 187 | unsigned int probe_decrement = 0; |
| 188 | |
| 189 | make_hash(key, &probe_address, &probe_decrement, STATUS_HASH_PRIME); |
| 190 | while(status_hashtable[probe_address] != NULL) { |
| 191 | if (strcmp(key, name_hashtable[package_hashtable[status_hashtable[probe_address]->package]->name]) == 0) { |
| 192 | break; |
| 193 | } else { |
| 194 | probe_address -= probe_decrement; |
| 195 | if ((int)probe_address < 0) { |
| 196 | probe_address += STATUS_HASH_PRIME; |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | return(probe_address); |
| 201 | } |
| 202 | |
| 203 | /* Need to rethink version comparison, maybe the official dpkg has something i can use ? */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 204 | static int version_compare_part(const char *version1, const char *version2) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 205 | { |
| 206 | int upstream_len1 = 0; |
| 207 | int upstream_len2 = 0; |
| 208 | char *name1_char; |
| 209 | char *name2_char; |
| 210 | int len1 = 0; |
| 211 | int len2 = 0; |
| 212 | int tmp_int; |
| 213 | int ver_num1; |
| 214 | int ver_num2; |
| 215 | int ret; |
| 216 | |
| 217 | if (version1 == NULL) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 218 | version1 = bb_xstrdup(""); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 219 | } |
| 220 | if (version2 == NULL) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 221 | version2 = bb_xstrdup(""); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 222 | } |
| 223 | upstream_len1 = strlen(version1); |
| 224 | upstream_len2 = strlen(version2); |
| 225 | |
| 226 | while ((len1 < upstream_len1) || (len2 < upstream_len2)) { |
| 227 | /* Compare non-digit section */ |
| 228 | tmp_int = strcspn(&version1[len1], "0123456789"); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 229 | name1_char = bb_xstrndup(&version1[len1], tmp_int); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 230 | len1 += tmp_int; |
| 231 | tmp_int = strcspn(&version2[len2], "0123456789"); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 232 | name2_char = bb_xstrndup(&version2[len2], tmp_int); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 233 | len2 += tmp_int; |
| 234 | tmp_int = strcmp(name1_char, name2_char); |
| 235 | free(name1_char); |
| 236 | free(name2_char); |
| 237 | if (tmp_int != 0) { |
| 238 | ret = tmp_int; |
| 239 | goto cleanup_version_compare_part; |
| 240 | } |
| 241 | |
| 242 | /* Compare digits */ |
| 243 | tmp_int = strspn(&version1[len1], "0123456789"); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 244 | name1_char = bb_xstrndup(&version1[len1], tmp_int); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 245 | len1 += tmp_int; |
| 246 | tmp_int = strspn(&version2[len2], "0123456789"); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 247 | name2_char = bb_xstrndup(&version2[len2], tmp_int); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 248 | len2 += tmp_int; |
| 249 | ver_num1 = atoi(name1_char); |
| 250 | ver_num2 = atoi(name2_char); |
| 251 | free(name1_char); |
| 252 | free(name2_char); |
| 253 | if (ver_num1 < ver_num2) { |
| 254 | ret = -1; |
| 255 | goto cleanup_version_compare_part; |
| 256 | } |
| 257 | else if (ver_num1 > ver_num2) { |
| 258 | ret = 1; |
| 259 | goto cleanup_version_compare_part; |
| 260 | } |
| 261 | } |
| 262 | ret = 0; |
| 263 | cleanup_version_compare_part: |
| 264 | return(ret); |
| 265 | } |
| 266 | |
| 267 | /* if ver1 < ver2 return -1, |
| 268 | * if ver1 = ver2 return 0, |
| 269 | * if ver1 > ver2 return 1, |
| 270 | */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 271 | static int version_compare(const unsigned int ver1, const unsigned int ver2) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 272 | { |
| 273 | char *ch_ver1 = name_hashtable[ver1]; |
| 274 | char *ch_ver2 = name_hashtable[ver2]; |
| 275 | |
| 276 | char epoch1, epoch2; |
| 277 | char *deb_ver1, *deb_ver2; |
| 278 | char *ver1_ptr, *ver2_ptr; |
| 279 | char *upstream_ver1; |
| 280 | char *upstream_ver2; |
| 281 | int result; |
| 282 | |
| 283 | /* Compare epoch */ |
| 284 | if (ch_ver1[1] == ':') { |
| 285 | epoch1 = ch_ver1[0]; |
| 286 | ver1_ptr = strchr(ch_ver1, ':') + 1; |
| 287 | } else { |
| 288 | epoch1 = '0'; |
| 289 | ver1_ptr = ch_ver1; |
| 290 | } |
| 291 | if (ch_ver2[1] == ':') { |
| 292 | epoch2 = ch_ver2[0]; |
| 293 | ver2_ptr = strchr(ch_ver2, ':') + 1; |
| 294 | } else { |
| 295 | epoch2 = '0'; |
| 296 | ver2_ptr = ch_ver2; |
| 297 | } |
| 298 | if (epoch1 < epoch2) { |
| 299 | return(-1); |
| 300 | } |
| 301 | else if (epoch1 > epoch2) { |
| 302 | return(1); |
| 303 | } |
| 304 | |
| 305 | /* Compare upstream version */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 306 | upstream_ver1 = bb_xstrdup(ver1_ptr); |
| 307 | upstream_ver2 = bb_xstrdup(ver2_ptr); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 308 | |
| 309 | /* Chop off debian version, and store for later use */ |
| 310 | deb_ver1 = strrchr(upstream_ver1, '-'); |
| 311 | deb_ver2 = strrchr(upstream_ver2, '-'); |
| 312 | if (deb_ver1) { |
| 313 | deb_ver1[0] = '\0'; |
| 314 | deb_ver1++; |
| 315 | } |
| 316 | if (deb_ver2) { |
| 317 | deb_ver2[0] = '\0'; |
| 318 | deb_ver2++; |
| 319 | } |
| 320 | result = version_compare_part(upstream_ver1, upstream_ver2); |
| 321 | |
| 322 | free(upstream_ver1); |
| 323 | free(upstream_ver2); |
| 324 | |
| 325 | if (result != 0) { |
| 326 | return(result); |
| 327 | } |
| 328 | |
| 329 | /* Compare debian versions */ |
| 330 | return(version_compare_part(deb_ver1, deb_ver2)); |
| 331 | } |
| 332 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 333 | static int test_version(const unsigned int version1, const unsigned int version2, const unsigned int operator) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 334 | { |
| 335 | const int version_result = version_compare(version1, version2); |
| 336 | switch(operator) { |
| 337 | case (VER_ANY): |
| 338 | return(TRUE); |
| 339 | case (VER_EQUAL): |
| 340 | if (version_result == 0) { |
| 341 | return(TRUE); |
| 342 | } |
| 343 | break; |
| 344 | case (VER_LESS): |
| 345 | if (version_result < 0) { |
| 346 | return(TRUE); |
| 347 | } |
| 348 | break; |
| 349 | case (VER_LESS_EQUAL): |
| 350 | if (version_result <= 0) { |
| 351 | return(TRUE); |
| 352 | } |
| 353 | break; |
| 354 | case (VER_MORE): |
| 355 | if (version_result > 0) { |
| 356 | return(TRUE); |
| 357 | } |
| 358 | break; |
| 359 | case (VER_MORE_EQUAL): |
| 360 | if (version_result >= 0) { |
| 361 | return(TRUE); |
| 362 | } |
| 363 | break; |
| 364 | } |
| 365 | return(FALSE); |
| 366 | } |
| 367 | |
| 368 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 369 | static int search_package_hashtable(const unsigned int name, const unsigned int version, const unsigned int operator) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 370 | { |
| 371 | unsigned int probe_address = 0; |
| 372 | unsigned int probe_decrement = 0; |
| 373 | |
| 374 | make_hash(name_hashtable[name], &probe_address, &probe_decrement, PACKAGE_HASH_PRIME); |
| 375 | while(package_hashtable[probe_address] != NULL) { |
| 376 | if (package_hashtable[probe_address]->name == name) { |
| 377 | if (operator == VER_ANY) { |
| 378 | return(probe_address); |
| 379 | } |
| 380 | if (test_version(package_hashtable[probe_address]->version, version, operator)) { |
| 381 | return(probe_address); |
| 382 | } |
| 383 | } |
| 384 | probe_address -= probe_decrement; |
| 385 | if ((int)probe_address < 0) { |
| 386 | probe_address += PACKAGE_HASH_PRIME; |
| 387 | } |
| 388 | } |
| 389 | return(probe_address); |
| 390 | } |
| 391 | |
| 392 | /* |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 393 | * This function searches through the entire package_hashtable looking |
| 394 | * for a package which provides "needle". It returns the index into |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 395 | * the package_hashtable for the providing package. |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 396 | * |
| 397 | * needle is the index into name_hashtable of the package we are |
| 398 | * looking for. |
| 399 | * |
| 400 | * start_at is the index in the package_hashtable to start looking |
| 401 | * at. If start_at is -1 then start at the beginning. This is to allow |
| 402 | * for repeated searches since more than one package might provide |
| 403 | * needle. |
| 404 | * |
| 405 | * FIXME: I don't think this is very efficient, but I thought I'd keep |
| 406 | * it simple for now until it proves to be a problem. |
| 407 | */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 408 | static int search_for_provides(int needle, int start_at) { |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 409 | int i, j; |
| 410 | common_node_t *p; |
| 411 | for (i = start_at + 1; i < PACKAGE_HASH_PRIME; i++) { |
| 412 | p = package_hashtable[i]; |
| 413 | if ( p == NULL ) continue; |
| 414 | for(j = 0; j < p->num_of_edges; j++) |
| 415 | if ( p->edge[j]->type == EDGE_PROVIDES && p->edge[j]->name == needle ) |
| 416 | return i; |
| 417 | } |
| 418 | return -1; |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | * Add an edge to a node |
| 423 | */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 424 | static void add_edge_to_node(common_node_t *node, edge_t *edge) |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 425 | { |
| 426 | node->num_of_edges++; |
| 427 | node->edge = xrealloc(node->edge, sizeof(edge_t) * (node->num_of_edges + 1)); |
| 428 | node->edge[node->num_of_edges - 1] = edge; |
| 429 | } |
| 430 | |
| 431 | /* |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 432 | * Create one new node and one new edge for every dependency. |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 433 | * |
| 434 | * Dependencies which contain multiple alternatives are represented as |
| 435 | * an EDGE_OR_PRE_DEPENDS or EDGE_OR_DEPENDS node, followed by a |
| 436 | * number of EDGE_PRE_DEPENDS or EDGE_DEPENDS nodes. The name field of |
| 437 | * the OR edge contains the full dependency string while the version |
| 438 | * field contains the number of EDGE nodes which follow as part of |
| 439 | * this alternative. |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 440 | */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 441 | static void add_split_dependencies(common_node_t *parent_node, const char *whole_line, unsigned int edge_type) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 442 | { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 443 | char *line = bb_xstrdup(whole_line); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 444 | char *line2; |
| 445 | char *line_ptr1 = NULL; |
| 446 | char *line_ptr2 = NULL; |
| 447 | char *field; |
| 448 | char *field2; |
| 449 | char *version; |
| 450 | edge_t *edge; |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 451 | edge_t *or_edge; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 452 | int offset_ch; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 453 | |
| 454 | field = strtok_r(line, ",", &line_ptr1); |
| 455 | do { |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 456 | /* skip leading spaces */ |
| 457 | field += strspn(field, " "); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 458 | line2 = bb_xstrdup(field); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 459 | field2 = strtok_r(line2, "|", &line_ptr2); |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 460 | if ( (edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS) && |
| 461 | (strcmp(field, field2) != 0)) { |
| 462 | or_edge = (edge_t *)xmalloc(sizeof(edge_t)); |
| 463 | or_edge->type = edge_type + 1; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 464 | } else { |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 465 | or_edge = NULL; |
| 466 | } |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 467 | |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 468 | if ( or_edge ) { |
| 469 | or_edge->name = search_name_hashtable(field); |
| 470 | or_edge->version = 0; // tracks the number of altenatives |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 471 | |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 472 | add_edge_to_node(parent_node, or_edge); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | do { |
| 476 | edge = (edge_t *) xmalloc(sizeof(edge_t)); |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 477 | edge->type = edge_type; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 478 | |
| 479 | /* Skip any extra leading spaces */ |
| 480 | field2 += strspn(field2, " "); |
| 481 | |
| 482 | /* Get dependency version info */ |
| 483 | version = strchr(field2, '('); |
| 484 | if (version == NULL) { |
| 485 | edge->operator = VER_ANY; |
| 486 | /* Get the versions hash number, adding it if the number isnt already in there */ |
| 487 | edge->version = search_name_hashtable("ANY"); |
| 488 | } else { |
| 489 | /* Skip leading ' ' or '(' */ |
| 490 | version += strspn(field2, " "); |
| 491 | version += strspn(version, "("); |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 492 | /* Calculate length of any operator characters */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 493 | offset_ch = strspn(version, "<=>"); |
| 494 | /* Determine operator */ |
| 495 | if (offset_ch > 0) { |
| 496 | if (strncmp(version, "=", offset_ch) == 0) { |
| 497 | edge->operator = VER_EQUAL; |
| 498 | } |
| 499 | else if (strncmp(version, "<<", offset_ch) == 0) { |
| 500 | edge->operator = VER_LESS; |
| 501 | } |
| 502 | else if (strncmp(version, "<=", offset_ch) == 0) { |
| 503 | edge->operator = VER_LESS_EQUAL; |
| 504 | } |
| 505 | else if (strncmp(version, ">>", offset_ch) == 0) { |
| 506 | edge->operator = VER_MORE; |
| 507 | } |
| 508 | else if (strncmp(version, ">=", offset_ch) == 0) { |
| 509 | edge->operator = VER_MORE_EQUAL; |
| 510 | } else { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 511 | bb_error_msg_and_die("Illegal operator\n"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | /* skip to start of version numbers */ |
| 515 | version += offset_ch; |
| 516 | version += strspn(version, " "); |
| 517 | |
| 518 | /* Truncate version at trailing ' ' or ')' */ |
| 519 | version[strcspn(version, " )")] = '\0'; |
| 520 | /* Get the versions hash number, adding it if the number isnt already in there */ |
| 521 | edge->version = search_name_hashtable(version); |
| 522 | } |
| 523 | |
| 524 | /* Get the dependency name */ |
| 525 | field2[strcspn(field2, " (")] = '\0'; |
| 526 | edge->name = search_name_hashtable(field2); |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 527 | |
| 528 | if ( or_edge ) |
| 529 | or_edge->version++; |
| 530 | |
| 531 | add_edge_to_node(parent_node, edge); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 532 | } while ((field2 = strtok_r(NULL, "|", &line_ptr2)) != NULL); |
| 533 | free(line2); |
| 534 | } while ((field = strtok_r(NULL, ",", &line_ptr1)) != NULL); |
| 535 | free(line); |
| 536 | |
| 537 | return; |
| 538 | } |
| 539 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 540 | static void free_package(common_node_t *node) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 541 | { |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 542 | unsigned short i; |
| 543 | if (node) { |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 544 | for (i = 0; i < node->num_of_edges; i++) { |
Aaron Lehmann | a170e1c | 2002-11-28 11:27:31 +0000 | [diff] [blame] | 545 | free(node->edge[i]); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 546 | } |
Rob Landley | e7c43b6 | 2006-03-01 16:39:45 +0000 | [diff] [blame] | 547 | free(node->edge); |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 548 | free(node); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 552 | static unsigned int fill_package_struct(char *control_buffer) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 553 | { |
Rob Landley | 0a7c8ef | 2006-02-22 17:01:00 +0000 | [diff] [blame] | 554 | static const char *const field_names[] = { "Package", "Version", |
| 555 | "Pre-Depends", "Depends","Replaces", "Provides", |
| 556 | "Conflicts", "Suggests", "Recommends", "Enhances", 0 |
| 557 | }; |
| 558 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 559 | common_node_t *new_node = (common_node_t *) xcalloc(1, sizeof(common_node_t)); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 560 | char *field_name; |
| 561 | char *field_value; |
| 562 | int field_start = 0; |
| 563 | int num = -1; |
| 564 | int buffer_length = strlen(control_buffer); |
| 565 | |
| 566 | new_node->version = search_name_hashtable("unknown"); |
| 567 | while (field_start < buffer_length) { |
Glenn L McGrath | 62d2882 | 2002-11-06 23:35:28 +0000 | [diff] [blame] | 568 | unsigned short field_num; |
| 569 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 570 | field_start += read_package_field(&control_buffer[field_start], |
| 571 | &field_name, &field_value); |
| 572 | |
| 573 | if (field_name == NULL) { |
Glenn L McGrath | 62d2882 | 2002-11-06 23:35:28 +0000 | [diff] [blame] | 574 | goto fill_package_struct_cleanup; /* Oh no, the dreaded goto statement ! */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 577 | field_num = compare_string_array(field_names, field_name); |
Glenn L McGrath | 62d2882 | 2002-11-06 23:35:28 +0000 | [diff] [blame] | 578 | switch(field_num) { |
| 579 | case 0: /* Package */ |
| 580 | new_node->name = search_name_hashtable(field_value); |
| 581 | break; |
| 582 | case 1: /* Version */ |
| 583 | new_node->version = search_name_hashtable(field_value); |
| 584 | break; |
| 585 | case 2: /* Pre-Depends */ |
| 586 | add_split_dependencies(new_node, field_value, EDGE_PRE_DEPENDS); |
| 587 | break; |
| 588 | case 3: /* Depends */ |
| 589 | add_split_dependencies(new_node, field_value, EDGE_DEPENDS); |
| 590 | break; |
| 591 | case 4: /* Replaces */ |
| 592 | add_split_dependencies(new_node, field_value, EDGE_REPLACES); |
| 593 | break; |
| 594 | case 5: /* Provides */ |
| 595 | add_split_dependencies(new_node, field_value, EDGE_PROVIDES); |
| 596 | break; |
| 597 | case 6: /* Conflicts */ |
| 598 | add_split_dependencies(new_node, field_value, EDGE_CONFLICTS); |
| 599 | break; |
| 600 | case 7: /* Suggests */ |
| 601 | add_split_dependencies(new_node, field_value, EDGE_SUGGESTS); |
| 602 | break; |
| 603 | case 8: /* Recommends */ |
| 604 | add_split_dependencies(new_node, field_value, EDGE_RECOMMENDS); |
| 605 | break; |
| 606 | case 9: /* Enhances */ |
| 607 | add_split_dependencies(new_node, field_value, EDGE_ENHANCES); |
| 608 | break; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 609 | } |
| 610 | fill_package_struct_cleanup: |
Aaron Lehmann | a170e1c | 2002-11-28 11:27:31 +0000 | [diff] [blame] | 611 | free(field_name); |
| 612 | free(field_value); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | if (new_node->version == search_name_hashtable("unknown")) { |
| 616 | free_package(new_node); |
| 617 | return(-1); |
| 618 | } |
| 619 | num = search_package_hashtable(new_node->name, new_node->version, VER_EQUAL); |
| 620 | if (package_hashtable[num] == NULL) { |
| 621 | package_hashtable[num] = new_node; |
| 622 | } else { |
| 623 | free_package(new_node); |
| 624 | } |
| 625 | return(num); |
| 626 | } |
| 627 | |
| 628 | /* if num = 1, it returns the want status, 2 returns flag, 3 returns status */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 629 | static unsigned int get_status(const unsigned int status_node, const int num) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 630 | { |
| 631 | char *status_string = name_hashtable[status_hashtable[status_node]->status]; |
| 632 | char *state_sub_string; |
| 633 | unsigned int state_sub_num; |
| 634 | int len; |
| 635 | int i; |
| 636 | |
| 637 | /* set tmp_string to point to the start of the word number */ |
| 638 | for (i = 1; i < num; i++) { |
| 639 | /* skip past a word */ |
| 640 | status_string += strcspn(status_string, " "); |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 641 | /* skip past the separating spaces */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 642 | status_string += strspn(status_string, " "); |
| 643 | } |
| 644 | len = strcspn(status_string, " \n\0"); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 645 | state_sub_string = bb_xstrndup(status_string, len); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 646 | state_sub_num = search_name_hashtable(state_sub_string); |
| 647 | free(state_sub_string); |
| 648 | return(state_sub_num); |
| 649 | } |
| 650 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 651 | static void set_status(const unsigned int status_node_num, const char *new_value, const int position) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 652 | { |
| 653 | const unsigned int new_value_len = strlen(new_value); |
| 654 | const unsigned int new_value_num = search_name_hashtable(new_value); |
| 655 | unsigned int want = get_status(status_node_num, 1); |
| 656 | unsigned int flag = get_status(status_node_num, 2); |
| 657 | unsigned int status = get_status(status_node_num, 3); |
| 658 | int want_len = strlen(name_hashtable[want]); |
| 659 | int flag_len = strlen(name_hashtable[flag]); |
| 660 | int status_len = strlen(name_hashtable[status]); |
| 661 | char *new_status; |
| 662 | |
| 663 | switch (position) { |
| 664 | case (1): |
| 665 | want = new_value_num; |
| 666 | want_len = new_value_len; |
| 667 | break; |
| 668 | case (2): |
| 669 | flag = new_value_num; |
| 670 | flag_len = new_value_len; |
| 671 | break; |
| 672 | case (3): |
| 673 | status = new_value_num; |
| 674 | status_len = new_value_len; |
| 675 | break; |
| 676 | default: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 677 | bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | new_status = (char *) xmalloc(want_len + flag_len + status_len + 3); |
| 681 | sprintf(new_status, "%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]); |
| 682 | status_hashtable[status_node_num]->status = search_name_hashtable(new_status); |
| 683 | free(new_status); |
| 684 | return; |
| 685 | } |
| 686 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 687 | static const char *describe_status(int status_num) { |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 688 | int status_want, status_state ; |
| 689 | if ( status_hashtable[status_num] == NULL || status_hashtable[status_num]->status == 0 ) |
| 690 | return "is not installed or flagged to be installed\n"; |
| 691 | |
| 692 | status_want = get_status(status_num, 1); |
| 693 | status_state = get_status(status_num, 3); |
| 694 | |
| 695 | if ( status_state == search_name_hashtable("installed") ) { |
| 696 | if ( status_want == search_name_hashtable("install") ) |
| 697 | return "is installed"; |
| 698 | if ( status_want == search_name_hashtable("deinstall") ) |
| 699 | return "is marked to be removed"; |
| 700 | if ( status_want == search_name_hashtable("purge") ) |
| 701 | return "is marked to be purged"; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 702 | } |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 703 | if ( status_want == search_name_hashtable("unknown") ) |
| 704 | return "is in an indeterminate state"; |
| 705 | if ( status_want == search_name_hashtable("install") ) |
| 706 | return "is marked to be installed"; |
| 707 | |
| 708 | return "is not installed or flagged to be installed"; |
| 709 | } |
| 710 | |
| 711 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 712 | static void index_status_file(const char *filename) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 713 | { |
| 714 | FILE *status_file; |
| 715 | char *control_buffer; |
| 716 | char *status_line; |
| 717 | status_node_t *status_node = NULL; |
| 718 | unsigned int status_num; |
| 719 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 720 | status_file = bb_xfopen(filename, "r"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 721 | while ((control_buffer = fgets_str(status_file, "\n\n")) != NULL) { |
| 722 | const unsigned int package_num = fill_package_struct(control_buffer); |
| 723 | if (package_num != -1) { |
| 724 | status_node = xmalloc(sizeof(status_node_t)); |
| 725 | /* fill_package_struct doesnt handle the status field */ |
| 726 | status_line = strstr(control_buffer, "Status:"); |
| 727 | if (status_line != NULL) { |
| 728 | status_line += 7; |
| 729 | status_line += strspn(status_line, " \n\t"); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 730 | status_line = bb_xstrndup(status_line, strcspn(status_line, "\n\0")); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 731 | status_node->status = search_name_hashtable(status_line); |
| 732 | free(status_line); |
| 733 | } |
| 734 | status_node->package = package_num; |
| 735 | status_num = search_status_hashtable(name_hashtable[package_hashtable[status_node->package]->name]); |
| 736 | status_hashtable[status_num] = status_node; |
| 737 | } |
| 738 | free(control_buffer); |
| 739 | } |
| 740 | fclose(status_file); |
| 741 | return; |
| 742 | } |
| 743 | |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 744 | #if 0 /* this code is no longer used */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 745 | char *get_depends_field(common_node_t *package, const int depends_type) |
| 746 | { |
| 747 | char *depends = NULL; |
| 748 | char *old_sep = (char *)xcalloc(1, 3); |
| 749 | char *new_sep = (char *)xcalloc(1, 3); |
| 750 | int line_size = 0; |
| 751 | int depends_size; |
| 752 | |
| 753 | int i; |
| 754 | |
| 755 | for (i = 0; i < package->num_of_edges; i++) { |
| 756 | if ((package->edge[i]->type == EDGE_OR_PRE_DEPENDS) || |
| 757 | (package->edge[i]->type == EDGE_OR_DEPENDS)) { |
| 758 | } |
| 759 | |
| 760 | if ((package->edge[i]->type == depends_type) || |
| 761 | (package->edge[i]->type == depends_type + 1)) { |
| 762 | /* Check if its the first time through */ |
| 763 | |
| 764 | depends_size = 8 + strlen(name_hashtable[package->edge[i]->name]) |
| 765 | + strlen(name_hashtable[package->edge[i]->version]); |
| 766 | line_size += depends_size; |
| 767 | depends = (char *) xrealloc(depends, line_size + 1); |
| 768 | |
| 769 | /* Check to see if this dependency is the type we are looking for |
| 770 | * +1 to check for 'extra' types, e.g. ored dependecies */ |
| 771 | strcpy(old_sep, new_sep); |
| 772 | if (package->edge[i]->type == depends_type) { |
| 773 | strcpy(new_sep, ", "); |
| 774 | } |
| 775 | else if (package->edge[i]->type == depends_type + 1) { |
| 776 | strcpy(new_sep, "| "); |
| 777 | } |
| 778 | |
| 779 | if (depends_size == line_size) { |
| 780 | strcpy(depends, ""); |
| 781 | } else { |
| 782 | if ((strcmp(old_sep, "| ") == 0) && (strcmp(new_sep, "| ") == 0)) { |
| 783 | strcat(depends, " | "); |
| 784 | } else { |
| 785 | strcat(depends, ", "); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | strcat(depends, name_hashtable[package->edge[i]->name]); |
| 790 | if (strcmp(name_hashtable[package->edge[i]->version], "NULL") != 0) { |
| 791 | if (package->edge[i]->operator == VER_EQUAL) { |
| 792 | strcat(depends, " (= "); |
| 793 | } |
| 794 | else if (package->edge[i]->operator == VER_LESS) { |
| 795 | strcat(depends, " (<< "); |
| 796 | } |
| 797 | else if (package->edge[i]->operator == VER_LESS_EQUAL) { |
| 798 | strcat(depends, " (<= "); |
| 799 | } |
| 800 | else if (package->edge[i]->operator == VER_MORE) { |
| 801 | strcat(depends, " (>> "); |
| 802 | } |
| 803 | else if (package->edge[i]->operator == VER_MORE_EQUAL) { |
| 804 | strcat(depends, " (>= "); |
| 805 | } else { |
| 806 | strcat(depends, " ("); |
| 807 | } |
| 808 | strcat(depends, name_hashtable[package->edge[i]->version]); |
| 809 | strcat(depends, ")"); |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | return(depends); |
| 814 | } |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 815 | #endif |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 816 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 817 | static void write_buffer_no_status(FILE *new_status_file, const char *control_buffer) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 818 | { |
| 819 | char *name; |
| 820 | char *value; |
| 821 | int start = 0; |
| 822 | while (1) { |
| 823 | start += read_package_field(&control_buffer[start], &name, &value); |
| 824 | if (name == NULL) { |
| 825 | break; |
| 826 | } |
| 827 | if (strcmp(name, "Status") != 0) { |
| 828 | fprintf(new_status_file, "%s: %s\n", name, value); |
| 829 | } |
| 830 | } |
| 831 | return; |
| 832 | } |
| 833 | |
| 834 | /* This could do with a cleanup */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 835 | static void write_status_file(deb_file_t **deb_file) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 836 | { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 837 | FILE *old_status_file = bb_xfopen("/var/lib/dpkg/status", "r"); |
| 838 | FILE *new_status_file = bb_xfopen("/var/lib/dpkg/status.udeb", "w"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 839 | char *package_name; |
| 840 | char *status_from_file; |
| 841 | char *control_buffer = NULL; |
| 842 | char *tmp_string; |
| 843 | int status_num; |
| 844 | int field_start = 0; |
| 845 | int write_flag; |
| 846 | int i = 0; |
| 847 | |
| 848 | /* Update previously known packages */ |
| 849 | while ((control_buffer = fgets_str(old_status_file, "\n\n")) != NULL) { |
| 850 | if ((tmp_string = strstr(control_buffer, "Package:")) == NULL) { |
| 851 | continue; |
| 852 | } |
| 853 | |
| 854 | tmp_string += 8; |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 855 | tmp_string += strspn(tmp_string, " \n\t"); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 856 | package_name = bb_xstrndup(tmp_string, strcspn(tmp_string, "\n\0")); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 857 | write_flag = FALSE; |
| 858 | tmp_string = strstr(control_buffer, "Status:"); |
| 859 | if (tmp_string != NULL) { |
| 860 | /* Seperate the status value from the control buffer */ |
| 861 | tmp_string += 7; |
| 862 | tmp_string += strspn(tmp_string, " \n\t"); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 863 | status_from_file = bb_xstrndup(tmp_string, strcspn(tmp_string, "\n")); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 864 | } else { |
| 865 | status_from_file = NULL; |
| 866 | } |
| 867 | |
| 868 | /* Find this package in the status hashtable */ |
| 869 | status_num = search_status_hashtable(package_name); |
| 870 | if (status_hashtable[status_num] != NULL) { |
| 871 | const char *status_from_hashtable = name_hashtable[status_hashtable[status_num]->status]; |
| 872 | if (strcmp(status_from_file, status_from_hashtable) != 0) { |
| 873 | /* New status isnt exactly the same as old status */ |
| 874 | const int state_status = get_status(status_num, 3); |
| 875 | if ((strcmp("installed", name_hashtable[state_status]) == 0) || |
| 876 | (strcmp("unpacked", name_hashtable[state_status]) == 0)) { |
| 877 | /* We need to add the control file from the package */ |
| 878 | i = 0; |
| 879 | while(deb_file[i] != NULL) { |
| 880 | if (strcmp(package_name, name_hashtable[package_hashtable[deb_file[i]->package]->name]) == 0) { |
| 881 | /* Write a status file entry with a modified status */ |
| 882 | /* remove trailing \n's */ |
| 883 | write_buffer_no_status(new_status_file, deb_file[i]->control_file); |
| 884 | set_status(status_num, "ok", 2); |
| 885 | fprintf(new_status_file, "Status: %s\n\n", name_hashtable[status_hashtable[status_num]->status]); |
| 886 | write_flag = TRUE; |
| 887 | break; |
| 888 | } |
| 889 | i++; |
| 890 | } |
| 891 | /* This is temperary, debugging only */ |
| 892 | if (deb_file[i] == NULL) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 893 | bb_error_msg_and_die("ALERT: Couldnt find a control file, your status file may be broken, status may be incorrect for %s", package_name); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | else if (strcmp("not-installed", name_hashtable[state_status]) == 0) { |
| 897 | /* Only write the Package, Status, Priority and Section lines */ |
| 898 | fprintf(new_status_file, "Package: %s\n", package_name); |
| 899 | fprintf(new_status_file, "Status: %s\n", status_from_hashtable); |
| 900 | |
| 901 | while (1) { |
| 902 | char *field_name; |
| 903 | char *field_value; |
| 904 | field_start += read_package_field(&control_buffer[field_start], &field_name, &field_value); |
| 905 | if (field_name == NULL) { |
| 906 | break; |
| 907 | } |
| 908 | if ((strcmp(field_name, "Priority") == 0) || |
| 909 | (strcmp(field_name, "Section") == 0)) { |
| 910 | fprintf(new_status_file, "%s: %s\n", field_name, field_value); |
| 911 | } |
| 912 | } |
| 913 | write_flag = TRUE; |
| 914 | fputs("\n", new_status_file); |
| 915 | } |
| 916 | else if (strcmp("config-files", name_hashtable[state_status]) == 0) { |
| 917 | /* only change the status line */ |
| 918 | while (1) { |
| 919 | char *field_name; |
| 920 | char *field_value; |
| 921 | field_start += read_package_field(&control_buffer[field_start], &field_name, &field_value); |
| 922 | if (field_name == NULL) { |
| 923 | break; |
| 924 | } |
| 925 | /* Setup start point for next field */ |
| 926 | if (strcmp(field_name, "Status") == 0) { |
| 927 | fprintf(new_status_file, "Status: %s\n", status_from_hashtable); |
| 928 | } else { |
| 929 | fprintf(new_status_file, "%s: %s\n", field_name, field_value); |
| 930 | } |
| 931 | } |
| 932 | write_flag = TRUE; |
| 933 | fputs("\n", new_status_file); |
| 934 | } |
| 935 | } |
| 936 | } |
| 937 | /* If the package from the status file wasnt handle above, do it now*/ |
Matt Kraai | 1f0c436 | 2001-12-20 23:13:26 +0000 | [diff] [blame] | 938 | if (! write_flag) { |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 939 | fprintf(new_status_file, "%s\n\n", control_buffer); |
| 940 | } |
| 941 | |
Aaron Lehmann | a170e1c | 2002-11-28 11:27:31 +0000 | [diff] [blame] | 942 | free(status_from_file); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 943 | free(package_name); |
| 944 | free(control_buffer); |
| 945 | } |
| 946 | |
| 947 | /* Write any new packages */ |
| 948 | for(i = 0; deb_file[i] != NULL; i++) { |
| 949 | status_num = search_status_hashtable(name_hashtable[package_hashtable[deb_file[i]->package]->name]); |
| 950 | if (strcmp("reinstreq", name_hashtable[get_status(status_num, 2)]) == 0) { |
| 951 | write_buffer_no_status(new_status_file, deb_file[i]->control_file); |
| 952 | set_status(status_num, "ok", 2); |
| 953 | fprintf(new_status_file, "Status: %s\n\n", name_hashtable[status_hashtable[status_num]->status]); |
| 954 | } |
| 955 | } |
| 956 | fclose(old_status_file); |
| 957 | fclose(new_status_file); |
| 958 | |
| 959 | |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 960 | /* Create a separate backfile to dpkg */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 961 | if (rename("/var/lib/dpkg/status", "/var/lib/dpkg/status.udeb.bak") == -1) { |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 962 | struct stat stat_buf; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 963 | if (stat("/var/lib/dpkg/status", &stat_buf) == 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 964 | bb_error_msg_and_die("Couldnt create backup status file"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 965 | } |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 966 | /* Its ok if renaming the status file fails because status |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 967 | * file doesnt exist, maybe we are starting from scratch */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 968 | bb_error_msg("No status file found, creating new one"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | if (rename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status") == -1) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 972 | bb_error_msg_and_die("DANGER: Couldnt create status file, you need to manually repair your status file"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 976 | /* This function returns TRUE if the given package can satisfy a |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 977 | * dependency of type depend_type. |
| 978 | * |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 979 | * A pre-depends is satisfied only if a package is already installed, |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 980 | * which a regular depends can be satisfied by a package which we want |
| 981 | * to install. |
| 982 | */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 983 | static int package_satisfies_dependency(int package, int depend_type) |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 984 | { |
| 985 | int status_num = search_status_hashtable(name_hashtable[package_hashtable[package]->name]); |
| 986 | |
| 987 | /* status could be unknown if package is a pure virtual |
| 988 | * provides which cannot satisfy any dependency by itself. |
| 989 | */ |
| 990 | if ( status_hashtable[status_num] == NULL ) |
| 991 | return 0; |
| 992 | |
| 993 | switch (depend_type) { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 994 | case EDGE_PRE_DEPENDS: return get_status(status_num, 3) == search_name_hashtable("installed"); |
| 995 | case EDGE_DEPENDS: return get_status(status_num, 1) == search_name_hashtable("install"); |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 996 | } |
| 997 | return 0; |
| 998 | } |
| 999 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 1000 | static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1001 | { |
| 1002 | int *conflicts = NULL; |
| 1003 | int conflicts_num = 0; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1004 | int i = deb_start; |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1005 | int j; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1006 | |
| 1007 | /* Check for conflicts |
| 1008 | * TODO: TEST if conflicts with other packages to be installed |
| 1009 | * |
| 1010 | * Add install packages and the packages they provide |
| 1011 | * to the list of files to check conflicts for |
| 1012 | */ |
| 1013 | |
| 1014 | /* Create array of package numbers to check against |
| 1015 | * installed package for conflicts*/ |
| 1016 | while (deb_file[i] != NULL) { |
| 1017 | const unsigned int package_num = deb_file[i]->package; |
| 1018 | conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1)); |
| 1019 | conflicts[conflicts_num] = package_num; |
| 1020 | conflicts_num++; |
| 1021 | /* add provides to conflicts list */ |
| 1022 | for (j = 0; j < package_hashtable[package_num]->num_of_edges; j++) { |
| 1023 | if (package_hashtable[package_num]->edge[j]->type == EDGE_PROVIDES) { |
| 1024 | const int conflicts_package_num = search_package_hashtable( |
| 1025 | package_hashtable[package_num]->edge[j]->name, |
| 1026 | package_hashtable[package_num]->edge[j]->version, |
| 1027 | package_hashtable[package_num]->edge[j]->operator); |
| 1028 | if (package_hashtable[conflicts_package_num] == NULL) { |
| 1029 | /* create a new package */ |
| 1030 | common_node_t *new_node = (common_node_t *) xmalloc(sizeof(common_node_t)); |
| 1031 | new_node->name = package_hashtable[package_num]->edge[j]->name; |
| 1032 | new_node->version = package_hashtable[package_num]->edge[j]->version; |
| 1033 | new_node->num_of_edges = 0; |
| 1034 | new_node->edge = NULL; |
| 1035 | package_hashtable[conflicts_package_num] = new_node; |
| 1036 | } |
| 1037 | conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1)); |
| 1038 | conflicts[conflicts_num] = conflicts_package_num; |
| 1039 | conflicts_num++; |
| 1040 | } |
| 1041 | } |
| 1042 | i++; |
| 1043 | } |
| 1044 | |
| 1045 | /* Check conflicts */ |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1046 | i = 0; |
| 1047 | while (deb_file[i] != NULL) { |
| 1048 | const common_node_t *package_node = package_hashtable[deb_file[i]->package]; |
| 1049 | int status_num = 0; |
| 1050 | status_num = search_status_hashtable(name_hashtable[package_node->name]); |
| 1051 | |
| 1052 | if (get_status(status_num, 3) == search_name_hashtable("installed")) { |
| 1053 | i++; |
| 1054 | continue; |
| 1055 | } |
| 1056 | |
| 1057 | for (j = 0; j < package_node->num_of_edges; j++) { |
| 1058 | const edge_t *package_edge = package_node->edge[j]; |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1059 | |
| 1060 | if (package_edge->type == EDGE_CONFLICTS) { |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1061 | const unsigned int package_num = |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1062 | search_package_hashtable(package_edge->name, |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1063 | package_edge->version, |
| 1064 | package_edge->operator); |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1065 | int result = 0; |
| 1066 | if (package_hashtable[package_num] != NULL) { |
| 1067 | status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]); |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1068 | |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1069 | if (get_status(status_num, 1) == search_name_hashtable("install")) { |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1070 | result = test_version(package_hashtable[deb_file[i]->package]->version, |
| 1071 | package_edge->version, package_edge->operator); |
| 1072 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1073 | } |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1074 | |
| 1075 | if (result) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1076 | bb_error_msg_and_die("Package %s conflicts with %s", |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1077 | name_hashtable[package_node->name], |
| 1078 | name_hashtable[package_edge->name]); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1079 | } |
| 1080 | } |
| 1081 | } |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1082 | i++; |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 1083 | } |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1084 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1085 | |
| 1086 | /* Check dependendcies */ |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1087 | for (i = 0; i < PACKAGE_HASH_PRIME; i++) { |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1088 | int status_num = 0; |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1089 | int number_of_alternatives = 0; |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 1090 | const edge_t * root_of_alternatives = NULL; |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1091 | const common_node_t *package_node = package_hashtable[i]; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1092 | |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1093 | /* If the package node does not exist then this |
| 1094 | * package is a virtual one. In which case there are |
| 1095 | * no dependencies to check. |
| 1096 | */ |
| 1097 | if ( package_node == NULL ) continue; |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1098 | |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1099 | status_num = search_status_hashtable(name_hashtable[package_node->name]); |
| 1100 | |
| 1101 | /* If there is no status then this package is a |
| 1102 | * virtual one provided by something else. In which |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1103 | * case there are no dependencies to check. |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1104 | */ |
| 1105 | if ( status_hashtable[status_num] == NULL ) continue; |
| 1106 | |
| 1107 | /* If we don't want this package installed then we may |
| 1108 | * as well ignore it's dependencies. |
| 1109 | */ |
| 1110 | if (get_status(status_num, 1) != search_name_hashtable("install")) { |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1111 | continue; |
| 1112 | } |
| 1113 | |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1114 | #if 0 |
| 1115 | /* This might be needed so we don't complain about |
| 1116 | * things which are broken but unrelated to the |
| 1117 | * packages that are currently being installed |
| 1118 | */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 1119 | if (state_status == search_name_hashtable("installed")) |
| 1120 | continue; |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1121 | #endif |
| 1122 | |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 1123 | /* This code is tested only for EDGE_DEPENDS, since I |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1124 | * have no suitable pre-depends available. There is no |
| 1125 | * reason that it shouldn't work though :-) |
| 1126 | */ |
| 1127 | for (j = 0; j < package_node->num_of_edges; j++) { |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1128 | const edge_t *package_edge = package_node->edge[j]; |
Glenn L McGrath | 1dbbd2f | 2001-12-05 04:10:14 +0000 | [diff] [blame] | 1129 | unsigned int package_num; |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 1130 | |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1131 | if ( package_edge->type == EDGE_OR_PRE_DEPENDS || |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 1132 | package_edge->type == EDGE_OR_DEPENDS ) { /* start an EDGE_OR_ list */ |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1133 | number_of_alternatives = package_edge->version; |
| 1134 | root_of_alternatives = package_edge; |
| 1135 | continue; |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 1136 | } else if ( number_of_alternatives == 0 ) { /* not in the middle of an EDGE_OR_ list */ |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1137 | number_of_alternatives = 1; |
| 1138 | root_of_alternatives = NULL; |
| 1139 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1140 | |
Glenn L McGrath | 1dbbd2f | 2001-12-05 04:10:14 +0000 | [diff] [blame] | 1141 | package_num = search_package_hashtable(package_edge->name, package_edge->version, package_edge->operator); |
Glenn L McGrath | 1dbbd2f | 2001-12-05 04:10:14 +0000 | [diff] [blame] | 1142 | |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1143 | if (package_edge->type == EDGE_PRE_DEPENDS || |
| 1144 | package_edge->type == EDGE_DEPENDS ) { |
| 1145 | int result=1; |
| 1146 | status_num = 0; |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1147 | |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1148 | /* If we are inside an alternative then check |
| 1149 | * this edge is the right type. |
| 1150 | * |
| 1151 | * EDGE_DEPENDS == OR_DEPENDS -1 |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1152 | * EDGE_PRE_DEPENDS == OR_PRE_DEPENDS -1 |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1153 | */ |
| 1154 | if ( root_of_alternatives && package_edge->type != root_of_alternatives->type - 1) |
| 1155 | bb_error_msg_and_die("Fatal error. Package dependencies corrupt: %d != %d - 1 \n", |
| 1156 | package_edge->type, root_of_alternatives->type); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1157 | |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1158 | if (package_hashtable[package_num] != NULL) |
| 1159 | result = !package_satisfies_dependency(package_num, package_edge->type); |
| 1160 | |
| 1161 | if (result) { /* check for other package which provide what we are looking for */ |
| 1162 | int provider = -1; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1163 | |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1164 | while ( (provider = search_for_provides(package_edge->name, provider) ) > -1 ) { |
| 1165 | if ( package_hashtable[provider] == NULL ) { |
| 1166 | printf("Have a provider but no package information for it\n"); |
| 1167 | continue; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1168 | } |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1169 | result = !package_satisfies_dependency(provider, package_edge->type); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1170 | |
| 1171 | if ( result == 0 ) |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1172 | break; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1173 | } |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1174 | } |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1175 | |
| 1176 | /* It must be already installed, or to be installed */ |
| 1177 | number_of_alternatives--; |
| 1178 | if (result && number_of_alternatives == 0) { |
| 1179 | if ( root_of_alternatives ) |
| 1180 | bb_error_msg_and_die( |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1181 | "Package %s %sdepends on %s, " |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1182 | "which cannot be satisfied", |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1183 | name_hashtable[package_node->name], |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1184 | package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "", |
| 1185 | name_hashtable[root_of_alternatives->name]); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1186 | else |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1187 | bb_error_msg_and_die( |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1188 | "Package %s %sdepends on %s, which %s\n", |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1189 | name_hashtable[package_node->name], |
| 1190 | package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "", |
| 1191 | name_hashtable[package_edge->name], |
| 1192 | describe_status(status_num)); |
| 1193 | } else if ( result == 0 && number_of_alternatives ) { |
| 1194 | /* we've found a package which |
| 1195 | * satisfies the dependency, |
| 1196 | * so skip over the rest of |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1197 | * the alternatives. |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1198 | */ |
| 1199 | j += number_of_alternatives; |
| 1200 | number_of_alternatives = 0; |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1201 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1202 | } |
| 1203 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1204 | } |
| 1205 | free(conflicts); |
| 1206 | return(TRUE); |
| 1207 | } |
| 1208 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 1209 | static char **create_list(const char *filename) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1210 | { |
| 1211 | FILE *list_stream; |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1212 | char **file_list = NULL; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1213 | char *line = NULL; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1214 | int count = 0; |
| 1215 | |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 1216 | /* don't use [xw]fopen here, handle error ourself */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1217 | list_stream = fopen(filename, "r"); |
| 1218 | if (list_stream == NULL) { |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1219 | return(NULL); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1220 | } |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1221 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1222 | while ((line = bb_get_chomped_line_from_file(list_stream)) != NULL) { |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1223 | file_list = xrealloc(file_list, sizeof(char *) * (count + 2)); |
Glenn L McGrath | b323162 | 2002-12-11 03:10:13 +0000 | [diff] [blame] | 1224 | file_list[count] = line; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1225 | count++; |
| 1226 | } |
| 1227 | fclose(list_stream); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1228 | |
| 1229 | if (count == 0) { |
| 1230 | return(NULL); |
| 1231 | } else { |
| 1232 | file_list[count] = NULL; |
| 1233 | return(file_list); |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | /* maybe i should try and hook this into remove_file.c somehow */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 1238 | static int remove_file_array(char **remove_names, char **exclude_names) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1239 | { |
| 1240 | struct stat path_stat; |
| 1241 | int match_flag; |
| 1242 | int remove_flag = FALSE; |
| 1243 | int i,j; |
| 1244 | |
| 1245 | if (remove_names == NULL) { |
| 1246 | return(FALSE); |
| 1247 | } |
| 1248 | for (i = 0; remove_names[i] != NULL; i++) { |
| 1249 | match_flag = FALSE; |
| 1250 | if (exclude_names != NULL) { |
| 1251 | for (j = 0; exclude_names[j] != 0; j++) { |
| 1252 | if (strcmp(remove_names[i], exclude_names[j]) == 0) { |
| 1253 | match_flag = TRUE; |
| 1254 | break; |
| 1255 | } |
| 1256 | } |
| 1257 | } |
| 1258 | if (!match_flag) { |
| 1259 | if (lstat(remove_names[i], &path_stat) < 0) { |
| 1260 | continue; |
| 1261 | } |
| 1262 | if (S_ISDIR(path_stat.st_mode)) { |
| 1263 | if (rmdir(remove_names[i]) != -1) { |
| 1264 | remove_flag = TRUE; |
| 1265 | } |
| 1266 | } else { |
| 1267 | if (unlink(remove_names[i]) != -1) { |
| 1268 | remove_flag = TRUE; |
| 1269 | } |
| 1270 | } |
| 1271 | } |
| 1272 | } |
| 1273 | return(remove_flag); |
| 1274 | } |
| 1275 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 1276 | static int run_package_script(const char *package_name, const char *script_type) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1277 | { |
| 1278 | struct stat path_stat; |
| 1279 | char *script_path; |
| 1280 | int result; |
| 1281 | |
| 1282 | script_path = xmalloc(strlen(package_name) + strlen(script_type) + 21); |
| 1283 | sprintf(script_path, "/var/lib/dpkg/info/%s.%s", package_name, script_type); |
| 1284 | |
| 1285 | /* If the file doesnt exist is isnt a fatal */ |
| 1286 | if (lstat(script_path, &path_stat) < 0) { |
| 1287 | result = EXIT_SUCCESS; |
| 1288 | } else { |
| 1289 | result = system(script_path); |
| 1290 | } |
| 1291 | free(script_path); |
| 1292 | return(result); |
| 1293 | } |
| 1294 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 1295 | static const char *all_control_files[] = {"preinst", "postinst", "prerm", "postrm", |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1296 | "list", "md5sums", "shlibs", "conffiles", "config", "templates", NULL }; |
| 1297 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 1298 | static char **all_control_list(const char *package_name) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1299 | { |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1300 | unsigned short i = 0; |
| 1301 | char **remove_files; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1302 | |
| 1303 | /* Create a list of all /var/lib/dpkg/info/<package> files */ |
Mike Frysinger | 1eef0c4 | 2005-08-16 05:32:42 +0000 | [diff] [blame] | 1304 | remove_files = xmalloc(sizeof(all_control_files)); |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1305 | while (all_control_files[i]) { |
| 1306 | remove_files[i] = xmalloc(strlen(package_name) + strlen(all_control_files[i]) + 21); |
| 1307 | sprintf(remove_files[i], "/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]); |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1308 | i++; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1309 | } |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1310 | remove_files[sizeof(all_control_files)/sizeof(char*) - 1] = NULL; |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1311 | |
| 1312 | return(remove_files); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 1315 | static void free_array(char **array) |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1316 | { |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1317 | |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1318 | if (array) { |
| 1319 | unsigned short i = 0; |
| 1320 | while (array[i]) { |
| 1321 | free(array[i]); |
| 1322 | i++; |
| 1323 | } |
| 1324 | free(array); |
| 1325 | } |
| 1326 | } |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1327 | |
| 1328 | /* This function lists information on the installed packages. It loops through |
| 1329 | * the status_hashtable to retrieve the info. This results in smaller code than |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1330 | * scanning the status file. The resulting list, however, is unsorted. |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1331 | */ |
Mike Frysinger | 4e5936e | 2005-04-16 04:30:38 +0000 | [diff] [blame] | 1332 | static void list_packages(void) |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1333 | { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 1334 | int i; |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1335 | |
| 1336 | printf(" Name Version\n"); |
| 1337 | printf("+++-==============-==============\n"); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1338 | |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1339 | /* go through status hash, dereference package hash and finally strings */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1340 | for (i=0; i<STATUS_HASH_PRIME+1; i++) { |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1341 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1342 | if (status_hashtable[i]) { |
| 1343 | const char *stat_str; /* status string */ |
| 1344 | const char *name_str; /* package name */ |
| 1345 | const char *vers_str; /* version */ |
| 1346 | char s1, s2; /* status abbreviations */ |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1347 | int spccnt; /* space count */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1348 | int j; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1349 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1350 | stat_str = name_hashtable[status_hashtable[i]->status]; |
| 1351 | name_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->name]; |
| 1352 | vers_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->version]; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1353 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1354 | /* get abbreviation for status field 1 */ |
| 1355 | s1 = stat_str[0] == 'i' ? 'i' : 'r'; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1356 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1357 | /* get abbreviation for status field 2 */ |
| 1358 | for (j=0, spccnt=0; stat_str[j] && spccnt<2; j++) { |
| 1359 | if (stat_str[j] == ' ') spccnt++; |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1360 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1361 | s2 = stat_str[j]; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1362 | |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1363 | /* print out the line formatted like Debian dpkg */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1364 | printf("%c%c %-14s %s\n", s1, s2, name_str, vers_str); |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1368 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 1369 | static void remove_package(const unsigned int package_num, int noisy) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1370 | { |
| 1371 | const char *package_name = name_hashtable[package_hashtable[package_num]->name]; |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1372 | const char *package_version = name_hashtable[package_hashtable[package_num]->version]; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1373 | const unsigned int status_num = search_status_hashtable(package_name); |
| 1374 | const int package_name_length = strlen(package_name); |
| 1375 | char **remove_files; |
| 1376 | char **exclude_files; |
| 1377 | char list_name[package_name_length + 25]; |
| 1378 | char conffile_name[package_name_length + 30]; |
| 1379 | int return_value; |
| 1380 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1381 | if ( noisy ) |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1382 | printf("Removing %s (%s) ...\n", package_name, package_version); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1383 | |
| 1384 | /* run prerm script */ |
| 1385 | return_value = run_package_script(package_name, "prerm"); |
| 1386 | if (return_value == -1) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1387 | bb_error_msg_and_die("script failed, prerm failure"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 1390 | /* Create a list of files to remove, and a separate list of those to keep */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1391 | sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name); |
| 1392 | remove_files = create_list(list_name); |
| 1393 | |
| 1394 | sprintf(conffile_name, "/var/lib/dpkg/info/%s.conffiles", package_name); |
| 1395 | exclude_files = create_list(conffile_name); |
| 1396 | |
| 1397 | /* Some directories cant be removed straight away, so do multiple passes */ |
Matt Kraai | 1f0c436 | 2001-12-20 23:13:26 +0000 | [diff] [blame] | 1398 | while (remove_file_array(remove_files, exclude_files)); |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1399 | free_array(exclude_files); |
| 1400 | free_array(remove_files); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1401 | |
| 1402 | /* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */ |
| 1403 | exclude_files = xmalloc(sizeof(char*) * 3); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1404 | exclude_files[0] = bb_xstrdup(conffile_name); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1405 | exclude_files[1] = xmalloc(package_name_length + 27); |
| 1406 | sprintf(exclude_files[1], "/var/lib/dpkg/info/%s.postrm", package_name); |
| 1407 | exclude_files[2] = NULL; |
| 1408 | |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1409 | /* Create a list of all /var/lib/dpkg/info/<package> files */ |
| 1410 | remove_files = all_control_list(package_name); |
| 1411 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1412 | remove_file_array(remove_files, exclude_files); |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1413 | free_array(remove_files); |
| 1414 | free_array(exclude_files); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1415 | |
| 1416 | /* rename <package>.conffile to <package>.list */ |
| 1417 | rename(conffile_name, list_name); |
| 1418 | |
| 1419 | /* Change package status */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1420 | set_status(status_num, "config-files", 3); |
| 1421 | } |
| 1422 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 1423 | static void purge_package(const unsigned int package_num) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1424 | { |
| 1425 | const char *package_name = name_hashtable[package_hashtable[package_num]->name]; |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1426 | const char *package_version = name_hashtable[package_hashtable[package_num]->version]; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1427 | const unsigned int status_num = search_status_hashtable(package_name); |
| 1428 | char **remove_files; |
| 1429 | char **exclude_files; |
| 1430 | char list_name[strlen(package_name) + 25]; |
| 1431 | |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1432 | printf("Purging %s (%s) ...\n", package_name, package_version); |
| 1433 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1434 | /* run prerm script */ |
| 1435 | if (run_package_script(package_name, "prerm") != 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1436 | bb_error_msg_and_die("script failed, prerm failure"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | /* Create a list of files to remove */ |
| 1440 | sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name); |
| 1441 | remove_files = create_list(list_name); |
| 1442 | |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1443 | exclude_files = xmalloc(sizeof(char*)); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1444 | exclude_files[0] = NULL; |
| 1445 | |
| 1446 | /* Some directories cant be removed straight away, so do multiple passes */ |
Matt Kraai | 1f0c436 | 2001-12-20 23:13:26 +0000 | [diff] [blame] | 1447 | while (remove_file_array(remove_files, exclude_files)); |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1448 | free_array(remove_files); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1449 | |
| 1450 | /* Create a list of all /var/lib/dpkg/info/<package> files */ |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1451 | remove_files = all_control_list(package_name); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1452 | remove_file_array(remove_files, exclude_files); |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1453 | free_array(remove_files); |
| 1454 | free(exclude_files); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1455 | |
| 1456 | /* run postrm script */ |
| 1457 | if (run_package_script(package_name, "postrm") == -1) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1458 | bb_error_msg_and_die("postrm fialure.. set status to what?"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | /* Change package status */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1462 | set_status(status_num, "not-installed", 3); |
| 1463 | } |
| 1464 | |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1465 | static archive_handle_t *init_archive_deb_ar(const char *filename) |
Glenn L McGrath | 61b7904 | 2002-10-19 10:40:55 +0000 | [diff] [blame] | 1466 | { |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1467 | archive_handle_t *ar_handle; |
Glenn L McGrath | 61b7904 | 2002-10-19 10:40:55 +0000 | [diff] [blame] | 1468 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1469 | /* Setup an ar archive handle that refers to the gzip sub archive */ |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1470 | ar_handle = init_handle(); |
| 1471 | ar_handle->filter = filter_accept_list_reassign; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1472 | ar_handle->src_fd = bb_xopen(filename, O_RDONLY); |
Glenn L McGrath | 61b7904 | 2002-10-19 10:40:55 +0000 | [diff] [blame] | 1473 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1474 | return(ar_handle); |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1475 | } |
Glenn L McGrath | 61b7904 | 2002-10-19 10:40:55 +0000 | [diff] [blame] | 1476 | |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1477 | static void init_archive_deb_control(archive_handle_t *ar_handle) |
| 1478 | { |
| 1479 | archive_handle_t *tar_handle; |
| 1480 | |
| 1481 | /* Setup the tar archive handle */ |
| 1482 | tar_handle = init_handle(); |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1483 | tar_handle->src_fd = ar_handle->src_fd; |
| 1484 | |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 1485 | /* We don't care about data.tar.* or debian-binary, just control.tar.* */ |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1486 | #ifdef CONFIG_FEATURE_DEB_TAR_GZ |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 1487 | ar_handle->accept = llist_add_to(NULL, "control.tar.gz"); |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1488 | #endif |
| 1489 | #ifdef CONFIG_FEATURE_DEB_TAR_BZ2 |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 1490 | ar_handle->accept = llist_add_to(ar_handle->accept, "control.tar.bz2"); |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1491 | #endif |
| 1492 | |
| 1493 | /* Assign the tar handle as a subarchive of the ar handle */ |
| 1494 | ar_handle->sub_archive = tar_handle; |
| 1495 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1496 | return; |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | static void init_archive_deb_data(archive_handle_t *ar_handle) |
| 1500 | { |
| 1501 | archive_handle_t *tar_handle; |
| 1502 | |
| 1503 | /* Setup the tar archive handle */ |
| 1504 | tar_handle = init_handle(); |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1505 | tar_handle->src_fd = ar_handle->src_fd; |
| 1506 | |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 1507 | /* We don't care about control.tar.* or debian-binary, just data.tar.* */ |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1508 | #ifdef CONFIG_FEATURE_DEB_TAR_GZ |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1509 | ar_handle->accept = llist_add_to(NULL, "data.tar.gz"); |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1510 | #endif |
| 1511 | #ifdef CONFIG_FEATURE_DEB_TAR_BZ2 |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1512 | ar_handle->accept = llist_add_to(ar_handle->accept, "data.tar.bz2"); |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1513 | #endif |
| 1514 | |
| 1515 | /* Assign the tar handle as a subarchive of the ar handle */ |
| 1516 | ar_handle->sub_archive = tar_handle; |
| 1517 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1518 | return; |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
Eric Andersen | 1393a39 | 2003-09-15 08:06:15 +0000 | [diff] [blame] | 1521 | static char *deb_extract_control_file_to_buffer(archive_handle_t *ar_handle, llist_t *myaccept) |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1522 | { |
| 1523 | ar_handle->sub_archive->action_data = data_extract_to_buffer; |
Eric Andersen | 1393a39 | 2003-09-15 08:06:15 +0000 | [diff] [blame] | 1524 | ar_handle->sub_archive->accept = myaccept; |
Paul Fox | 37dd624 | 2005-07-22 13:17:41 +0000 | [diff] [blame] | 1525 | ar_handle->sub_archive->filter = filter_accept_list; |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1526 | |
| 1527 | unpack_ar_archive(ar_handle); |
| 1528 | close(ar_handle->src_fd); |
| 1529 | |
| 1530 | return(ar_handle->sub_archive->buffer); |
Glenn L McGrath | 61b7904 | 2002-10-19 10:40:55 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
Glenn L McGrath | 6ab32eb | 2002-11-03 11:57:10 +0000 | [diff] [blame] | 1533 | static void data_extract_all_prefix(archive_handle_t *archive_handle) |
| 1534 | { |
| 1535 | char *name_ptr = archive_handle->file_header->name; |
| 1536 | |
| 1537 | name_ptr += strspn(name_ptr, "./"); |
| 1538 | if (name_ptr[0] != '\0') { |
| 1539 | archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 2 + strlen(name_ptr)); |
| 1540 | strcpy(archive_handle->file_header->name, archive_handle->buffer); |
| 1541 | strcat(archive_handle->file_header->name, name_ptr); |
| 1542 | data_extract_all(archive_handle); |
| 1543 | } |
| 1544 | return; |
| 1545 | } |
| 1546 | |
| 1547 | static void unpack_package(deb_file_t *deb_file) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1548 | { |
| 1549 | const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name]; |
| 1550 | const unsigned int status_num = search_status_hashtable(package_name); |
| 1551 | const unsigned int status_package_num = status_hashtable[status_num]->package; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1552 | char *info_prefix; |
Glenn L McGrath | 61b7904 | 2002-10-19 10:40:55 +0000 | [diff] [blame] | 1553 | archive_handle_t *archive_handle; |
| 1554 | FILE *out_stream; |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1555 | llist_t *accept_list = NULL; |
| 1556 | int i = 0; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1557 | |
| 1558 | /* If existing version, remove it first */ |
| 1559 | if (strcmp(name_hashtable[get_status(status_num, 3)], "installed") == 0) { |
| 1560 | /* Package is already installed, remove old version first */ |
| 1561 | printf("Preparing to replace %s %s (using %s) ...\n", package_name, |
| 1562 | name_hashtable[package_hashtable[status_package_num]->version], |
| 1563 | deb_file->filename); |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1564 | remove_package(status_package_num, 0); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1565 | } else { |
| 1566 | printf("Unpacking %s (from %s) ...\n", package_name, deb_file->filename); |
| 1567 | } |
| 1568 | |
| 1569 | /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */ |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1570 | info_prefix = (char *) xmalloc(strlen(package_name) + 20 + 4 + 2); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1571 | sprintf(info_prefix, "/var/lib/dpkg/info/%s.", package_name); |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1572 | archive_handle = init_archive_deb_ar(deb_file->filename); |
| 1573 | init_archive_deb_control(archive_handle); |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1574 | |
| 1575 | while(all_control_files[i]) { |
| 1576 | char *c = (char *) xmalloc(3 + bb_strlen(all_control_files[i])); |
| 1577 | sprintf(c, "./%s", all_control_files[i]); |
| 1578 | accept_list= llist_add_to(accept_list, c); |
| 1579 | i++; |
| 1580 | } |
| 1581 | archive_handle->sub_archive->accept = accept_list; |
| 1582 | archive_handle->sub_archive->filter = filter_accept_list; |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1583 | archive_handle->sub_archive->action_data = data_extract_all_prefix; |
| 1584 | archive_handle->sub_archive->buffer = info_prefix; |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1585 | archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL; |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1586 | unpack_ar_archive(archive_handle); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1587 | |
| 1588 | /* Run the preinst prior to extracting */ |
| 1589 | if (run_package_script(package_name, "preinst") != 0) { |
| 1590 | /* when preinst returns exit code != 0 then quit installation process */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1591 | bb_error_msg_and_die("subprocess pre-installation script returned error."); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1592 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1593 | |
| 1594 | /* Extract data.tar.gz to the root directory */ |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1595 | archive_handle = init_archive_deb_ar(deb_file->filename); |
| 1596 | init_archive_deb_data(archive_handle); |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1597 | archive_handle->sub_archive->action_data = data_extract_all_prefix; |
| 1598 | archive_handle->sub_archive->buffer = "/"; |
| 1599 | archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL; |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1600 | unpack_ar_archive(archive_handle); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1601 | |
| 1602 | /* Create the list file */ |
| 1603 | strcat(info_prefix, "list"); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1604 | out_stream = bb_xfopen(info_prefix, "w"); |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1605 | while (archive_handle->sub_archive->passed) { |
| 1606 | /* the leading . has been stripped by data_extract_all_prefix already */ |
| 1607 | fputs(archive_handle->sub_archive->passed->data, out_stream); |
Glenn L McGrath | 61b7904 | 2002-10-19 10:40:55 +0000 | [diff] [blame] | 1608 | fputc('\n', out_stream); |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1609 | archive_handle->sub_archive->passed = archive_handle->sub_archive->passed->link; |
Glenn L McGrath | 61b7904 | 2002-10-19 10:40:55 +0000 | [diff] [blame] | 1610 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1611 | fclose(out_stream); |
| 1612 | |
| 1613 | /* change status */ |
| 1614 | set_status(status_num, "install", 1); |
| 1615 | set_status(status_num, "unpacked", 3); |
| 1616 | |
| 1617 | free(info_prefix); |
| 1618 | } |
| 1619 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 1620 | static void configure_package(deb_file_t *deb_file) |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1621 | { |
| 1622 | const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name]; |
| 1623 | const char *package_version = name_hashtable[package_hashtable[deb_file->package]->version]; |
| 1624 | const int status_num = search_status_hashtable(package_name); |
| 1625 | |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1626 | printf("Setting up %s (%s) ...\n", package_name, package_version); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1627 | |
| 1628 | /* Run the postinst script */ |
| 1629 | if (run_package_script(package_name, "postinst") != 0) { |
| 1630 | /* TODO: handle failure gracefully */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1631 | bb_error_msg_and_die("postrm failure.. set status to what?"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1632 | } |
| 1633 | /* Change status to reflect success */ |
| 1634 | set_status(status_num, "install", 1); |
| 1635 | set_status(status_num, "installed", 3); |
| 1636 | } |
Glenn L McGrath | c900575 | 2001-02-10 02:05:24 +0000 | [diff] [blame] | 1637 | |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1638 | int dpkg_main(int argc, char **argv) |
Glenn L McGrath | c900575 | 2001-02-10 02:05:24 +0000 | [diff] [blame] | 1639 | { |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1640 | deb_file_t **deb_file = NULL; |
| 1641 | status_node_t *status_node; |
Matt Kraai | efd7f03 | 2001-11-19 21:07:15 +0000 | [diff] [blame] | 1642 | int opt; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1643 | int package_num; |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1644 | int dpkg_opt = 0; |
| 1645 | int deb_count = 0; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1646 | int state_status; |
| 1647 | int status_num; |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1648 | int i; |
Glenn L McGrath | 0e757a2 | 2001-04-08 05:27:18 +0000 | [diff] [blame] | 1649 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1650 | while ((opt = getopt(argc, argv, "CF:ilPru")) != -1) { |
Glenn L McGrath | 0e757a2 | 2001-04-08 05:27:18 +0000 | [diff] [blame] | 1651 | switch (opt) { |
Glenn L McGrath | 778041f | 2001-07-18 05:17:39 +0000 | [diff] [blame] | 1652 | case 'C': // equivalent to --configure in official dpkg |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1653 | dpkg_opt |= dpkg_opt_configure; |
| 1654 | dpkg_opt |= dpkg_opt_package_name; |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1655 | break; |
| 1656 | case 'F': // equivalent to --force in official dpkg |
| 1657 | if (strcmp(optarg, "depends") == 0) { |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1658 | dpkg_opt |= dpkg_opt_force_ignore_depends; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1659 | } |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1660 | break; |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1661 | case 'i': |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1662 | dpkg_opt |= dpkg_opt_install; |
| 1663 | dpkg_opt |= dpkg_opt_filename; |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1664 | break; |
| 1665 | case 'l': |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1666 | dpkg_opt |= dpkg_opt_list_installed; |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1667 | break; |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1668 | case 'P': |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1669 | dpkg_opt |= dpkg_opt_purge; |
| 1670 | dpkg_opt |= dpkg_opt_package_name; |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1671 | break; |
| 1672 | case 'r': |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1673 | dpkg_opt |= dpkg_opt_remove; |
| 1674 | dpkg_opt |= dpkg_opt_package_name; |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1675 | break; |
| 1676 | case 'u': /* Equivalent to --unpack in official dpkg */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1677 | dpkg_opt |= dpkg_opt_unpack; |
| 1678 | dpkg_opt |= dpkg_opt_filename; |
Glenn L McGrath | 0e757a2 | 2001-04-08 05:27:18 +0000 | [diff] [blame] | 1679 | break; |
| 1680 | default: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1681 | bb_show_usage(); |
Glenn L McGrath | 0e757a2 | 2001-04-08 05:27:18 +0000 | [diff] [blame] | 1682 | } |
Glenn L McGrath | c900575 | 2001-02-10 02:05:24 +0000 | [diff] [blame] | 1683 | } |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1684 | /* check for non-otion argument if expected */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1685 | if ((dpkg_opt == 0) || ((argc == optind) && !(dpkg_opt && dpkg_opt_list_installed))) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1686 | bb_show_usage(); |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1687 | } |
Glenn L McGrath | 0e757a2 | 2001-04-08 05:27:18 +0000 | [diff] [blame] | 1688 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1689 | /* puts("(Reading database ... xxxxx files and directories installed.)"); */ |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1690 | index_status_file("/var/lib/dpkg/status"); |
| 1691 | |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1692 | /* if the list action was given print the installed packages and exit */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1693 | if (dpkg_opt & dpkg_opt_list_installed) { |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1694 | list_packages(); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1695 | return(EXIT_SUCCESS); |
Glenn L McGrath | e738661 | 2001-09-21 04:30:51 +0000 | [diff] [blame] | 1696 | } |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1697 | |
Glenn L McGrath | 0d2fb76 | 2001-10-25 14:26:05 +0000 | [diff] [blame] | 1698 | /* Read arguments and store relevant info in structs */ |
| 1699 | while (optind < argc) { |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1700 | /* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */ |
| 1701 | deb_file = xrealloc(deb_file, sizeof(deb_file_t *) * (deb_count + 2)); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1702 | deb_file[deb_count] = (deb_file_t *) xmalloc(sizeof(deb_file_t)); |
| 1703 | if (dpkg_opt & dpkg_opt_filename) { |
Glenn L McGrath | 61b7904 | 2002-10-19 10:40:55 +0000 | [diff] [blame] | 1704 | archive_handle_t *archive_handle; |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 1705 | llist_t *control_list = NULL; |
Glenn L McGrath | d8d1191 | 2002-11-05 13:56:04 +0000 | [diff] [blame] | 1706 | |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1707 | /* Extract the control file */ |
Glenn L McGrath | 66125c8 | 2002-12-08 00:54:33 +0000 | [diff] [blame] | 1708 | control_list = llist_add_to(NULL, "./control"); |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1709 | archive_handle = init_archive_deb_ar(argv[optind]); |
| 1710 | init_archive_deb_control(archive_handle); |
| 1711 | deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1712 | if (deb_file[deb_count]->control_file == NULL) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1713 | bb_error_msg_and_die("Couldnt extract control file"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1714 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1715 | deb_file[deb_count]->filename = bb_xstrdup(argv[optind]); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1716 | package_num = fill_package_struct(deb_file[deb_count]->control_file); |
Glenn L McGrath | 0d2fb76 | 2001-10-25 14:26:05 +0000 | [diff] [blame] | 1717 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1718 | if (package_num == -1) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1719 | bb_error_msg("Invalid control file in %s", argv[optind]); |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 1720 | optind++; |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1721 | continue; |
| 1722 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1723 | deb_file[deb_count]->package = (unsigned int) package_num; |
Glenn L McGrath | 747381c | 2002-11-06 22:54:41 +0000 | [diff] [blame] | 1724 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1725 | /* Add the package to the status hashtable */ |
| 1726 | if ((dpkg_opt & dpkg_opt_unpack) || (dpkg_opt & dpkg_opt_install)) { |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1727 | /* Try and find a currently installed version of this package */ |
| 1728 | status_num = search_status_hashtable(name_hashtable[package_hashtable[deb_file[deb_count]->package]->name]); |
| 1729 | /* If no previous entry was found initialise a new entry */ |
| 1730 | if ((status_hashtable[status_num] == NULL) || |
| 1731 | (status_hashtable[status_num]->status == 0)) { |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1732 | status_node = (status_node_t *) xmalloc(sizeof(status_node_t)); |
| 1733 | status_node->package = deb_file[deb_count]->package; |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1734 | /* reinstreq isnt changed to "ok" until the package control info |
| 1735 | * is written to the status file*/ |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1736 | status_node->status = search_name_hashtable("install reinstreq not-installed"); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1737 | status_hashtable[status_num] = status_node; |
| 1738 | } else { |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1739 | set_status(status_num, "install", 1); |
| 1740 | set_status(status_num, "reinstreq", 2); |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1741 | } |
| 1742 | } |
| 1743 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1744 | else if (dpkg_opt & dpkg_opt_package_name) { |
| 1745 | deb_file[deb_count]->filename = NULL; |
| 1746 | deb_file[deb_count]->control_file = NULL; |
| 1747 | deb_file[deb_count]->package = search_package_hashtable( |
| 1748 | search_name_hashtable(argv[optind]), |
| 1749 | search_name_hashtable("ANY"), VER_ANY); |
| 1750 | if (package_hashtable[deb_file[deb_count]->package] == NULL) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1751 | bb_error_msg_and_die("Package %s is uninstalled or unknown\n", argv[optind]); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1752 | } |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1753 | package_num = deb_file[deb_count]->package; |
| 1754 | status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]); |
| 1755 | state_status = get_status(status_num, 3); |
Glenn L McGrath | 0d2fb76 | 2001-10-25 14:26:05 +0000 | [diff] [blame] | 1756 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1757 | /* check package status is "installed" */ |
| 1758 | if (dpkg_opt & dpkg_opt_remove) { |
| 1759 | if ((strcmp(name_hashtable[state_status], "not-installed") == 0) || |
| 1760 | (strcmp(name_hashtable[state_status], "config-files") == 0)) { |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1761 | bb_error_msg_and_die("%s is already removed.", name_hashtable[package_hashtable[package_num]->name]); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1762 | } |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1763 | set_status(status_num, "deinstall", 1); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1764 | } |
| 1765 | else if (dpkg_opt & dpkg_opt_purge) { |
| 1766 | /* if package status is "conf-files" then its ok */ |
| 1767 | if (strcmp(name_hashtable[state_status], "not-installed") == 0) { |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1768 | bb_error_msg_and_die("%s is already purged.", name_hashtable[package_hashtable[package_num]->name]); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1769 | } |
Glenn L McGrath | b8c3a54 | 2003-11-28 22:38:14 +0000 | [diff] [blame] | 1770 | set_status(status_num, "purge", 1); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1771 | } |
| 1772 | } |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1773 | deb_count++; |
Glenn L McGrath | 0e757a2 | 2001-04-08 05:27:18 +0000 | [diff] [blame] | 1774 | optind++; |
| 1775 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1776 | deb_file[deb_count] = NULL; |
Glenn L McGrath | 0e757a2 | 2001-04-08 05:27:18 +0000 | [diff] [blame] | 1777 | |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1778 | /* Check that the deb file arguments are installable */ |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1779 | if ((dpkg_opt & dpkg_opt_force_ignore_depends) != dpkg_opt_force_ignore_depends) { |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1780 | if (!check_deps(deb_file, 0, deb_count)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1781 | bb_error_msg_and_die("Dependency check failed"); |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1782 | } |
Glenn L McGrath | 0d2fb76 | 2001-10-25 14:26:05 +0000 | [diff] [blame] | 1783 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1784 | |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1785 | /* TODO: install or remove packages in the correct dependency order */ |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1786 | for (i = 0; i < deb_count; i++) { |
| 1787 | /* Remove or purge packages */ |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1788 | if (dpkg_opt & dpkg_opt_remove) { |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1789 | remove_package(deb_file[i]->package, 1); |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1790 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1791 | else if (dpkg_opt & dpkg_opt_purge) { |
| 1792 | purge_package(deb_file[i]->package); |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1793 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1794 | else if (dpkg_opt & dpkg_opt_unpack) { |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1795 | unpack_package(deb_file[i]); |
| 1796 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1797 | else if (dpkg_opt & dpkg_opt_install) { |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1798 | unpack_package(deb_file[i]); |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1799 | /* package is configured in second pass below */ |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1800 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1801 | else if (dpkg_opt & dpkg_opt_configure) { |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1802 | configure_package(deb_file[i]); |
| 1803 | } |
| 1804 | } |
Glenn L McGrath | fea4b44 | 2003-11-26 21:53:37 +0000 | [diff] [blame] | 1805 | /* configure installed packages */ |
| 1806 | if (dpkg_opt & dpkg_opt_install) { |
| 1807 | for (i = 0; i < deb_count; i++) |
| 1808 | configure_package(deb_file[i]); |
| 1809 | } |
Glenn L McGrath | c3fbec7 | 2001-07-18 15:47:21 +0000 | [diff] [blame] | 1810 | |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1811 | write_status_file(deb_file); |
| 1812 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1813 | for (i = 0; i < deb_count; i++) { |
| 1814 | free(deb_file[i]->control_file); |
| 1815 | free(deb_file[i]->filename); |
| 1816 | free(deb_file[i]); |
Glenn L McGrath | c900575 | 2001-02-10 02:05:24 +0000 | [diff] [blame] | 1817 | } |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1818 | |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1819 | free(deb_file); |
| 1820 | |
| 1821 | for (i = 0; i < NAME_HASH_PRIME; i++) { |
Aaron Lehmann | a170e1c | 2002-11-28 11:27:31 +0000 | [diff] [blame] | 1822 | free(name_hashtable[i]); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | for (i = 0; i < PACKAGE_HASH_PRIME; i++) { |
Glenn L McGrath | a94a06a | 2002-05-29 13:45:34 +0000 | [diff] [blame] | 1826 | if (package_hashtable[i] != NULL) { |
| 1827 | free_package(package_hashtable[i]); |
| 1828 | } |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | for (i = 0; i < STATUS_HASH_PRIME; i++) { |
Aaron Lehmann | a170e1c | 2002-11-28 11:27:31 +0000 | [diff] [blame] | 1832 | free(status_hashtable[i]); |
Glenn L McGrath | ef0eab5 | 2001-10-25 14:49:48 +0000 | [diff] [blame] | 1833 | } |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1834 | |
Glenn L McGrath | 95bfe63 | 2001-09-29 03:34:38 +0000 | [diff] [blame] | 1835 | return(EXIT_SUCCESS); |
Eric Andersen | 67991cf | 2001-02-14 21:23:06 +0000 | [diff] [blame] | 1836 | } |
Glenn L McGrath | ccd65c9 | 2001-07-13 18:35:24 +0000 | [diff] [blame] | 1837 | |