diff --git a/Makefile.am b/Makefile.am
--- a/Makefile.am
+++ b/Makefile.am
@@ -16,16 +16,13 @@ endif
pkglib_LTLIBRARIES = libdistrencommon.la
# libdistrencommon.la:
-libdistrencommon_la_SOURCES = src/common/options.c \
- src/common/options.h \
+libdistrencommon_la_SOURCES = src/common/asprintf.c src/common/asprintf.h \
+ src/common/execio.c src/common/execio.h \
+ src/common/misc.c src/common/misc.h \
+ src/common/options.c src/common/options.h \
src/common/protocol.h \
- src/common/execio.h \
- src/common/execio.c \
src/common/remoteio.h \
- src/common/libremoteio.h \
- src/common/remoteio.c \
- src/common/asprintf.h \
- src/common/asprintf.c
+ src/common/remoteio.c src/common/libremoteio.h
#see http://sources.redhat.com/autobook/autobook/autobook_91.html
# either increase the revision number or the interface number each release!
libdistrencommon_la_LDFLAGS = $(AM_LDFLAGS) -version-info 0:0:0
diff --git a/src/common/options.c b/src/common/options.c
--- a/src/common/options.c
+++ b/src/common/options.c
@@ -17,13 +17,12 @@
along with DistRen. If not, see .
*/
-/* The purpose of this file is to... */
-
#include "options.h"
-/* privat-ish files for components we need to config */
-#include "libremoteio.h"
-#include "protocol.h" /*< for DISTREN_SERVERTYPE_* */
+#include "common/asprintf.h"
+#include "common/misc.h"
+#include "common/libremoteio.h"
+#include "common/protocol.h"
#include
#include
@@ -51,6 +50,9 @@ int options_init(int argc, char *argv[],
char *optstring = "hc:";
char curopt;
+ char *workingdir;
+ char *tmp;
+
configfileprefix = NULL;
while((curopt = getopt(argc, argv, optstring)) != (char)-1)
switch(curopt)
@@ -90,31 +92,37 @@ int options_init(int argc, char *argv[],
strdup is because someday configfile will be customizable via argv[]
*/
if(!configfileprefix)
- configfileprefix = strdup(SYSCONFDIR "/distren");
+ configfileprefix = strdup(SYSCONFDIR);
if(!configfileprefix)
{
fprintf(stderr, "OOM\n");
return 1;
}
-
- i = strlen(configfileprefix) + strlen(myname) + strlen(".conf") + 1;
- configfile = malloc(i);
+
+ workingdir = distren_getcwd();
+ if(!workingdir)
+ fprintf(stderr, "Error finding working directory, I will not be able to return to it after reading the configuration files\n");
+ if(chdir(configfileprefix))
+ fprintf(stderr, "Unable to chdir(\"%s\") where I expected to find config files, expect failure\n", configfileprefix);
+
+ _distren_asprintf(&configfile, "%s%s.conf", PACKAGE, myname);
if(!configfile)
{
- perror("malloc");
+ perror("blah");
+ free(workingdir);
return 1;
}
- strncpy(configfile, configfileprefix, strlen(configfileprefix) + 1);
- strcat(configfile, myname);
- strcat(configfile, ".conf");
- fprintf(stderr, "using configuration file: %s\n", configfile);
+ tmp = distren_getcwd();
+ fprintf(stderr, "using configuration file: ``%s'' (CWD=``%s'')\n", configfile, tmp ? tmp : "");
+ free(tmp);
/* initialize structs */
*allopts = malloc(sizeof(struct options_common));
if(!*allopts)
{
perror("malloc");
+ free(workingdir);
free(configfile);
return 1;
}
@@ -124,6 +132,7 @@ int options_init(int argc, char *argv[],
if(!(*allopts)->data)
{
perror("malloc");
+ free(workingdir);
free(configfile);
free(*allopts);
return 1;
@@ -134,6 +143,7 @@ int options_init(int argc, char *argv[],
if(!(*allopts)->data)
{
perror("malloc");
+ free(workingdir);
free(configfile);
free((*allopts)->data);
free(*allopts);
@@ -208,6 +218,9 @@ int options_init(int argc, char *argv[],
*mycfg = cfg_getsec((*allopts)->data->cfg, myname);
+ if(chdir(workingdir))
+ fprintf(stderr, "Unable to return to ``%s'', my old working directory. If you passed relative pathnames on the commandline, those pathnames will likely be disrespected\n", workingdir);
+ free(workingdir);
/*
* libdistrencommon's config options: