From 042926de183bdba739821c2cc557b2118b81aee2 Mon Sep 17 00:00:00 2001 From: ellson Date: Tue, 18 Oct 2005 18:27:43 +0000 Subject: [PATCH] be quiet about inability to find config --- lib/gvc/gvcint.h | 3 ++ lib/gvc/gvconfig.c | 74 ++++++++++++++++++++++++--------------------- lib/gvc/gvcontext.c | 2 ++ 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/lib/gvc/gvcint.h b/lib/gvc/gvcint.h index b32689b1a..8f0d2f0dc 100644 --- a/lib/gvc/gvcint.h +++ b/lib/gvc/gvcint.h @@ -250,6 +250,9 @@ extern "C" { char *user; char **info; + char *config_path; + boolean config_found; + /* gvrender_config() */ GVJ_t *jobs; /* linked list of jobs */ GVJ_t *job; /* current job */ diff --git a/lib/gvc/gvconfig.c b/lib/gvc/gvconfig.c index b7d52ea48..33c99e902 100644 --- a/lib/gvc/gvconfig.c +++ b/lib/gvc/gvconfig.c @@ -262,6 +262,9 @@ char * gvconfig_libdir(void) tmp = strstr (path, "/libgvc."); if (tmp) { *tmp = 0; + /* Check for real /lib dir. Don't accept pre-install /.libs */ + if (strcmp(strrchr(path,'/'), "/lib") != 0) + continue; libdir = path; break; } @@ -456,7 +459,7 @@ void gvconfig(GVC_t * gvc, boolean rescan) int sz, rc; struct stat config_st, libdir_st; FILE *f = NULL; - char *config_path = NULL, *config_text = NULL; + char *config_text = NULL; char *libdir; char *config_file_name = "config"; @@ -477,52 +480,55 @@ void gvconfig(GVC_t * gvc, boolean rescan) /* 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 */ + if (rc == -1) { + /* if we fail to stat it then it probably doesn't exist so just fail silently */ return; } - config_path = malloc(strlen(libdir) + 1 + strlen(config_file_name) + 1); - strcpy(config_path, libdir); - strcat(config_path, "/"); - strcat(config_path, config_file_name); + if (! gvc->config_path) { + gvc->config_path = malloc(strlen(libdir) + 1 + strlen(config_file_name) + 1); + strcpy(gvc->config_path, libdir); + strcat(gvc->config_path, "/"); + strcat(gvc->config_path, config_file_name); + } if (rescan) { - config_rescan(gvc, config_path); + config_rescan(gvc, gvc->config_path); + gvc->config_found = TRUE; + return; } - else { - /* load in the cached plugin library data */ - rc = stat(config_path, &config_st); - if (rc == -1) { - agerr(AGERR,"Unable to stat %s.\n", config_path); - } - else if (config_st.st_size > MAX_SZ_CONFIG) { - agerr(AGERR,"%s is bigger than I can handle.\n", config_path); + /* load in the cached plugin library data */ + + rc = stat(gvc->config_path, &config_st); + if (rc == -1) { + /* silently return without setting gvc->config_found = TRUE */ + return; + } + else if (config_st.st_size > MAX_SZ_CONFIG) { + agerr(AGERR,"%s is bigger than I can handle.\n", gvc->config_path); + } + else { + f = fopen(gvc->config_path,"r"); + if (!f) { + agerr (AGERR,"failed to open %s for read.\n", gvc->config_path); } else { - f = fopen(config_path,"r"); - if (!f) { - agerr (AGERR,"failed to open %s for read.\n", config_path); + config_text = malloc(config_st.st_size + 1); + sz = fread(config_text, 1, config_st.st_size, f); + if (sz == 0) { + agerr(AGERR,"%s is zero sized, or other read error.\n", gvc->config_path); + free(config_text); } else { - config_text = malloc(config_st.st_size + 1); - sz = fread(config_text, 1, config_st.st_size, f); - if (sz == 0) { - agerr(AGERR,"%s is zero sized, or other read error.\n", config_path); - free(config_text); - } - else { - config_text[sz] = '\0'; /* make input into a null terminated string */ - rc = gvconfig_plugin_install_from_config(gvc, config_text); - /* NB. config_text not freed because we retain char* into it */ - } + gvc->config_found = TRUE; + config_text[sz] = '\0'; /* make input into a null terminated string */ + rc = gvconfig_plugin_install_from_config(gvc, config_text); + /* NB. config_text not freed because we retain char* into it */ } - if (f) - fclose(f); } + if (f) + fclose(f); } - if (config_path) - free(config_path); #endif } diff --git a/lib/gvc/gvcontext.c b/lib/gvc/gvcontext.c index 53ad3c154..a5d6bb93a 100644 --- a/lib/gvc/gvcontext.c +++ b/lib/gvc/gvcontext.c @@ -63,6 +63,8 @@ int gvFreeContext(GVC_t * gvc) gvdevice_finalize(gvc); emit_jobs_eof(gvc); gvrender_delete_jobs(gvc); + if (gvc->config_path) + free(gvc->config_path); free(gvc); return (graphviz_errors + agerrors()); } -- 2.40.0