aboutsummaryrefslogtreecommitdiff
path: root/src/lib/os_installation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/os_installation.c')
-rw-r--r--src/lib/os_installation.c175
1 files changed, 116 insertions, 59 deletions
diff --git a/src/lib/os_installation.c b/src/lib/os_installation.c
index e73ed63e..0e390718 100644
--- a/src/lib/os_installation.c
+++ b/src/lib/os_installation.c
@@ -58,7 +58,7 @@ get_path_from_proc_maps ()
58 while (NULL != fgets (line, sizeof (line), f)) 58 while (NULL != fgets (line, sizeof (line), f))
59 { 59 {
60 if ((1 == 60 if ((1 ==
61 sscanf (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", dir)) && 61 sscanf (line, "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%s", dir)) &&
62 (NULL != (lgu = strstr (dir, "libgnunetgtk.so")))) 62 (NULL != (lgu = strstr (dir, "libgnunetgtk.so"))))
63 { 63 {
64 lgu[0] = '\0'; 64 lgu[0] = '\0';
@@ -94,7 +94,7 @@ get_path_from_proc_exe ()
94 lnk[size] = '\0'; 94 lnk[size] = '\0';
95 while ((lnk[size] != '/') && (size > 0)) 95 while ((lnk[size] != '/') && (size > 0))
96 size--; 96 size--;
97 /* test for being in lib/gnunet/libexec/ */ 97 /* test for being in lib/gnunet/libexec/ or lib/MULTIARCH/gnunet/libexec */
98 if ( (size > strlen ("/gnunet/libexec/")) && 98 if ( (size > strlen ("/gnunet/libexec/")) &&
99 (0 == strcmp ("/gnunet/libexec/", 99 (0 == strcmp ("/gnunet/libexec/",
100 &lnk[size - strlen ("/gnunet/libexec/")])) ) 100 &lnk[size - strlen ("/gnunet/libexec/")])) )
@@ -407,9 +407,9 @@ os_get_gnunet_path ()
407 return ret; 407 return ret;
408 /* other attempts here */ 408 /* other attempts here */
409 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 409 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
410 _ 410 _("Could not determine installation path for %s. Set `%s' environment variable.\n"),
411 ("Could not determine installation path for %s. Set `%s' environment variable.\n"), 411 "gnunet-gtk",
412 "gnunet-gtk", "GNUNET_GTK_PREFIX"); 412 "GNUNET_GTK_PREFIX");
413 return NULL; 413 return NULL;
414} 414}
415 415
@@ -427,17 +427,17 @@ os_get_exec_path ()
427 ret = NULL; 427 ret = NULL;
428#if LINUX 428#if LINUX
429 ret = get_path_from_proc_exe (); 429 ret = get_path_from_proc_exe ();
430 if (ret != NULL) 430 if (NULL != ret)
431 return ret; 431 return ret;
432#endif 432#endif
433#if WINDOWS 433#if WINDOWS
434 ret = get_path_from_module_filename (); 434 ret = get_path_from_module_filename ();
435 if (ret != NULL) 435 if (NULL != ret)
436 return ret; 436 return ret;
437#endif 437#endif
438#if DARWIN 438#if DARWIN
439 ret = get_path_from_NSGetExecutablePath (); 439 ret = get_path_from_NSGetExecutablePath ();
440 if (ret != NULL) 440 if (NULL != ret)
441 return ret; 441 return ret;
442#endif 442#endif
443 /* other attempts here */ 443 /* other attempts here */
@@ -448,7 +448,7 @@ os_get_exec_path ()
448 448
449/** 449/**
450 * @brief get the path to a specific GNUnet installation directory or, 450 * @brief get the path to a specific GNUnet installation directory or,
451 * with GNUNET_IPK_SELF_PREFIX, the current running apps installation directory 451 * with #GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation directory
452 * @author Milan 452 * @author Milan
453 * @return a pointer to the dir path (to be freed by the caller) 453 * @return a pointer to the dir path (to be freed by the caller)
454 */ 454 */
@@ -459,6 +459,8 @@ GNUNET_GTK_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
459 const char *dirname; 459 const char *dirname;
460 char *execpath = NULL; 460 char *execpath = NULL;
461 char *tmp; 461 char *tmp;
462 char *multiarch;
463 char *libdir;
462 int isbasedir; 464 int isbasedir;
463 465
464 /* if wanted, try to get the current app's bin/ */ 466 /* if wanted, try to get the current app's bin/ */
@@ -467,45 +469,56 @@ GNUNET_GTK_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
467 469
468 /* try to get GNUnet's bin/ or lib/, or if previous was unsuccessful some 470 /* try to get GNUnet's bin/ or lib/, or if previous was unsuccessful some
469 * guess for the current app */ 471 * guess for the current app */
470 if (execpath == NULL) 472 if (NULL == execpath)
471 execpath = os_get_gnunet_path (); 473 execpath = os_get_gnunet_path ();
472 474
473 if (NULL == execpath) 475 if (NULL == execpath)
474 return NULL; 476 return NULL;
475 477
476 n = strlen (execpath); 478 n = strlen (execpath);
477 if (n == 0) 479 if (0 == n)
478 { 480 {
479 /* should never happen, but better safe than sorry */ 481 /* should never happen, but better safe than sorry */
480 GNUNET_free (execpath); 482 GNUNET_free (execpath);
481 return NULL; 483 return NULL;
482 } 484 }
483 /* remove filename itself */ 485 /* remove filename itself */
484 while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) 486 while ((n > 1) && (DIR_SEPARATOR == execpath[n - 1]))
485 execpath[--n] = '\0'; 487 execpath[--n] = '\0';
486 488
487 isbasedir = 1; 489 isbasedir = 1;
488 if ((n > 5) && 490 if ((n > 6) &&
489 ((0 == strcasecmp (&execpath[n - 5], "lib32")) || 491 ((0 == strcasecmp (&execpath[n - 6], "/lib32")) ||
490 (0 == strcasecmp (&execpath[n - 5], "lib64")))) 492 (0 == strcasecmp (&execpath[n - 6], "/lib64"))))
491 { 493 {
492 if ( (GNUNET_OS_IPK_LIBDIR != dirkind) && 494 if ( (GNUNET_OS_IPK_LIBDIR != dirkind) &&
493 (GNUNET_OS_IPK_LIBEXECDIR != dirkind) ) 495 (GNUNET_OS_IPK_LIBEXECDIR != dirkind) )
494 { 496 {
495 /* strip '/lib32' or '/lib64' */ 497 /* strip '/lib32' or '/lib64' */
496 execpath[n - 5] = '\0'; 498 execpath[n - 6] = '\0';
497 n -= 5; 499 n -= 6;
498 } 500 }
499 else 501 else
500 isbasedir = 0; 502 isbasedir = 0;
501 } 503 }
502 else if ((n > 3) && 504 else if ((n > 4) &&
503 ((0 == strcasecmp (&execpath[n - 3], "bin")) || 505 ((0 == strcasecmp (&execpath[n - 4], "/bin")) ||
504 (0 == strcasecmp (&execpath[n - 3], "lib")))) 506 (0 == strcasecmp (&execpath[n - 4], "/lib"))))
505 { 507 {
506 /* strip '/bin' or '/lib' */ 508 /* strip '/bin' or '/lib' */
507 execpath[n - 3] = '\0'; 509 execpath[n - 4] = '\0';
508 n -= 3; 510 n -= 4;
511 }
512 multiarch = NULL;
513 if (NULL != (libdir = strstr (execpath, "/lib/")))
514 {
515 /* test for multi-arch path of the form "PREFIX/lib/MULTIARCH/";
516 here we need to re-add 'multiarch' to lib and libexec paths later! */
517 multiarch = &libdir[5];
518 if (NULL == strchr (multiarch, '/'))
519 libdir[0] = '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */
520 else
521 multiarch = NULL; /* maybe not, multiarch still has a '/', which is not OK */
509 } 522 }
510 /* in case this was a directory named foo-bin, remove "foo-" */ 523 /* in case this was a directory named foo-bin, remove "foo-" */
511 while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) 524 while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR))
@@ -523,84 +536,128 @@ GNUNET_GTK_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
523 if (isbasedir) 536 if (isbasedir)
524 { 537 {
525 dirname = 538 dirname =
526 DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR; 539 DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR;
527 tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); 540 GNUNET_asprintf (&tmp,
528 sprintf (tmp, "%s%s", execpath, dirname); 541 "%s%s%s%s",
529 if ( (GNUNET_YES != 542 execpath,
530 GNUNET_DISK_directory_test (tmp, GNUNET_YES)) && 543 DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR,
531 (4 == sizeof (void *)) ) 544 (NULL != multiarch) ? multiarch : ""
545 dirname);
546 if (GNUNET_YES ==
547 GNUNET_DISK_directory_test (tmp, GNUNET_YES))
548 {
549 GNUNET_free (execpath);
550 return tmp;
551 }
552 GNUNET_free (tmp);
553 NULL == tmp;
554 if (4 == sizeof (void *))
532 { 555 {
533 GNUNET_free (tmp);
534 dirname = 556 dirname =
535 DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR; 557 DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR;
536 tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); 558 GNUNET_asprintf (&tmp,
537 sprintf (tmp, "%s%s", execpath, dirname); 559 "%s%s",
560 execpath,
561 dirname);
538 } 562 }
539 if ( (GNUNET_YES != 563 if (8 == sizeof (void *))
540 GNUNET_DISK_directory_test (tmp, GNUNET_YES)) &&
541 (8 == sizeof (void *)) )
542 { 564 {
543 dirname = 565 dirname =
544 DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR; 566 DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR;
567 GNUNET_asprintf (&tmp,
568 "%s%s",
569 execpath,
570 dirname);
571 }
572 if ( (NULL != tmp) &&
573 (GNUNET_YES ==
574 GNUNET_DISK_directory_test (tmp, GNUNET_YES)) )
575 {
576 GNUNET_free (execpath);
577 return tmp;
545 } 578 }
546 GNUNET_free (tmp); 579 GNUNET_free (tmp);
547 } 580 }
548 else 581 dirname = DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR;
549 dirname = DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR;
550 break; 582 break;
551 case GNUNET_OS_IPK_DATADIR: 583 case GNUNET_OS_IPK_DATADIR:
552 dirname = 584 dirname =
553 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet-gtk" 585 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR;
554 DIR_SEPARATOR_STR; 586 break;
587 case GNUNET_OS_IPK_LOCALEDIR:
588 dirname =
589 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" DIR_SEPARATOR_STR;
555 break; 590 break;
556 case GNUNET_OS_IPK_ICONDIR: 591 case GNUNET_OS_IPK_ICONDIR:
557 dirname = 592 dirname =
558 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR; 593 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR;
559 break; 594 break;
560 case GNUNET_OS_IPK_LOCALEDIR: 595 case GNUNET_OS_IPK_DOCDIR:
561 dirname = 596 dirname =
562 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" DIR_SEPARATOR_STR; 597 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "doc" DIR_SEPARATOR_STR \
598 "gnunet" DIR_SEPARATOR_STR;
563 break; 599 break;
564 case GNUNET_OS_IPK_LIBEXECDIR: 600 case GNUNET_OS_IPK_LIBEXECDIR:
565 if (isbasedir) 601 if (isbasedir)
566 { 602 {
567 dirname = 603 dirname =
568 DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR \ 604 DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR;
569 "libexec" DIR_SEPARATOR_STR; 605 GNUNET_asprintf (&tmp,
570 tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); 606 "%s%s%s%s",
571 sprintf (tmp, "%s%s", execpath, dirname); 607 execpath,
572 if ( (GNUNET_YES != 608 DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR,
573 GNUNET_DISK_directory_test (tmp, GNUNET_YES)) && 609 (NULL != multiarch) ? multiarch : "",
574 (4 == sizeof (void *)) ) 610 dirname);
611 if (GNUNET_YES ==
612 GNUNET_DISK_directory_test (tmp, GNUNET_YES))
613 {
614 GNUNET_free (execpath);
615 return tmp;
616 }
617 GNUNET_free (tmp);
618 tmp = NULL;
619 if (4 == sizeof (void *))
575 { 620 {
576 GNUNET_free (tmp);
577 dirname = 621 dirname =
578 DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR \ 622 DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR \
579 "libexec" DIR_SEPARATOR_STR; 623 "libexec" DIR_SEPARATOR_STR;
580 tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); 624 GNUNET_asprintf (&tmp,
581 sprintf (tmp, "%s%s", execpath, dirname); 625 "%s%s",
626 execpath,
627 dirname);
582 } 628 }
583 if ( (GNUNET_YES != 629 if (8 == sizeof (void *))
584 GNUNET_DISK_directory_test (tmp, GNUNET_YES)) &&
585 (8 == sizeof (void *)) )
586 { 630 {
587 dirname = 631 dirname =
588 DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR \ 632 DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR \
589 "libexec" DIR_SEPARATOR_STR; 633 "libexec" DIR_SEPARATOR_STR;
634 GNUNET_asprintf (&tmp,
635 "%s%s",
636 execpath,
637 dirname);
638 }
639 if ( (NULL != tmp) &&
640 (GNUNET_YES ==
641 GNUNET_DISK_directory_test (tmp, GNUNET_YES)) )
642 {
643 GNUNET_free (execpath);
644 return tmp;
590 } 645 }
646
591 GNUNET_free (tmp); 647 GNUNET_free (tmp);
592 } 648 }
593 else 649 dirname =
594 dirname = 650 DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR \
595 DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR \ 651 "libexec" DIR_SEPARATOR_STR;
596 "libexec" DIR_SEPARATOR_STR;
597 break; 652 break;
598 default: 653 default:
599 GNUNET_free (execpath); 654 GNUNET_free (execpath);
600 return NULL; 655 return NULL;
601 } 656 }
602 tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); 657 GNUNET_asprintf (&tmp,
603 sprintf (tmp, "%s%s", execpath, dirname); 658 "%s%s",
659 execpath,
660 dirname);
604 GNUNET_free (execpath); 661 GNUNET_free (execpath);
605 return tmp; 662 return tmp;
606} 663}