Handling search of config file in multiple directories, additional debug messages
[vlp.git] / src / kernel / kernel.cpp
index 1f7d383ebc8f6500ef184fe7943a5d64d4753574..1c0b7921b96806dd5accaecddd8398e0973090b9 100644 (file)
@@ -73,6 +73,8 @@
 #include "MessageDialog.h"
 
 #include "vlp/config.h"
+#include "vlp/QtConfigurationFinder.h"
+#include "vlp/exception/ConfigFileNotFound.h"
 
 #include <sys/prctl.h>
 /* File resides in top directory (where are Makefiles)*/
@@ -126,12 +128,6 @@ QKernel::QKernel(int argc, char **argv)
 {
        setupUi(this);
 
-       QString arg0(argv[0]);
-       arg0 += "/";
-       homeDir = QDir(arg0);
-       homeDir.cdUp();
-
-       
        int i;
        for(i = 0; (i < 5) && (i < argc-1); i++) {
                strcpy(myargs[i], "");
@@ -140,6 +136,9 @@ QKernel::QKernel(int argc, char **argv)
                }
        }
 
+       loglan::vlp::QtConfigurationFinder configFinder;
+       configFinder.initSearchDirs();
+
        QDir q(getRemoteDir());
 
        if (!q.exists()) {
@@ -158,7 +157,7 @@ QKernel::QKernel(int argc, char **argv)
        ActiveConnections = 0;
        strcpy(LockPasswd, "");
 
-       loadConfig(getConfigFilePath());
+       loadConfig(configFinder.findConfig().c_str());
 
        RunNetModule();
 
@@ -215,6 +214,8 @@ void QKernel::loadConfig(const char * fname)
                }
 
                strncpy(progdir, config.getProgramDir(), 256);
+
+               homeDir = QDir(QCoreApplication::applicationDirPath());
        }
 }
 
@@ -249,6 +250,7 @@ void QKernel::on_actionEditor_triggered()
        pid_t pid = fork();
        if (pid == 0) {
                if (execl(program.toStdString().c_str(),
+                       "logedit",
                        getHomeDir(),
                        myargs[0],
                        myargs[1],
@@ -285,6 +287,7 @@ void QKernel::on_actionHelp_triggered()
        pid_t pid = fork();
        if (pid == 0) {
                if (execl(program.toStdString().c_str(),
+                       "loghelp",
                        docDir.toStdString().c_str(),
                        myargs[0],
                        myargs[1],
@@ -319,6 +322,7 @@ void QKernel::RunGraphModule(char *sk)
        pid_t pid = fork();
        if (pid == 0) {
                if (execl(program.toStdString().c_str(),
+                       "loggraph",
                        program.toStdString().c_str(),
                        sk,
                        myargs[0],
@@ -362,7 +366,7 @@ void QKernel::RunNetModule()
        pid_t pid = fork();
        if (pid == 0) {
                if (execl(program.toStdString().c_str(),
-                       program.toStdString().c_str(),
+                       "lognet",
                        getNetModuleSocket(),
                        getConfigFilePath().toStdString().c_str(),
                        myargs[0],
@@ -922,7 +926,7 @@ InterpEntry *QKernel::RunIntModule(char *ss, int r)
        strcpy(newINT->shortname, b);
        strcpy(newINT->fullname, ss);
 
-       sprintf(a, "%s%d", IPATH, newint);
+       sprintf(a, "%s%d", homeDir.absoluteFilePath(IPATH).toStdString().c_str(), newint);
        sprintf(cmd, "%s/modules/logint %s %s",
                getHomeDir(),
                a,
@@ -930,9 +934,11 @@ InterpEntry *QKernel::RunIntModule(char *ss, int r)
        if (r) {
                strcat(cmd, " r");
        }
-       sprintf(b, " %s %s %s %s %s",
-               myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
-       strcat(cmd, b);
+//     sprintf(b, " %s %s %s %s %s",
+//             myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
+//     sprintf(cmd, "%s %s", cmd, b);
+//     strcat(cmd, b);
+       fprintf(stderr, "%s\n", cmd);
        strcat(cmd, " &");
 
        sock = socket(AF_UNIX, SOCK_STREAM, 0);