Previously the PLUGINSDIR was hardcoded to /usr/lib/osdsh which broke terribly for installing into another PREFIX.
Add and document OSDSH_LIB_DIR that takes precedence over the hardwired PLUGINSDIR. Signed-off-by: aldot <rep.dot....@gmail.com> --- debian/osdsh.1 | 5 +++++ src/osdsh/controlsh.c | 33 +++++++++++++++++++++++++++++---- src/osdsh/osdsh.c | 13 ++++--------- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/debian/osdsh.1 b/debian/osdsh.1 index 74b2ade..7cddbd4 100644 --- a/debian/osdsh.1 +++ b/debian/osdsh.1 @@ -72,6 +72,11 @@ align of the osd: left, center or right .B \-n number set the nice number so osdsh won't eat your cpu +.SH ENVIRONMENT VARIABLES +The following environment variables are processed by osdsh: +.IP "OSDSH_LIB_DIR" +The directory that contains plugins like mixer, clock etc. +Default is @PLUGINSDIR@ .SH SEE ALSO .BR osdctl (1), .BR osdshconfig (1). diff --git a/src/osdsh/controlsh.c b/src/osdsh/controlsh.c index de637db..923d582 100644 --- a/src/osdsh/controlsh.c +++ b/src/osdsh/controlsh.c @@ -5,6 +5,17 @@ plugininfo_t plugins[MAX_PLUGINS]; settings_t settings; +/* get plugin directory from environment or fallback to the configured default + */ +static const char* get_osdsh_libdir(void) +{ + const char *lib_dir; + lib_dir = getenv("OSDSH_LIB_DIR"); + if (!lib_dir) + lib_dir = PLUGINSDIR; + return lib_dir; +} + /* ================================== load a plugin ============================= */ int load_plugin( char pluginfile[255]) { @@ -12,16 +23,22 @@ int load_plugin( char pluginfile[255]) void *module; int a; - char file[PATH_MAX+256]; + char *file, *plugin_name; char *msg = NULL; /* getcwd(file, PATH_MAX); strcat(file, "/"); */ - strcat(file, pluginfile); + file = malloc(PATH_MAX + 256); + if (file == NULL) { + fprintf(stderr, "Out of memory\n"); + exit(1); + } + memset(file, 0, PATH_MAX + 256); + snprintf(file, PATH_MAX + 256, "%s/%s", get_osdsh_libdir(), pluginfile); - module = dlopen(pluginfile, RTLD_NOW); + module = dlopen(file, RTLD_NOW); if(!module) { msg = dlerror(); @@ -31,6 +48,13 @@ int load_plugin( char pluginfile[255]) } } else { + a = strlen(file); + plugin_name = malloc(a); + if (plugin_name == NULL) { + fprintf(stderr, "Out of memory\n"); + exit(1); + } + strncpy(plugin_name, file, a); info = dlsym(module, "whoami"); a = info(); @@ -43,10 +67,11 @@ int load_plugin( char pluginfile[255]) plugins[a].module = module; plugins[a].whoami = a; - plugins[a].file = file; + plugins[a].file = plugin_name; plugins[a].myname = (char *) info(); plugins[a].active = 1; } + free(file); return a; } /* =========================== close a plugin ===============================*/ diff --git a/src/osdsh/osdsh.c b/src/osdsh/osdsh.c index 0432177..4774c12 100644 --- a/src/osdsh/osdsh.c +++ b/src/osdsh/osdsh.c @@ -106,31 +106,26 @@ void parse_args(int argc, char *argv[], settings_t * settings) void load_basic_plugins(void) { int a; - char file[PATH_MAX+255]; - sprintf(file, "%s/libosdshmixer.so", PLUGINSDIR); - a = load_plugin(file); + a = load_plugin("libosdshmixer.so"); if (a<0) { xosd_display(settings.myosd, 0, XOSD_string, "No Mixer Support"); xosd_display(settings.myosd, 1, XOSD_string, ""); } - sprintf(file, "%s/libosdshclock.so", PLUGINSDIR); - a = load_plugin(file); + a = load_plugin("libosdshclock.so"); if (a<0) { xosd_display(settings.myosd, 0, XOSD_string, "No Clock Support"); xosd_display(settings.myosd, 1, XOSD_string, ""); } - sprintf(file, "%s/libosdshnet.so", PLUGINSDIR); - a = load_plugin(file); + a = load_plugin("libosdshnet.so"); if (a<0) { xosd_display(settings.myosd, 0, XOSD_string, "No Net Support"); xosd_display(settings.myosd, 1, XOSD_string, ""); } - sprintf(file, "%s/libosdshapm.so", PLUGINSDIR); - a = load_plugin(file); + a = load_plugin("libosdshapm.so"); if (a<0) { xosd_display(settings.myosd, 0, XOSD_string, "No APM/Battery support"); xosd_display(settings.myosd, 1, XOSD_string, ""); -- 1.5.6.5 -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org