From: ellson Date: Thu, 28 Jul 2005 00:03:06 +0000 (+0000) Subject: Use the path to libgvc.so from /proc/self/maps to determine path for config. X-Git-Tag: LAST_LIBGRAPH~32^2~7372 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d8b352e55570a0508ee93f81ea26082d5f56e46;p=graphviz Use the path to libgvc.so from /proc/self/maps to determine path for config. So long as dot can find libgvc.so, e.g. using LD_LIBRARY_PATH, then it can be binary-relocated. --- diff --git a/lib/gvc/gvconfig.c b/lib/gvc/gvconfig.c index 445a93739..7e09deb72 100644 --- a/lib/gvc/gvconfig.c +++ b/lib/gvc/gvconfig.c @@ -49,10 +49,6 @@ VTX_CodeGen, GD_CodeGen, memGD_CodeGen; #endif -#ifndef DISABLE_LTDL -static char *libdir = GVLIBDIR; -#endif - /* A config for gvrender is a text file containing a list of plugin librariess and their capabilities using a tcl-like @@ -221,6 +217,40 @@ static void gvconfig_write_library_config(char *path, gvplugin_library_t *librar fputs ("}\n", f); } +char * gvconfig_libdir(void) +{ + static char line[1024]; + static char *libdir; + char *path, *tmp; + FILE *f; + + if (!libdir) { + + /* this only works on linux, other systems will get GVLIBDIR only */ + libdir = GVLIBDIR; + f = fopen ("/proc/self/maps", "r"); + if (f) { + while (!feof (f)) { + if (!fgets (line, sizeof (line), f)) + continue; + if (!strstr (line, " r-xp ")) + continue; + path = strchr (line, '/'); + if (!path) + continue; + tmp = strstr (path, "/libgvc."); + if (tmp) { + *tmp = 0; + libdir = path; + break; + } + } + fclose (f); + } + } + return libdir; +} + #ifdef DISABLE_LTDL extern gvplugin_library_t *builtins[]; #endif @@ -230,7 +260,7 @@ static void config_rescan(GVC_t *gvc, char *config_path) { FILE *f = NULL; glob_t globbuf; - char *config_glob, *path; + char *config_glob, *path, *libdir; int i, rc; gvplugin_library_t *library; char *plugin_glob = "libgvplugin*.so.?"; @@ -242,6 +272,8 @@ static void config_rescan(GVC_t *gvc, char *config_path) } } + libdir = gvconfig_libdir(); + /* load all libraries even if can't save config */ config_glob = malloc(strlen(libdir) + 1 @@ -406,7 +438,7 @@ void gvconfig(GVC_t * gvc, boolean rescan) struct stat config_st, libdir_st; FILE *f = NULL; char *config_path = NULL, *config_text = NULL; - + char *libdir; char *config_file_name = "config"; #define MAX_SZ_CONFIG 100000 @@ -426,15 +458,15 @@ void gvconfig(GVC_t * gvc, boolean rescan) } #else /* see if there are any new plugins */ - + libdir = gvconfig_libdir(); rc = stat(libdir, &libdir_st); if (rc == -1) { /* if we fail to stat it then it probably doesn't exist so just fail silently */ return; } - config_path = malloc(strlen(GVLIBDIR) + 1 + strlen(config_file_name) + 1); - strcpy(config_path, GVLIBDIR); + config_path = malloc(strlen(libdir) + 1 + strlen(config_file_name) + 1); + strcpy(config_path, libdir); strcat(config_path, "/"); strcat(config_path, config_file_name); diff --git a/lib/gvc/gvcproc.h b/lib/gvc/gvcproc.h index 5a71be60d..1a8605bf0 100644 --- a/lib/gvc/gvcproc.h +++ b/lib/gvc/gvcproc.h @@ -31,6 +31,7 @@ extern "C" { /* configuration */ + extern char *gvconfig_libdir(void); extern void gvconfig(GVC_t * gvc, boolean rescan); extern char *gvhostname(void); diff --git a/lib/gvc/gvplugin.c b/lib/gvc/gvplugin.c index 754b156c4..ee3f5970a 100644 --- a/lib/gvc/gvplugin.c +++ b/lib/gvc/gvplugin.c @@ -33,10 +33,6 @@ #include "gvcint.h" #include "gvcproc.h" -#ifndef DISABLE_LTDL -static char *libdir = GVLIBDIR; -#endif - /* * Define an apis array of name strings using an enumerated api_t as index. * The enumerated type is defined gvplugin.h. The apis array is @@ -111,9 +107,10 @@ gvplugin_library_t *gvplugin_library_load(char *path) int len; static char *p; static int lenp; - + char *libdir; char *suffix = "_LTX_library"; + libdir = gvconfig_libdir(); len = strlen(libdir) + 1 + strlen(path) + 1; if (len > lenp) { lenp = len+20;