ldconfig.c (4eae39bfdf5f9d66699e50c10b996e75a902d344) ldconfig.c (06eda379d4263d63853cad084178254d15664c5f)
1/*
2 * Copyright (c) 1993,1995 Paul Kranenburg
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 60 unchanged lines hidden (view full) ---

69#undef major
70#undef minor
71
72static int verbose;
73static int nostd;
74static int justread;
75static int merge;
76static int rescan;
1/*
2 * Copyright (c) 1993,1995 Paul Kranenburg
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 60 unchanged lines hidden (view full) ---

69#undef major
70#undef minor
71
72static int verbose;
73static int nostd;
74static int justread;
75static int merge;
76static int rescan;
77static char *hints_file;
77static const char *hints_file;
78
79struct shlib_list {
80 /* Internal list of shared libraries found */
81 char *name;
82 char *path;
83 int dewey[MAXDEWEY];
84 int ndewey;
85#define major dewey[0]

--- 8 unchanged lines hidden (view full) ---

94static int dodir(char *, int);
95int dofile(char *, int);
96static void enter(char *, char *, char *, int *, int);
97static void listhints(void);
98static int readhints(void);
99static void usage(void);
100
101int
78
79struct shlib_list {
80 /* Internal list of shared libraries found */
81 char *name;
82 char *path;
83 int dewey[MAXDEWEY];
84 int ndewey;
85#define major dewey[0]

--- 8 unchanged lines hidden (view full) ---

94static int dodir(char *, int);
95int dofile(char *, int);
96static void enter(char *, char *, char *, int *, int);
97static void listhints(void);
98static int readhints(void);
99static void usage(void);
100
101int
102main(argc, argv)
103int argc;
104char *argv[];
102main(int argc, char **argv)
105{
106 int i, c;
107 int rval = 0;
108 int is_aout = 0;
109 int is_32 = 0;
110
111 while (argc > 1) {
112 if (strcmp(argv[1], "-aout") == 0) {

--- 262 unchanged lines hidden (view full) ---

375 shp->ndewey = ndewey;
376 shp->next = NULL;
377
378 *shlib_tail = shp;
379 shlib_tail = &shp->next;
380}
381
382
103{
104 int i, c;
105 int rval = 0;
106 int is_aout = 0;
107 int is_32 = 0;
108
109 while (argc > 1) {
110 if (strcmp(argv[1], "-aout") == 0) {

--- 262 unchanged lines hidden (view full) ---

373 shp->ndewey = ndewey;
374 shp->next = NULL;
375
376 *shlib_tail = shp;
377 shlib_tail = &shp->next;
378}
379
380
383int
384hinthash(cp, vmajor)
385char *cp;
386int vmajor;
381static int
382hinthash(char *cp, int vmajor)
387{
388 int k = 0;
389
390 while (*cp)
391 k = (((k << 1) + (k >> 14)) ^ (*cp++)) & 0x3fff;
392
393 k = (((k << 1) + (k >> 14)) ^ (vmajor*257)) & 0x3fff;
394

--- 6 unchanged lines hidden (view full) ---

401 struct hints_header hdr;
402 struct hints_bucket *blist;
403 struct shlib_list *shp;
404 char *strtab;
405 int i, n, str_index = 0;
406 int strtab_sz = 0; /* Total length of strings */
407 int nhints = 0; /* Total number of hints */
408 int fd;
383{
384 int k = 0;
385
386 while (*cp)
387 k = (((k << 1) + (k >> 14)) ^ (*cp++)) & 0x3fff;
388
389 k = (((k << 1) + (k >> 14)) ^ (vmajor*257)) & 0x3fff;
390

--- 6 unchanged lines hidden (view full) ---

397 struct hints_header hdr;
398 struct hints_bucket *blist;
399 struct shlib_list *shp;
400 char *strtab;
401 int i, n, str_index = 0;
402 int strtab_sz = 0; /* Total length of strings */
403 int nhints = 0; /* Total number of hints */
404 int fd;
409 char *tmpfile;
405 char *_tmpfile;
410
411 for (shp = shlib_head; shp; shp = shp->next) {
412 strtab_sz += 1 + strlen(shp->name);
413 strtab_sz += 1 + strlen(shp->path);
414 nhints++;
415 }
416
417 /* Fill hints file header */

--- 24 unchanged lines hidden (view full) ---

442 /* Enter all */
443 for (shp = shlib_head; shp; shp = shp->next) {
444 struct hints_bucket *bp;
445
446 bp = blist +
447 (hinthash(shp->name, shp->major) % hdr.hh_nbucket);
448
449 if (bp->hi_pathx) {
406
407 for (shp = shlib_head; shp; shp = shp->next) {
408 strtab_sz += 1 + strlen(shp->name);
409 strtab_sz += 1 + strlen(shp->path);
410 nhints++;
411 }
412
413 /* Fill hints file header */

--- 24 unchanged lines hidden (view full) ---

438 /* Enter all */
439 for (shp = shlib_head; shp; shp = shp->next) {
440 struct hints_bucket *bp;
441
442 bp = blist +
443 (hinthash(shp->name, shp->major) % hdr.hh_nbucket);
444
445 if (bp->hi_pathx) {
450 int i;
446 int j;
451
447
452 for (i = 0; i < hdr.hh_nbucket; i++) {
453 if (blist[i].hi_pathx == 0)
448 for (j = 0; j < hdr.hh_nbucket; j++) {
449 if (blist[j].hi_pathx == 0)
454 break;
455 }
450 break;
451 }
456 if (i == hdr.hh_nbucket) {
452 if (j == hdr.hh_nbucket) {
457 warnx("bummer!");
458 return -1;
459 }
460 while (bp->hi_next != -1)
461 bp = &blist[bp->hi_next];
453 warnx("bummer!");
454 return -1;
455 }
456 while (bp->hi_next != -1)
457 bp = &blist[bp->hi_next];
462 bp->hi_next = i;
463 bp = blist + i;
458 bp->hi_next = j;
459 bp = blist + j;
464 }
465
466 /* Insert strings in string table */
467 bp->hi_namex = str_index;
468 strcpy(strtab + str_index, shp->name);
469 str_index += 1 + strlen(shp->name);
470
471 bp->hi_pathx = str_index;

--- 9 unchanged lines hidden (view full) ---

481 strcpy(strtab + str_index, dir_list);
482 str_index += 1 + strlen(dir_list);
483
484 /* Sanity check */
485 if (str_index != strtab_sz) {
486 errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz);
487 }
488
460 }
461
462 /* Insert strings in string table */
463 bp->hi_namex = str_index;
464 strcpy(strtab + str_index, shp->name);
465 str_index += 1 + strlen(shp->name);
466
467 bp->hi_pathx = str_index;

--- 9 unchanged lines hidden (view full) ---

477 strcpy(strtab + str_index, dir_list);
478 str_index += 1 + strlen(dir_list);
479
480 /* Sanity check */
481 if (str_index != strtab_sz) {
482 errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz);
483 }
484
489 tmpfile = concat(hints_file, ".XXXXXXXXXX", "");
485 _tmpfile = concat(hints_file, ".XXXXXXXXXX", "");
490 umask(0); /* Create with exact permissions */
486 umask(0); /* Create with exact permissions */
491 if ((fd = mkstemp(tmpfile)) == -1) {
492 warn("%s", tmpfile);
487 if ((fd = mkstemp(_tmpfile)) == -1) {
488 warn("%s", _tmpfile);
493 return -1;
494 }
495 fchmod(fd, 0444);
496
497 if (write(fd, &hdr, sizeof(struct hints_header)) !=
498 sizeof(struct hints_header)) {
499 warn("%s", hints_file);
500 return -1;
501 }
502 if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) !=
489 return -1;
490 }
491 fchmod(fd, 0444);
492
493 if (write(fd, &hdr, sizeof(struct hints_header)) !=
494 sizeof(struct hints_header)) {
495 warn("%s", hints_file);
496 return -1;
497 }
498 if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) !=
503 hdr.hh_nbucket * sizeof(struct hints_bucket)) {
499 (ssize_t)(hdr.hh_nbucket * sizeof(struct hints_bucket))) {
504 warn("%s", hints_file);
505 return -1;
506 }
507 if (write(fd, strtab, strtab_sz) != strtab_sz) {
508 warn("%s", hints_file);
509 return -1;
510 }
511 if (close(fd) != 0) {
512 warn("%s", hints_file);
513 return -1;
514 }
515
516 /* Install it */
517 if (unlink(hints_file) != 0 && errno != ENOENT) {
518 warn("%s", hints_file);
519 return -1;
520 }
521
500 warn("%s", hints_file);
501 return -1;
502 }
503 if (write(fd, strtab, strtab_sz) != strtab_sz) {
504 warn("%s", hints_file);
505 return -1;
506 }
507 if (close(fd) != 0) {
508 warn("%s", hints_file);
509 return -1;
510 }
511
512 /* Install it */
513 if (unlink(hints_file) != 0 && errno != ENOENT) {
514 warn("%s", hints_file);
515 return -1;
516 }
517
522 if (rename(tmpfile, hints_file) != 0) {
518 if (rename(_tmpfile, hints_file) != 0) {
523 warn("%s", hints_file);
524 return -1;
525 }
526
527 return 0;
528}
529
530static int

--- 42 unchanged lines hidden (view full) ---

573 if (addr == MAP_FAILED) {
574 warn("%s", hints_file);
575 return -1;
576 }
577 hdr = (struct hints_header *)addr;
578 }
579 close(fd);
580
519 warn("%s", hints_file);
520 return -1;
521 }
522
523 return 0;
524}
525
526static int

