#AM_CXXFLAGS = -m32
# @TODO: move --std=c++11 to the autoconf
-AM_CXXFLAGS = -I$(top_srcdir)/src/global -I${QTDIR}/include/qt4 -pedantic -Wall -Wextra -DQT3_SUPPORT --std=c++11
+AM_CPPFLAGS =
+AM_CXXFLAGS = \
+ -I$(top_srcdir)/src/global \
+ -I${QTDIR}/include/qt4 \
+ -pedantic \
+ -Wall \
+ -Wextra \
+ -DQT3_SUPPORT \
+ -DSYSCONFDIR='"$(sysconfdir)"' \
+ --std=c++11
AM_LDFLAGS= -fPIC -L$(QTDIR)/lib -lQtCore -lQtGui -lQt3Support
EXTRA_DIST = \
src/net/lognet.moc.cpp \
src/kernel/kernel.moc.cpp \
src/edit/editor.moc.cpp \
- src/lgconfig/lgconfig.moc.cpp \
- src/preproc/prep.moc.cpp
+ src/lgconfig/lgconfig.moc.cpp
+
# \
# src/help/help.moc
src/kernel/OptionsDialog.cpp \
src/kernel/OptionsDialog.moc.cpp \
src/kernel/MessageDialog.cpp \
- src/global/vlp/config.cpp
+ src/global/vlp/config.cpp \
+ src/global/vlp/ConfigurationFinder.cpp \
+ src/global/vlp/QtConfigurationFinder.cpp
bin_logker_CPPFLAGS = $(bin_logker_CFLAGS)
bin_logker_LDADD = $(bin_logker_LIBS) -lconfig++ -lX11
bin_logkerdir = src/kernel
src/kernel/ui/dialogs/LockDialog.h \
src/kernel/ui/dialogs/OptionsDialog.h \
src/kernel/ui/dialogs/MessageDialog.h \
- src/global/vlp/config.h
+ src/global/vlp/config.h \
+ src/global/vlp/ConfigurationFinder.h \
+ src/global/vlp/QtConfigurationFinder.h \
+ src/global/vlp/exception/ConfigFileNotFound.h
src/kernel/kernel.moc.cpp: \
src/kernel/kernel.h \
src/kernel/ui/KernelWindow.h \
bin_logcomp_SOURCES = \
src/preproc/prep.cpp \
- src/preproc/prep.moc.cpp
+ src/preproc/prep.moc.cpp \
+ src/global/vlp/ConfigurationFinder.cpp \
+ src/global/vlp/QtConfigurationFinder.cpp
bin_logcomp_CPPFLAGS = $(bin_logcomp_CFLAGS)
bin_logcomp_LDADD = $(bin_logcomp_LIBS)
+bin_lgconfigdir = src/preproc
+bin_lgconfig_HEADERS = \
+ src/global/vlp/ConfigurationFinder.h \
+ src/global/vlp/QtConfigurationFinder.h \
+ src/global/vlp/exception/ConfigFileNotFound.h
src/preproc/prep.moc.cpp: src/preproc/prep.cpp
$(MOC) src/preproc/prep.cpp -o src/preproc/prep.moc.cpp
--- /dev/null
+#include <string>
+#include <fstream>
+
+#include <stdio.h>
+
+#include "ConfigurationFinder.h"
+#include "config.h"
+#include "exception/ConfigFileNotFound.h"
+
+namespace loglan {
+namespace vlp {
+
+ConfigurationFinder::ConfigurationFinder()
+{
+}
+
+std::string ConfigurationFinder::findConfig(std::string filename)
+{
+ for (std::string dir : searchDirs) {
+ std::ifstream infile(dir + filename);
+ if (infile.good()) {
+ return dir + filename;
+ }
+ }
+
+ throw exception::ConfigFileNotFound();
+}
+
+/**
+ * Gets path to system-wide settings directory
+ *
+ * @return directory of user settings
+ */
+std::string ConfigurationFinder::getSystemConfigurationDir()
+{
+ std::string dir(SYSCONFDIR);
+
+ dir += VLP_CONFIG_PATH_SEPARATOR;
+ dir += "loglan";
+ dir += VLP_CONFIG_PATH_SEPARATOR;
+
+ return dir;
+}
+
+
+void ConfigurationFinder::addSearchDir(std::string dir)
+{
+ searchDirs.push_back(dir);
+}
+
+void ConfigurationFinder::initSearchDirs()
+{
+ searchDirs.clear();
+
+ addSearchDir("./");
+ addSearchDir(getUserConfigurationDir());
+ addSearchDir(getSystemConfigurationDir());
+}
+
+}
+}
\ No newline at end of file
--- /dev/null
+#ifndef __VLP_CONFIGURATIONFINDER_H
+#define __VLP_CONFIGURATIONFINDER_H
+
+#include <string>
+#include <vector>
+
+#include "config.h"
+
+/**
+ * @file
+ * @brief Configuration file finding utilities
+ * @author Rafał Długołęcki
+ */
+
+namespace loglan {
+namespace vlp {
+
+#if defined(WIN32) || defined(_WIN32)
+# define VLP_CONFIG_PATH_SEPARATOR "\\"
+#else
+# define VLP_CONFIG_PATH_SEPARATOR "/"
+#endif
+
+class ConfigurationFinder {
+private:
+ std::vector<std::string> searchDirs;
+
+ /**
+ * Adds directory to the list of search directories
+ */
+ void addSearchDir(std::string dir);
+public:
+ /**
+ * Default name of configuration file
+ */
+ static const constexpr char * DEFAULT_CONFIG_FILENAME = "vlp.cfg";
+
+ ConfigurationFinder();
+
+ /**
+ * Initializes list of search directories
+ */
+ void initSearchDirs();
+
+ /**
+ * Finds config file in possible config directories
+ *
+ * Search is made in following steps:
+ * 1. Check existence of filename in current execution path dir
+ * 2. If not found, check in user home directory, e.g:
+ * - C:/Documents and Settings/Username
+ * - ~/
+ * 3. If not found, check in system config directory (build dependent),
+ * e.g.:
+ * - /usr/local/etc/loglan/
+ * - /etc/loglan/
+ *
+ * @param filename name of the file to search for
+ * @return path to the filename
+ *
+ */
+ std::string findConfig(std::string filename = DEFAULT_CONFIG_FILENAME);
+
+ /**
+ * Gets path to user local settings directory
+ *
+ * @return directory of user settings
+ */
+ virtual std::string getUserConfigurationDir() = 0;
+
+ /**
+ * Gets path to system-wide settings directory
+ *
+ * @return directory of user settings
+ */
+ std::string getSystemConfigurationDir();
+};
+
+}
+}
+
+
+#endif /* __VLP_CONFIGURATIONFINDER_H */
\ No newline at end of file
--- /dev/null
+#include <QtCore/QString>
+#include <QtCore/QDir>
+#include <string>
+
+#include "QtConfigurationFinder.h"
+
+namespace loglan {
+namespace vlp {
+
+std::string QtConfigurationFinder::getUserConfigurationDir()
+{
+ QString dir = QDir::homePath()
+ + QDir::separator()
+ + ".loglan"
+ + QDir::separator();
+ return dir.toStdString();
+}
+
+}
+}
\ No newline at end of file
--- /dev/null
+#ifndef __VLP_QTCONFIGURATIONFINDER_H
+#define __VLP_QTCONFIGURATIONFINDER_H
+
+#include <string>
+#include "ConfigurationFinder.h"
+
+/**
+ * @file
+ * @brief Qt Configuration file finding utilities
+ * @author Rafał Długołęcki
+ */
+
+namespace loglan {
+namespace vlp {
+
+/**
+ * Qt implementation of ConfigurationFinder
+ */
+class QtConfigurationFinder : public ConfigurationFinder {
+public:
+ virtual std::string getUserConfigurationDir();
+};
+
+}
+}
+
+
+#endif /* __VLP_QTCONFIGURATIONFINDER_H */
\ No newline at end of file
--- /dev/null
+#ifndef __VLP_EXCEPTION_CONFIGFILENOTFOUND_H
+#define __VLP_EXCEPTION_CONFIGFILENOTFOUND_H
+
+#include <stdexcept>
+
+/**
+ * @file
+ * @author Rafał Długołęcki
+ */
+
+namespace loglan {
+namespace vlp {
+namespace exception {
+
+/**
+ * Exception thrwon when configuration file has not been found
+ */
+class ConfigFileNotFound : public std::runtime_error
+{
+public:
+ ConfigFileNotFound() :
+ std::runtime_error("Configuration file has not been found") {
+ }
+};
+
+}
+}
+}
+
+#endif /* __VLP_EXCEPTION_CONFIGFILENOTFOUND_H */
svr.sun_family = AF_UNIX;
strcpy(svr.sun_path, mynname);
len = strlen(svr.sun_path) + sizeof(svr.sun_family);
+ fprintf(stderr, "logint: Binding to socket: %s\n", svr.sun_path);
bind(sock, (struct sockaddr*)&svr, len);
listen(sock, 5);
strcpy(svr.sun_path, argv[1]);
strcpy(mykname, argv[1]);
len = strlen(svr.sun_path) + sizeof(svr.sun_family);
+ fprintf(stderr, "logint: Connecting to socket: %s\n", svr.sun_path);
i = connect(internal_sock, (struct sockaddr*)&svr, len);
if (i==0) {
fcntl(internal_sock,F_SETFL, O_NONBLOCK |
fcntl(internal_sock,F_GETFL,0));
}
- else
+ else {
while (i!=0) {
close(internal_sock);
internal_sock = socket(AF_UNIX, SOCK_STREAM, 0);
fcntl(internal_sock, F_GETFL, 0));
i = connect(internal_sock, (struct sockaddr*)&svr, len);
}
+ }
on = 1;
setsockopt(internal_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on,
sizeof(on));
close(sock);
/* load code and prototypes */
- if (filename != NULL)
+ if (filename != NULL) {
+ fprintf(stderr, "logint: loading code: %s\n", filename);
load(filename);
- else
+ }
+ else {
usage();
+ }
}
/**
*/
int main(int argc, char **argv)
{
+ fprintf(stderr, "logint: initializing\n");
/* initialize executor */
initiate(argc, argv);
/* initialize running system */
+ fprintf(stderr, "logint: runsys\n");
runsys();
+ fprintf(stderr, "logint: initializing scheduler\n");
init_scheduler();
+ fprintf(stderr, "logint: acquiring GRAPH resource\n");
GraphRes = get_graph_res();
- if (GraphRes < 0)
+ if (GraphRes < 0) {
+ fprintf(stderr, "logint: > acquiring GRAPH resource failed\n");
exit(12);
+ }
request_id();
if (remote)
#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)*/
{
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], "");
}
}
+ loglan::vlp::QtConfigurationFinder configFinder;
+ configFinder.initSearchDirs();
+
QDir q(getRemoteDir());
if (!q.exists()) {
ActiveConnections = 0;
strcpy(LockPasswd, "");
- loadConfig(getConfigFilePath());
+ loadConfig(configFinder.findConfig().c_str());
RunNetModule();
}
strncpy(progdir, config.getProgramDir(), 256);
+
+ homeDir = QDir(QCoreApplication::applicationDirPath());
}
}
pid_t pid = fork();
if (pid == 0) {
if (execl(program.toStdString().c_str(),
+ "logedit",
getHomeDir(),
myargs[0],
myargs[1],
pid_t pid = fork();
if (pid == 0) {
if (execl(program.toStdString().c_str(),
+ "loghelp",
docDir.toStdString().c_str(),
myargs[0],
myargs[1],
pid_t pid = fork();
if (pid == 0) {
if (execl(program.toStdString().c_str(),
+ "loggraph",
program.toStdString().c_str(),
sk,
myargs[0],
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],
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,
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);