diff options
Diffstat (limited to 'dpkg.c')
-rw-r--r-- | dpkg.c | 305 |
1 files changed, 132 insertions, 173 deletions
@@ -112,23 +112,19 @@ static char **depends_split(const char *dependsstr) | |||
112 | 112 | ||
113 | dependsvec[0] = 0; | 113 | dependsvec[0] = 0; |
114 | 114 | ||
115 | if (dependsstr != 0) | 115 | if (dependsstr != 0) { |
116 | { | ||
117 | p = strdup(dependsstr); | 116 | p = strdup(dependsstr); |
118 | while (*p != 0 && *p != '\n') | 117 | while (*p != 0 && *p != '\n') { |
119 | { | 118 | if (*p != ' ') { |
120 | if (*p != ' ') | 119 | if (*p == ',') { |
121 | { | ||
122 | if (*p == ',') | ||
123 | { | ||
124 | *p = 0; | 120 | *p = 0; |
125 | dependsvec[++i] = 0; | 121 | dependsvec[++i] = 0; |
126 | } | 122 | } else |
127 | else if (dependsvec[i] == 0) | 123 | if (dependsvec[i] == 0) |
128 | dependsvec[i] = p; | 124 | dependsvec[i] = p; |
129 | } | 125 | } else { |
130 | else | ||
131 | *p = 0; /* eat the space... */ | 126 | *p = 0; /* eat the space... */ |
127 | } | ||
132 | p++; | 128 | p++; |
133 | } | 129 | } |
134 | *p = 0; | 130 | *p = 0; |
@@ -213,12 +209,10 @@ static package_t *depends_resolve(package_t *pkgs, void *status) | |||
213 | int i; | 209 | int i; |
214 | void *found; | 210 | void *found; |
215 | 211 | ||
216 | for (pkg = pkgs; pkg != 0; pkg = pkg->next) | 212 | for (pkg = pkgs; pkg != 0; pkg = pkg->next) { |
217 | { | ||
218 | dependsvec = depends_split(pkg->depends); | 213 | dependsvec = depends_split(pkg->depends); |
219 | i = 0; | 214 | i = 0; |
220 | while (dependsvec[i] != 0) | 215 | while (dependsvec[i] != 0) { |
221 | { | ||
222 | /* Check for dependencies; first look for installed packages */ | 216 | /* Check for dependencies; first look for installed packages */ |
223 | dependpkg.package = dependsvec[i]; | 217 | dependpkg.package = dependsvec[i]; |
224 | if ((found = tfind(&dependpkg, &status, package_compare)) == 0 || | 218 | if ((found = tfind(&dependpkg, &status, package_compare)) == 0 || |
@@ -228,25 +222,22 @@ static package_t *depends_resolve(package_t *pkgs, void *status) | |||
228 | { | 222 | { |
229 | /* if it fails, we look through the list of packages we are going to | 223 | /* if it fails, we look through the list of packages we are going to |
230 | * install */ | 224 | * install */ |
231 | for (chk = pkgs; chk != 0; chk = chk->next) | 225 | for (chk = pkgs; chk != 0; chk = chk->next) { |
232 | { | ||
233 | if (strcmp(chk->package, dependsvec[i]) == 0 || | 226 | if (strcmp(chk->package, dependsvec[i]) == 0 || |
234 | (chk->provides && | 227 | (chk->provides && |
235 | strncmp(chk->provides, dependsvec[i], strlen(dependsvec[i])) == 0)) | 228 | strncmp(chk->provides, dependsvec[i], strlen(dependsvec[i])) == 0)) { |
236 | { | 229 | if (chk->requiredcount >= DEPENDSMAX) { |
237 | if (chk->requiredcount >= DEPENDSMAX) | ||
238 | { | ||
239 | fprintf(stderr, "Too many dependencies for %s\n", | 230 | fprintf(stderr, "Too many dependencies for %s\n", |
240 | chk->package); | 231 | chk->package); |
241 | return 0; | 232 | return 0; |
242 | } | 233 | } |
243 | if (chk != pkg) | 234 | if (chk != pkg) { |
244 | chk->requiredfor[chk->requiredcount++] = pkg; | 235 | chk->requiredfor[chk->requiredcount++] = pkg; |
236 | } | ||
245 | break; | 237 | break; |
246 | } | 238 | } |
247 | } | 239 | } |
248 | if (chk == 0) | 240 | if (chk == 0) { |
249 | { | ||
250 | fprintf(stderr, "%s depends on %s, but it is not going to be installed\n", pkg->package, dependsvec[i]); | 241 | fprintf(stderr, "%s depends on %s, but it is not going to be installed\n", pkg->package, dependsvec[i]); |
251 | return 0; | 242 | return 0; |
252 | } | 243 | } |
@@ -284,16 +275,17 @@ static unsigned long status_parse(const char *line) | |||
284 | p = strchr(line, ' '); | 275 | p = strchr(line, ' '); |
285 | if (p) *p = 0; | 276 | if (p) *p = 0; |
286 | j = 1; | 277 | j = 1; |
287 | while (statuswords[i][j] != 0) | 278 | while (statuswords[i][j] != 0) { |
288 | { | 279 | if (strcmp(line, statuswords[i][j]) == 0) { |
289 | if (strcmp(line, statuswords[i][j]) == 0) | ||
290 | { | ||
291 | l |= (1 << ((int)statuswords[i][0] + j - 1)); | 280 | l |= (1 << ((int)statuswords[i][0] + j - 1)); |
292 | break; | 281 | break; |
293 | } | 282 | } |
294 | j++; | 283 | j++; |
295 | } | 284 | } |
296 | if (statuswords[i][j] == 0) return 0; /* parse error */ | 285 | /* parse error */ |
286 | if (statuswords[i][j] == 0) { | ||
287 | return 0; | ||
288 | } | ||
297 | line = p+1; | 289 | line = p+1; |
298 | } | 290 | } |
299 | return l; | 291 | return l; |
@@ -306,21 +298,17 @@ static const char *status_print(unsigned long flags) | |||
306 | int i, j; | 298 | int i, j; |
307 | 299 | ||
308 | buf[0] = 0; | 300 | buf[0] = 0; |
309 | for (i = 0; i < 3; i++) | 301 | for (i = 0; i < 3; i++) { |
310 | { | ||
311 | j = 1; | 302 | j = 1; |
312 | while (statuswords[i][j] != 0) | 303 | while (statuswords[i][j] != 0) { |
313 | { | 304 | if ((flags & (1 << ((int)statuswords[i][0] + j - 1))) != 0) { |
314 | if ((flags & (1 << ((int)statuswords[i][0] + j - 1))) != 0) | ||
315 | { | ||
316 | strcat(buf, statuswords[i][j]); | 305 | strcat(buf, statuswords[i][j]); |
317 | if (i < 2) strcat(buf, " "); | 306 | if (i < 2) strcat(buf, " "); |
318 | break; | 307 | break; |
319 | } | 308 | } |
320 | j++; | 309 | j++; |
321 | } | 310 | } |
322 | if (statuswords[i][j] == 0) | 311 | if (statuswords[i][j] == 0) { |
323 | { | ||
324 | fprintf(stderr, "corrupted status flag!!\n"); | 312 | fprintf(stderr, "corrupted status flag!!\n"); |
325 | return NULL; | 313 | return NULL; |
326 | } | 314 | } |
@@ -332,41 +320,37 @@ static const char *status_print(unsigned long flags) | |||
332 | * Read a control file (or a stanza of a status file) and parse it, | 320 | * Read a control file (or a stanza of a status file) and parse it, |
333 | * filling parsed fields into the package structure | 321 | * filling parsed fields into the package structure |
334 | */ | 322 | */ |
335 | static void control_read(FILE *f, package_t *p) | 323 | static void control_read(FILE *file, package_t *p) |
336 | { | 324 | { |
337 | char buf[BUFSIZE]; | 325 | char *line; |
338 | while (fgets(buf, BUFSIZE, f) && !feof(f)) | 326 | |
339 | { | 327 | while ((line = get_line_from_file(file)) != NULL) { |
340 | buf[strlen(buf)-1] = 0; | 328 | line[strlen(line)] = 0; |
341 | if (*buf == 0) | 329 | if (strlen(line) == 0) { |
342 | return; | 330 | break; |
343 | else if (strstr(buf, "Package: ") == buf) | 331 | } else |
344 | { | 332 | if (strstr(line, "Package: ") == line) { |
345 | p->package = strdup(buf+9); | 333 | p->package = strdup(line + 9); |
346 | } | 334 | } else |
347 | else if (strstr(buf, "Status: ") == buf) | 335 | if (strstr(line, "Status: ") == line) { |
348 | { | 336 | p->status = status_parse(line + 8); |
349 | p->status = status_parse(buf+8); | 337 | } else |
350 | } | 338 | if (strstr(line, "Depends: ") == line) { |
351 | else if (strstr(buf, "Depends: ") == buf) | 339 | p->depends = strdup(line + 9); |
352 | { | 340 | } else |
353 | p->depends = strdup(buf+9); | 341 | if (strstr(line, "Provides: ") == line) { |
354 | } | 342 | p->provides = strdup(line + 10); |
355 | else if (strstr(buf, "Provides: ") == buf) | 343 | } else |
356 | { | 344 | if (strstr(line, "Description: ") == line) { |
357 | p->provides = strdup(buf+10); | 345 | p->description = strdup(line + 13); |
358 | } | ||
359 | /* This is specific to the Debian Installer. Ifdef? */ | 346 | /* This is specific to the Debian Installer. Ifdef? */ |
360 | else if (strstr(buf, "installer-menu-item: ") == buf) | 347 | } else |
361 | { | 348 | if (strstr(line, "installer-menu-item: ") == line) { |
362 | p->installer_menu_item = atoi(buf+21); | 349 | p->installer_menu_item = atoi(line + 21); |
363 | } | ||
364 | else if (strstr(buf, "Description: ") == buf) | ||
365 | { | ||
366 | p->description = strdup(buf+13); | ||
367 | } | 350 | } |
368 | /* TODO: localized descriptions */ | 351 | /* TODO: localized descriptions */ |
369 | } | 352 | } |
353 | free(line); | ||
370 | } | 354 | } |
371 | 355 | ||
372 | static void *status_read(void) | 356 | static void *status_read(void) |
@@ -375,20 +359,18 @@ static void *status_read(void) | |||
375 | void *status = 0; | 359 | void *status = 0; |
376 | package_t *m = 0, *p = 0, *t = 0; | 360 | package_t *m = 0, *p = 0, *t = 0; |
377 | 361 | ||
378 | if ((f = fopen(STATUSFILE, "r")) == NULL) | 362 | if ((f = fopen(STATUSFILE, "r")) == NULL) { |
379 | { | ||
380 | perror(STATUSFILE); | 363 | perror(STATUSFILE); |
381 | return 0; | 364 | return 0; |
382 | } | 365 | } |
383 | if (getenv(udpkg_quiet) == NULL) | 366 | if (getenv(udpkg_quiet) == NULL) { |
384 | printf("(Reading database...)\n"); | 367 | printf("(Reading database...)\n"); |
385 | while (!feof(f)) | 368 | } |
386 | { | 369 | while (!feof(f)) { |
387 | m = (package_t *)malloc(sizeof(package_t)); | 370 | m = (package_t *)xmalloc(sizeof(package_t)); |
388 | memset(m, 0, sizeof(package_t)); | 371 | memset(m, 0, sizeof(package_t)); |
389 | control_read(f, m); | 372 | control_read(f, m); |
390 | if (m->package) | 373 | if (m->package) { |
391 | { | ||
392 | /* | 374 | /* |
393 | * If there is an item in the tree by this name, | 375 | * If there is an item in the tree by this name, |
394 | * it must be a virtual package; insert real | 376 | * it must be a virtual package; insert real |
@@ -396,20 +378,18 @@ static void *status_read(void) | |||
396 | */ | 378 | */ |
397 | tdelete(m, &status, package_compare); | 379 | tdelete(m, &status, package_compare); |
398 | tsearch(m, &status, package_compare); | 380 | tsearch(m, &status, package_compare); |
399 | if (m->provides) | 381 | if (m->provides) { |
400 | { | ||
401 | /* | 382 | /* |
402 | * A "Provides" triggers the insertion | 383 | * A "Provides" triggers the insertion |
403 | * of a pseudo package into the status | 384 | * of a pseudo package into the status |
404 | * binary-tree. | 385 | * binary-tree. |
405 | */ | 386 | */ |
406 | p = (package_t *)malloc(sizeof(package_t)); | 387 | p = (package_t *)xmalloc(sizeof(package_t)); |
407 | memset(p, 0, sizeof(package_t)); | 388 | memset(p, 0, sizeof(package_t)); |
408 | p->package = strdup(m->provides); | 389 | p->package = strdup(m->provides); |
409 | 390 | ||
410 | t = *(package_t **)tsearch(p, &status, package_compare); | 391 | t = *(package_t **)tsearch(p, &status, package_compare); |
411 | if (!(t == p)) | 392 | if (!(t == p)) { |
412 | { | ||
413 | free(p->package); | 393 | free(p->package); |
414 | free(p); | 394 | free(p); |
415 | } | 395 | } |
@@ -426,8 +406,7 @@ static void *status_read(void) | |||
426 | } | 406 | } |
427 | } | 407 | } |
428 | } | 408 | } |
429 | else | 409 | else { |
430 | { | ||
431 | free(m); | 410 | free(m); |
432 | } | 411 | } |
433 | } | 412 | } |
@@ -438,26 +417,24 @@ static void *status_read(void) | |||
438 | static int status_merge(void *status, package_t *pkgs) | 417 | static int status_merge(void *status, package_t *pkgs) |
439 | { | 418 | { |
440 | FILE *fin, *fout; | 419 | FILE *fin, *fout; |
441 | char buf[BUFSIZE]; | 420 | char *line; |
442 | package_t *pkg = 0, *statpkg = 0; | 421 | package_t *pkg = 0, *statpkg = 0; |
443 | package_t locpkg; | 422 | package_t locpkg; |
444 | int r = 0; | 423 | int r = 0; |
445 | 424 | ||
446 | if ((fin = fopen(STATUSFILE, "r")) == NULL) | 425 | if ((fin = fopen(STATUSFILE, "r")) == NULL) { |
447 | { | ||
448 | perror(STATUSFILE); | 426 | perror(STATUSFILE); |
449 | return 0; | 427 | return 0; |
450 | } | 428 | } |
451 | if ((fout = fopen(STATUSFILE ".new", "w")) == NULL) | 429 | if ((fout = fopen(STATUSFILE ".new", "w")) == NULL) { |
452 | { | ||
453 | perror(STATUSFILE ".new"); | 430 | perror(STATUSFILE ".new"); |
454 | return 0; | 431 | return 0; |
455 | } | 432 | } |
456 | if (getenv(udpkg_quiet) == NULL) | 433 | if (getenv(udpkg_quiet) == NULL) { |
457 | printf("(Updating database...)\n"); | 434 | printf("(Updating database...)\n"); |
458 | while (fgets(buf, BUFSIZE, fin) && !feof(fin)) | 435 | } |
459 | { | 436 | while (((line = get_line_from_file(fin)) != NULL) && (feof(fin) != 0)) { |
460 | buf[strlen(buf)-1] = 0; /* trim newline */ | 437 | line[strlen(line)] = 0; /* trim newline */ |
461 | /* If we see a package header, find out if it's a package | 438 | /* If we see a package header, find out if it's a package |
462 | * that we have processed. if so, we skip that block for | 439 | * that we have processed. if so, we skip that block for |
463 | * now (write it at the end). | 440 | * now (write it at the end). |
@@ -465,31 +442,33 @@ static int status_merge(void *status, package_t *pkgs) | |||
465 | * we also look at packages in the status cache and update | 442 | * we also look at packages in the status cache and update |
466 | * their status fields | 443 | * their status fields |
467 | */ | 444 | */ |
468 | if (strstr(buf, "Package: ") == buf) | 445 | if (strstr(line, "Package: ") == line) { |
469 | { | 446 | for (pkg = pkgs; pkg != 0 && strncmp(line + 9, |
470 | for (pkg = pkgs; pkg != 0 && strncmp(buf + 9, | 447 | pkg->package, strlen(line) - 9) != 0; |
471 | pkg->package, strlen(buf) - 9)!=0; | ||
472 | pkg = pkg->next) ; | 448 | pkg = pkg->next) ; |
473 | 449 | ||
474 | locpkg.package = buf+9; | 450 | locpkg.package = line + 9; |
475 | statpkg = tfind(&locpkg, &status, package_compare); | 451 | statpkg = tfind(&locpkg, &status, package_compare); |
476 | 452 | ||
477 | /* note: statpkg should be non-zero, unless the status | 453 | /* note: statpkg should be non-zero, unless the status |
478 | * file was changed while we are processing (no locking | 454 | * file was changed while we are processing (no locking |
479 | * is currently done... | 455 | * is currently done... |
480 | */ | 456 | */ |
481 | if (statpkg != 0) statpkg = *(package_t **)statpkg; | 457 | if (statpkg != 0) { |
458 | statpkg = *(package_t **)statpkg; | ||
459 | } | ||
482 | } | 460 | } |
483 | if (pkg != 0) continue; | 461 | if (pkg != 0) { |
484 | 462 | continue; | |
485 | if (strstr(buf, "Status: ") == buf && statpkg != 0) | ||
486 | { | ||
487 | snprintf(buf, sizeof(buf), "Status: %s", | ||
488 | status_print(statpkg->status)); | ||
489 | } | 463 | } |
490 | fputs(buf, fout); | 464 | if (strstr(line, "Status: ") == line && statpkg != 0) { |
465 | snprintf(line, sizeof(line), "Status: %s", | ||
466 | status_print(statpkg->status)); | ||
467 | } | ||
468 | fputs(line, fout); | ||
491 | fputc('\n', fout); | 469 | fputc('\n', fout); |
492 | } | 470 | } |
471 | free(line); | ||
493 | 472 | ||
494 | // Print out packages we processed. | 473 | // Print out packages we processed. |
495 | for (pkg = pkgs; pkg != 0; pkg = pkg->next) { | 474 | for (pkg = pkgs; pkg != 0; pkg = pkg->next) { |
@@ -510,7 +489,9 @@ static int status_merge(void *status, package_t *pkgs) | |||
510 | fclose(fout); | 489 | fclose(fout); |
511 | 490 | ||
512 | r = rename(STATUSFILE, STATUSFILE ".bak"); | 491 | r = rename(STATUSFILE, STATUSFILE ".bak"); |
513 | if (r == 0) r = rename(STATUSFILE ".new", STATUSFILE); | 492 | if (r == 0) { |
493 | r = rename(STATUSFILE ".new", STATUSFILE); | ||
494 | } | ||
514 | return 0; | 495 | return 0; |
515 | } | 496 | } |
516 | 497 | ||
@@ -532,7 +513,9 @@ static int is_file(const char *fn) | |||
532 | { | 513 | { |
533 | struct stat statbuf; | 514 | struct stat statbuf; |
534 | 515 | ||
535 | if (stat(fn, &statbuf) < 0) return 0; | 516 | if (stat(fn, &statbuf) < 0) { |
517 | return 0; | ||
518 | } | ||
536 | return S_ISREG(statbuf.st_mode); | 519 | return S_ISREG(statbuf.st_mode); |
537 | } | 520 | } |
538 | 521 | ||
@@ -544,11 +527,9 @@ static int dpkg_doconfigure(package_t *pkg) | |||
544 | DPRINTF("Configuring %s\n", pkg->package); | 527 | DPRINTF("Configuring %s\n", pkg->package); |
545 | pkg->status &= status_statusmask; | 528 | pkg->status &= status_statusmask; |
546 | snprintf(postinst, sizeof(postinst), "%s%s.postinst", infodir, pkg->package); | 529 | snprintf(postinst, sizeof(postinst), "%s%s.postinst", infodir, pkg->package); |
547 | if (is_file(postinst)) | 530 | if (is_file(postinst)) { |
548 | { | ||
549 | snprintf(buf, sizeof(buf), "%s configure", postinst); | 531 | snprintf(buf, sizeof(buf), "%s configure", postinst); |
550 | if ((r = do_system(buf)) != 0) | 532 | if ((r = do_system(buf)) != 0) { |
551 | { | ||
552 | fprintf(stderr, "postinst exited with status %d\n", r); | 533 | fprintf(stderr, "postinst exited with status %d\n", r); |
553 | pkg->status |= status_statushalfconfigured; | 534 | pkg->status |= status_statushalfconfigured; |
554 | return 1; | 535 | return 1; |
@@ -576,25 +557,19 @@ static int dpkg_dounpack(package_t *pkg) | |||
576 | cwd = getcwd(0, 0); | 557 | cwd = getcwd(0, 0); |
577 | chdir("/"); | 558 | chdir("/"); |
578 | snprintf(buf, sizeof(buf), "ar -p %s data.tar.gz|zcat|tar -xf -", pkg->file); | 559 | snprintf(buf, sizeof(buf), "ar -p %s data.tar.gz|zcat|tar -xf -", pkg->file); |
579 | if (SYSTEM(buf) == 0) | 560 | if (SYSTEM(buf) == 0) { |
580 | { | ||
581 | /* Installs the package scripts into the info directory */ | 561 | /* Installs the package scripts into the info directory */ |
582 | for (i = 0; i < sizeof(adminscripts) / sizeof(adminscripts[0]); | 562 | for (i = 0; i < sizeof(adminscripts) / sizeof(adminscripts[0]); i++) { |
583 | i++) | ||
584 | { | ||
585 | snprintf(buf, sizeof(buf), "%s%s/%s", | 563 | snprintf(buf, sizeof(buf), "%s%s/%s", |
586 | DPKGCIDIR, pkg->package, adminscripts[i]); | 564 | DPKGCIDIR, pkg->package, adminscripts[i]); |
587 | snprintf(buf2, sizeof(buf), "%s%s.%s", | 565 | snprintf(buf2, sizeof(buf), "%s%s.%s", |
588 | infodir, pkg->package, adminscripts[i]); | 566 | infodir, pkg->package, adminscripts[i]); |
589 | if (copy_file(buf, buf2, TRUE, FALSE, FALSE) < 0) | 567 | if (copy_file(buf, buf2, TRUE, FALSE, FALSE) < 0) { |
590 | { | ||
591 | fprintf(stderr, "Cannot copy %s to %s: %s\n", | 568 | fprintf(stderr, "Cannot copy %s to %s: %s\n", |
592 | buf, buf2, strerror(errno)); | 569 | buf, buf2, strerror(errno)); |
593 | r = 1; | 570 | r = 1; |
594 | break; | 571 | break; |
595 | } | 572 | } else { |
596 | else | ||
597 | { | ||
598 | /* ugly hack to create the list file; should | 573 | /* ugly hack to create the list file; should |
599 | * probably do something more elegant | 574 | * probably do something more elegant |
600 | * | 575 | * |
@@ -607,26 +582,22 @@ static int dpkg_dounpack(package_t *pkg) | |||
607 | snprintf(buf2, sizeof(buf2), | 582 | snprintf(buf2, sizeof(buf2), |
608 | "%s%s.list", infodir, pkg->package); | 583 | "%s%s.list", infodir, pkg->package); |
609 | if ((infp = popen(buf, "r")) == NULL || | 584 | if ((infp = popen(buf, "r")) == NULL || |
610 | (outfp = fopen(buf2, "w")) == NULL) | 585 | (outfp = fopen(buf2, "w")) == NULL) { |
611 | { | ||
612 | fprintf(stderr, "Cannot create %s\n", | 586 | fprintf(stderr, "Cannot create %s\n", |
613 | buf2); | 587 | buf2); |
614 | r = 1; | 588 | r = 1; |
615 | break; | 589 | break; |
616 | } | 590 | } |
617 | while (fgets(buf, sizeof(buf), infp) && | 591 | while (fgets(buf, sizeof(buf), infp) && |
618 | !feof(infp)) | 592 | !feof(infp)) { |
619 | { | ||
620 | p = buf; | 593 | p = buf; |
621 | if (*p == '.') p++; | 594 | if (*p == '.') p++; |
622 | if (*p == '/' && *(p+1) == '\n') | 595 | if (*p == '/' && *(p+1) == '\n') { |
623 | { | ||
624 | *(p+1) = '.'; | 596 | *(p+1) = '.'; |
625 | *(p+2) = '\n'; | 597 | *(p+2) = '\n'; |
626 | *(p+3) = 0; | 598 | *(p+3) = 0; |
627 | } | 599 | } |
628 | if (p[strlen(p)-2] == '/') | 600 | if (p[strlen(p)-2] == '/') { |
629 | { | ||
630 | p[strlen(p)-2] = '\n'; | 601 | p[strlen(p)-2] = '\n'; |
631 | p[strlen(p)-1] = 0; | 602 | p[strlen(p)-1] = 0; |
632 | } | 603 | } |
@@ -673,12 +644,10 @@ static int dpkg_unpackcontrol(package_t *pkg) | |||
673 | cwd = getcwd(0, 0); | 644 | cwd = getcwd(0, 0); |
674 | snprintf(buf, sizeof(buf), "%s%s", DPKGCIDIR, pkg->package); | 645 | snprintf(buf, sizeof(buf), "%s%s", DPKGCIDIR, pkg->package); |
675 | DPRINTF("dir = %s\n", buf); | 646 | DPRINTF("dir = %s\n", buf); |
676 | if (mkdir(buf, S_IRWXU) == 0 && chdir(buf) == 0) | 647 | if (mkdir(buf, S_IRWXU) == 0 && chdir(buf) == 0) { |
677 | { | ||
678 | snprintf(buf, sizeof(buf), "ar -p %s control.tar.gz|zcat|tar -xf -", | 648 | snprintf(buf, sizeof(buf), "ar -p %s control.tar.gz|zcat|tar -xf -", |
679 | pkg->file); | 649 | pkg->file); |
680 | if (SYSTEM(buf) == 0) | 650 | if (SYSTEM(buf) == 0) { |
681 | { | ||
682 | if ((f = fopen("control", "r")) != NULL) { | 651 | if ((f = fopen("control", "r")) != NULL) { |
683 | control_read(f, pkg); | 652 | control_read(f, pkg); |
684 | r = 0; | 653 | r = 0; |
@@ -698,14 +667,12 @@ static int dpkg_unpack(package_t *pkgs) | |||
698 | void *status = status_read(); | 667 | void *status = status_read(); |
699 | 668 | ||
700 | if (SYSTEM("rm -rf -- " DPKGCIDIR) != 0 || | 669 | if (SYSTEM("rm -rf -- " DPKGCIDIR) != 0 || |
701 | mkdir(DPKGCIDIR, S_IRWXU) != 0) | 670 | mkdir(DPKGCIDIR, S_IRWXU) != 0) { |
702 | { | ||
703 | perror("mkdir"); | 671 | perror("mkdir"); |
704 | return 1; | 672 | return 1; |
705 | } | 673 | } |
706 | 674 | ||
707 | for (pkg = pkgs; pkg != 0; pkg = pkg->next) | 675 | for (pkg = pkgs; pkg != 0; pkg = pkg->next) { |
708 | { | ||
709 | dpkg_unpackcontrol(pkg); | 676 | dpkg_unpackcontrol(pkg); |
710 | r = dpkg_dounpack(pkg); | 677 | r = dpkg_dounpack(pkg); |
711 | if (r != 0) break; | 678 | if (r != 0) break; |
@@ -721,16 +688,12 @@ static int dpkg_configure(package_t *pkgs) | |||
721 | void *found; | 688 | void *found; |
722 | package_t *pkg; | 689 | package_t *pkg; |
723 | void *status = status_read(); | 690 | void *status = status_read(); |
724 | for (pkg = pkgs; pkg != 0 && r == 0; pkg = pkg->next) | 691 | for (pkg = pkgs; pkg != 0 && r == 0; pkg = pkg->next) { |
725 | { | ||
726 | found = tfind(pkg, &status, package_compare); | 692 | found = tfind(pkg, &status, package_compare); |
727 | if (found == 0) | 693 | if (found == 0) { |
728 | { | ||
729 | fprintf(stderr, "Trying to configure %s, but it is not installed\n", pkg->package); | 694 | fprintf(stderr, "Trying to configure %s, but it is not installed\n", pkg->package); |
730 | r = 1; | 695 | r = 1; |
731 | } | 696 | } else { |
732 | else | ||
733 | { | ||
734 | /* configure the package listed in the status file; | 697 | /* configure the package listed in the status file; |
735 | * not pkg, as we have info only for the latter */ | 698 | * not pkg, as we have info only for the latter */ |
736 | r = dpkg_doconfigure(*(package_t **)found); | 699 | r = dpkg_doconfigure(*(package_t **)found); |
@@ -745,16 +708,14 @@ static int dpkg_install(package_t *pkgs) | |||
745 | package_t *p, *ordered = 0; | 708 | package_t *p, *ordered = 0; |
746 | void *status = status_read(); | 709 | void *status = status_read(); |
747 | if (SYSTEM("rm -rf -- " DPKGCIDIR) != 0 || | 710 | if (SYSTEM("rm -rf -- " DPKGCIDIR) != 0 || |
748 | mkdir(DPKGCIDIR, S_IRWXU) != 0) | 711 | mkdir(DPKGCIDIR, S_IRWXU) != 0) { |
749 | { | ||
750 | perror("mkdir"); | 712 | perror("mkdir"); |
751 | return 1; | 713 | return 1; |
752 | } | 714 | } |
753 | 715 | ||
754 | /* Stage 1: parse all the control information */ | 716 | /* Stage 1: parse all the control information */ |
755 | for (p = pkgs; p != 0; p = p->next) | 717 | for (p = pkgs; p != 0; p = p->next) |
756 | if (dpkg_unpackcontrol(p) != 0) | 718 | if (dpkg_unpackcontrol(p) != 0) { |
757 | { | ||
758 | perror(p->file); | 719 | perror(p->file); |
759 | /* force loop break, and prevents further ops */ | 720 | /* force loop break, and prevents further ops */ |
760 | pkgs = 0; | 721 | pkgs = 0; |
@@ -768,8 +729,7 @@ static int dpkg_install(package_t *pkgs) | |||
768 | #endif | 729 | #endif |
769 | 730 | ||
770 | /* Stage 3: install */ | 731 | /* Stage 3: install */ |
771 | for (p = ordered; p != 0; p = p->next) | 732 | for (p = ordered; p != 0; p = p->next) { |
772 | { | ||
773 | p->status &= status_wantmask; | 733 | p->status &= status_wantmask; |
774 | p->status |= status_wantinstall; | 734 | p->status |= status_wantinstall; |
775 | 735 | ||
@@ -779,14 +739,14 @@ static int dpkg_install(package_t *pkgs) | |||
779 | p->status &= status_flagmask; | 739 | p->status &= status_flagmask; |
780 | p->status |= status_flagok; | 740 | p->status |= status_flagok; |
781 | 741 | ||
782 | if (dpkg_doinstall(p) != 0) | 742 | if (dpkg_doinstall(p) != 0) { |
783 | { | ||
784 | perror(p->file); | 743 | perror(p->file); |
785 | } | 744 | } |
786 | } | 745 | } |
787 | 746 | ||
788 | if (ordered != 0) | 747 | if (ordered != 0) { |
789 | status_merge(status, pkgs); | 748 | status_merge(status, pkgs); |
749 | } | ||
790 | SYSTEM("rm -rf -- " DPKGCIDIR); | 750 | SYSTEM("rm -rf -- " DPKGCIDIR); |
791 | return 0; | 751 | return 0; |
792 | } | 752 | } |
@@ -808,27 +768,23 @@ extern int dpkg_main(int argc, char **argv) | |||
808 | char *s; | 768 | char *s; |
809 | package_t *p, *packages = NULL; | 769 | package_t *p, *packages = NULL; |
810 | char *cwd = getcwd(0, 0); | 770 | char *cwd = getcwd(0, 0); |
811 | while (*++argv) | 771 | while (*++argv) { |
812 | { | ||
813 | if (**argv == '-') { | 772 | if (**argv == '-') { |
814 | /* Nasty little hack to "parse" long options. */ | 773 | /* Nasty little hack to "parse" long options. */ |
815 | s = *argv; | 774 | s = *argv; |
816 | while (*s == '-') | 775 | while (*s == '-') |
817 | s++; | 776 | s++; |
818 | opt=s[0]; | 777 | opt=s[0]; |
819 | } | 778 | } else { |
820 | else | 779 | p = (package_t *)xmalloc(sizeof(package_t)); |
821 | { | ||
822 | p = (package_t *)malloc(sizeof(package_t)); | ||
823 | memset(p, 0, sizeof(package_t)); | 780 | memset(p, 0, sizeof(package_t)); |
824 | if (**argv == '/') | 781 | if (**argv == '/') { |
825 | p->file = *argv; | 782 | p->file = *argv; |
826 | else if (opt != 'c') | 783 | } else |
827 | { | 784 | if (opt != 'c') { |
828 | p->file = malloc(strlen(cwd) + strlen(*argv) + 2); | 785 | p->file = xmalloc(strlen(cwd) + strlen(*argv) + 2); |
829 | sprintf(p->file, "%s/%s", cwd, *argv); | 786 | sprintf(p->file, "%s/%s", cwd, *argv); |
830 | } | 787 | } else { |
831 | else { | ||
832 | p->package = strdup(*argv); | 788 | p->package = strdup(*argv); |
833 | } | 789 | } |
834 | p->next = packages; | 790 | p->next = packages; |
@@ -836,12 +792,15 @@ extern int dpkg_main(int argc, char **argv) | |||
836 | } | 792 | } |
837 | 793 | ||
838 | } | 794 | } |
839 | switch (opt) | 795 | switch (opt) { |
840 | { | 796 | case 'i': |
841 | case 'i': return dpkg_install(packages); break; | 797 | return dpkg_install(packages); |
842 | case 'r': return dpkg_remove(packages); break; | 798 | case 'r': |
843 | case 'u': return dpkg_unpack(packages); break; | 799 | return dpkg_remove(packages); |
844 | case 'c': return dpkg_configure(packages); break; | 800 | case 'u': |
801 | return dpkg_unpack(packages); | ||
802 | case 'c': | ||
803 | return dpkg_configure(packages); | ||
845 | } | 804 | } |
846 | 805 | ||
847 | /* if it falls through to here, some of the command line options were | 806 | /* if it falls through to here, some of the command line options were |