--- 42 unchanged lines hidden (view full) ---

569 if (addr == MAP_FAILED) {
570 warn("%s", hints_file);
571 return -1;
572 }
573 hdr = (struct hints_header *)addr;
574 }
575 close(fd);
576
581 blist = (struct hints_bucket *)((char *)addr + hdr->hh_hashtab);
582 strtab = (char *)addr + hdr->hh_strtab;
583
584 if (hdr->hh_version >= LD_HINTS_VERSION_2)
585 add_search_path(strtab + hdr->hh_dirlist);
586 else if (rescan)
587 errx(1, "%s too old and does not contain the search path",
588 hints_file);
589
590 if (rescan)
591 return 0;
592
577 strtab = (char *)addr + hdr->hh_strtab;
578
579 if (hdr->hh_version >= LD_HINTS_VERSION_2)
580 add_search_path(strtab + hdr->hh_dirlist);
581 else if (rescan)
582 errx(1, "%s too old and does not contain the search path",
583 hints_file);
584
585 if (rescan)
586 return 0;
587
588 blist = malloc(sizeof(struct hints_bucket) * hdr->hh_nbucket);
589 if (blist == NULL)
590 err(1, "readhints");
591 memcpy(blist, (char *)addr + hdr->hh_hashtab,
592 sizeof(struct hints_bucket) * hdr->hh_nbucket);
593
594
593 for (i = 0; i < hdr->hh_nbucket; i++) {
594 struct hints_bucket *bp = &blist[i];
595
596 /* Sanity check */
597 if (bp->hi_namex >= hdr->hh_strtab_sz) {
598 warnx("bad name index: %#x", bp->hi_namex);
595 for (i = 0; i < hdr->hh_nbucket; i++) {
596 struct hints_bucket *bp = &blist[i];
597
598 /* Sanity check */
599 if (bp->hi_namex >= hdr->hh_strtab_sz) {
600 warnx("bad name index: %#x", bp->hi_namex);
601 free(blist);
599 return -1;
600 }
601 if (bp->hi_pathx >= hdr->hh_strtab_sz) {
602 warnx("bad path index: %#x", bp->hi_pathx);
602 return -1;
603 }
604 if (bp->hi_pathx >= hdr->hh_strtab_sz) {
605 warnx("bad path index: %#x", bp->hi_pathx);
606 free(blist);
603 return -1;
604 }
605
606 /* Allocate new list element */
607 shp = (struct shlib_list *)xmalloc(sizeof *shp);
608 shp->name = strdup(strtab + bp->hi_namex);
609 shp->path = strdup(strtab + bp->hi_pathx);
610 bcopy(bp->hi_dewey, shp->dewey, sizeof(shp->dewey));
611 shp->ndewey = bp->hi_ndewey;
612 shp->next = NULL;
613
614 *shlib_tail = shp;
615 shlib_tail = &shp->next;
616 }
617
607 return -1;
608 }
609
610 /* Allocate new list element */
611 shp = (struct shlib_list *)xmalloc(sizeof *shp);
612 shp->name = strdup(strtab + bp->hi_namex);
613 shp->path = strdup(strtab + bp->hi_pathx);
614 bcopy(bp->hi_dewey, shp->dewey, sizeof(shp->dewey));
615 shp->ndewey = bp->hi_ndewey;
616 shp->next = NULL;
617
618 *shlib_tail = shp;
619 shlib_tail = &shp->next;
620 }
621
622 free(blist);
618 return 0;
619}
620
621static void
622listhints()
623{
624 struct shlib_list *shp;
625 int i;
626
627 printf("%s:\n", hints_file);
628 printf("\tsearch directories: %s\n", dir_list);
629
630 for (i = 0, shp = shlib_head; shp; i++, shp = shp->next)
631 printf("\t%d:-l%s.%d.%d => %s\n",
632 i, shp->name, shp->major, shp->minor, shp->path);
633
634 return;
635}
623 return 0;
624}
625
626static void
627listhints()
628{
629 struct shlib_list *shp;
630 int i;
631
632 printf("%s:\n", hints_file);
633 printf("\tsearch directories: %s\n", dir_list);
634
635 for (i = 0, shp = shlib_head; shp; i++, shp = shp->next)
636 printf("\t%d:-l%s.%d.%d => %s\n",
637 i, shp->name, shp->major, shp->minor, shp->path);
638
639 return;
640}