diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-01-30 14:47:20 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-01-30 14:47:20 +0000 |
commit | f57cbab24fb7a22fc982eb8b6c4a2d18402be460 (patch) | |
tree | aa04434af42c35c434a233e31a91da5800eeb098 /src/util/os_installation.c | |
parent | e4e2c54e62f4eeba2aa2db33bd9cf75e45d99c0c (diff) | |
download | gnunet-f57cbab24fb7a22fc982eb8b6c4a2d18402be460.tar.gz gnunet-f57cbab24fb7a22fc982eb8b6c4a2d18402be460.zip |
fix #3284: support lib/MULTIARCH/ paths in installation, use GNUNET_PREFIX=@libdir@ so that we can extract the value of MULTIARCH during 'make check'
Diffstat (limited to 'src/util/os_installation.c')
-rw-r--r-- | src/util/os_installation.c | 123 |
1 files changed, 88 insertions, 35 deletions
diff --git a/src/util/os_installation.c b/src/util/os_installation.c index 30e729dc6..02d23688c 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2006 Christian Grothoff (and other contributing authors) | 3 | (C) 2006-2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -65,7 +65,7 @@ get_path_from_proc_maps () | |||
65 | while (NULL != fgets (line, sizeof (line), f)) | 65 | while (NULL != fgets (line, sizeof (line), f)) |
66 | { | 66 | { |
67 | if ((1 == | 67 | if ((1 == |
68 | SSCANF (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%1023s", dir)) && | 68 | SSCANF (line, "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%1023s", dir)) && |
69 | (NULL != (lgu = strstr (dir, "libgnunetutil")))) | 69 | (NULL != (lgu = strstr (dir, "libgnunetutil")))) |
70 | { | 70 | { |
71 | lgu[0] = '\0'; | 71 | lgu[0] = '\0'; |
@@ -101,7 +101,7 @@ get_path_from_proc_exe () | |||
101 | lnk[size] = '\0'; | 101 | lnk[size] = '\0'; |
102 | while ((lnk[size] != '/') && (size > 0)) | 102 | while ((lnk[size] != '/') && (size > 0)) |
103 | size--; | 103 | size--; |
104 | /* test for being in lib/gnunet/libexec/ */ | 104 | /* test for being in lib/gnunet/libexec/ or lib/MULTIARCH/gnunet/libexec */ |
105 | if ( (size > strlen ("/gnunet/libexec/")) && | 105 | if ( (size > strlen ("/gnunet/libexec/")) && |
106 | (0 == strcmp ("/gnunet/libexec/", | 106 | (0 == strcmp ("/gnunet/libexec/", |
107 | &lnk[size - strlen ("/gnunet/libexec/")])) ) | 107 | &lnk[size - strlen ("/gnunet/libexec/")])) ) |
@@ -465,6 +465,8 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
465 | const char *dirname; | 465 | const char *dirname; |
466 | char *execpath = NULL; | 466 | char *execpath = NULL; |
467 | char *tmp; | 467 | char *tmp; |
468 | char *multiarch; | ||
469 | char *libdir; | ||
468 | int isbasedir; | 470 | int isbasedir; |
469 | 471 | ||
470 | /* if wanted, try to get the current app's bin/ */ | 472 | /* if wanted, try to get the current app's bin/ */ |
@@ -513,6 +515,17 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
513 | execpath[n - 4] = '\0'; | 515 | execpath[n - 4] = '\0'; |
514 | n -= 4; | 516 | n -= 4; |
515 | } | 517 | } |
518 | multiarch = NULL; | ||
519 | if (NULL != (libdir = strstr (execpath, "/lib/"))) | ||
520 | { | ||
521 | /* test for multi-arch path of the form "PREFIX/lib/MULTIARCH/"; | ||
522 | here we need to re-add 'multiarch' to lib and libexec paths later! */ | ||
523 | multiarch = &libdir[5]; | ||
524 | if (NULL == strchr (multiarch, '/')) | ||
525 | libdir[0] = '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */ | ||
526 | else | ||
527 | multiarch = NULL; /* maybe not, multiarch still has a '/', which is not OK */ | ||
528 | } | ||
516 | /* in case this was a directory named foo-bin, remove "foo-" */ | 529 | /* in case this was a directory named foo-bin, remove "foo-" */ |
517 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) | 530 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) |
518 | execpath[--n] = '\0'; | 531 | execpath[--n] = '\0'; |
@@ -530,29 +543,48 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
530 | { | 543 | { |
531 | dirname = | 544 | dirname = |
532 | DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; | 545 | DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; |
533 | tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); | 546 | GNUNET_asprintf (&tmp, |
534 | sprintf (tmp, "%s%s", execpath, dirname); | 547 | "%s%s%s", |
535 | if ( (GNUNET_YES != | 548 | execpath, |
536 | GNUNET_DISK_directory_test (tmp, GNUNET_YES)) && | 549 | dirname, |
537 | (4 == sizeof (void *)) ) | 550 | (NULL != multiarch) ? multiarch : ""); |
551 | if (GNUNET_YES == | ||
552 | GNUNET_DISK_directory_test (tmp, GNUNET_YES)) | ||
553 | { | ||
554 | GNUNET_free (execpath); | ||
555 | return tmp; | ||
556 | } | ||
557 | GNUNET_free (tmp); | ||
558 | tmp = NULL; | ||
559 | if (4 == sizeof (void *)) | ||
538 | { | 560 | { |
539 | GNUNET_free (tmp); | ||
540 | dirname = | 561 | dirname = |
541 | DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; | 562 | DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; |
542 | tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); | 563 | GNUNET_asprintf (&tmp, |
543 | sprintf (tmp, "%s%s", execpath, dirname); | 564 | "%s%s", |
565 | execpath, | ||
566 | dirname); | ||
544 | } | 567 | } |
545 | if ( (GNUNET_YES != | 568 | if (8 == sizeof (void *)) |
546 | GNUNET_DISK_directory_test (tmp, GNUNET_YES)) && | ||
547 | (8 == sizeof (void *)) ) | ||
548 | { | 569 | { |
549 | dirname = | 570 | dirname = |
550 | DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; | 571 | DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; |
572 | GNUNET_asprintf (&tmp, | ||
573 | "%s%s", | ||
574 | execpath, | ||
575 | dirname); | ||
576 | } | ||
577 | |||
578 | if ( (NULL != tmp) && | ||
579 | (GNUNET_YES == | ||
580 | GNUNET_DISK_directory_test (tmp, GNUNET_YES)) ) | ||
581 | { | ||
582 | GNUNET_free (execpath); | ||
583 | return tmp; | ||
551 | } | 584 | } |
552 | GNUNET_free (tmp); | 585 | GNUNET_free (tmp); |
553 | } | 586 | } |
554 | else | 587 | dirname = DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; |
555 | dirname = DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; | ||
556 | break; | 588 | break; |
557 | case GNUNET_OS_IPK_DATADIR: | 589 | case GNUNET_OS_IPK_DATADIR: |
558 | dirname = | 590 | dirname = |
@@ -575,42 +607,63 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
575 | if (isbasedir) | 607 | if (isbasedir) |
576 | { | 608 | { |
577 | dirname = | 609 | dirname = |
578 | DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR \ | 610 | DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR; |
579 | "libexec" DIR_SEPARATOR_STR; | 611 | GNUNET_asprintf (&tmp, |
580 | tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); | 612 | "%s%s%s%s", |
581 | sprintf (tmp, "%s%s", execpath, dirname); | 613 | execpath, |
582 | if ( (GNUNET_YES != | 614 | DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR, |
583 | GNUNET_DISK_directory_test (tmp, GNUNET_YES)) && | 615 | (NULL != multiarch) ? multiarch : "", |
584 | (4 == sizeof (void *)) ) | 616 | dirname); |
617 | if (GNUNET_YES == | ||
618 | GNUNET_DISK_directory_test (tmp, GNUNET_YES)) | ||
619 | { | ||
620 | GNUNET_free (execpath); | ||
621 | return tmp; | ||
622 | } | ||
623 | GNUNET_free (tmp); | ||
624 | tmp = NULL; | ||
625 | if (4 == sizeof (void *)) | ||
585 | { | 626 | { |
586 | GNUNET_free (tmp); | ||
587 | dirname = | 627 | dirname = |
588 | DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR \ | 628 | DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR \ |
589 | "libexec" DIR_SEPARATOR_STR; | 629 | "libexec" DIR_SEPARATOR_STR; |
590 | tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); | 630 | GNUNET_asprintf (&tmp, |
591 | sprintf (tmp, "%s%s", execpath, dirname); | 631 | "%s%s", |
632 | execpath, | ||
633 | dirname); | ||
592 | } | 634 | } |
593 | if ( (GNUNET_YES != | 635 | if (8 == sizeof (void *)) |
594 | GNUNET_DISK_directory_test (tmp, GNUNET_YES)) && | ||
595 | (8 == sizeof (void *)) ) | ||
596 | { | 636 | { |
597 | dirname = | 637 | dirname = |
598 | DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR \ | 638 | DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR \ |
599 | "libexec" DIR_SEPARATOR_STR; | 639 | "libexec" DIR_SEPARATOR_STR; |
640 | GNUNET_asprintf (&tmp, | ||
641 | "%s%s", | ||
642 | execpath, | ||
643 | dirname); | ||
644 | } | ||
645 | if ( (NULL != tmp) && | ||
646 | (GNUNET_YES == | ||
647 | GNUNET_DISK_directory_test (tmp, GNUNET_YES)) ) | ||
648 | { | ||
649 | GNUNET_free (execpath); | ||
650 | return tmp; | ||
600 | } | 651 | } |
652 | |||
601 | GNUNET_free (tmp); | 653 | GNUNET_free (tmp); |
602 | } | 654 | } |
603 | else | 655 | dirname = |
604 | dirname = | 656 | DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR \ |
605 | DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR \ | 657 | "libexec" DIR_SEPARATOR_STR; |
606 | "libexec" DIR_SEPARATOR_STR; | ||
607 | break; | 658 | break; |
608 | default: | 659 | default: |
609 | GNUNET_free (execpath); | 660 | GNUNET_free (execpath); |
610 | return NULL; | 661 | return NULL; |
611 | } | 662 | } |
612 | tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); | 663 | GNUNET_asprintf (&tmp, |
613 | sprintf (tmp, "%s%s", execpath, dirname); | 664 | "%s%s", |
665 | execpath, | ||
666 | dirname); | ||
614 | GNUNET_free (execpath); | 667 | GNUNET_free (execpath); |
615 | return tmp; | 668 | return tmp; |
616 | } | 669 | } |