Skip to content

Commit

Permalink
determine default log file location from localstatedir, determine def…
Browse files Browse the repository at this point in the history
…ault config directory from sysconfdir, moved sysconfdir default to autogen.sh, adjusted author and git location
  • Loading branch information
john30 committed Feb 14, 2015
1 parent 287bb85 commit 2ca6be5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ test -n "$srcdir" || srcdir=.
mkdir -p "$srcdir/build"

autoreconf --force --install --verbose "$srcdir"
test -n "$NOCONFIGURE" || "$srcdir/configure" "--localstatedir=/var" "$@"
test -n "$NOCONFIGURE" || "$srcdir/configure" "--sysconfdir=/etc" "--localstatedir=/var" "$@"
11 changes: 4 additions & 7 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
AC_PREREQ([2.65])
AC_INIT([ebusd], [0.5.0], [[email protected]], [ebusd], [https://github.com/yuhu-/ebusd])

case "$@" in
*"--sysconfdir="*) ;;
*) sysconfdir=/etc ;;
esac
AC_INIT([ebusd], [0.5.0], [[email protected]], [ebusd], [https://github.com/john30/ebusd])

if test -z $CXXFLAGS;
then CXXFLAGS='-g -O2'
Expand Down Expand Up @@ -41,7 +36,9 @@ AC_CONFIG_FILES([Makefile
src/ebusd/Makefile
src/tools/Makefile])

AC_DEFINE_UNQUOTED(PACKAGE_PIDFILE, LOCALSTATEDIR "/run/" PACKAGE ".pid", [The name of the PID file.])
AC_DEFINE_UNQUOTED(PACKAGE_PIDFILE, LOCALSTATEDIR "/run/" PACKAGE ".pid", [The path and name of the PID file.])
AC_DEFINE_UNQUOTED(PACKAGE_LOGFILE, LOCALSTATEDIR "/log/" PACKAGE ".log", [The path and name of the log file.])
AC_DEFINE_UNQUOTED(PACKAGE_CONFIGPATH, SYSCONFDIR "/ebusd", [The default path of the configuration files.])

AC_CHECK_PROGS([HAVE_DOXYGEN], [doxygen])
if test -z "$HAVE_DOXYGEN";
Expand Down
31 changes: 22 additions & 9 deletions src/ebusd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,27 @@
#include <sys/types.h>
#include <sys/stat.h>

/** the name of the PID file. */
/** the path and name of the PID file. */
#ifdef PACKAGE_PIDFILE
#define PID_FILE_NAME PACKAGE_PIDFILE
#else
#define PID_FILE_NAME "/var/run/ebusd.pid"
#endif

/** the path and name of the log file. */
#ifdef PACKAGE_LOGFILE
#define LOG_FILE_NAME PACKAGE_LOGFILE
#else
#define LOG_FILE_NAME "/var/log/ebusd.log"
#endif

/** the default path of the configuration files. */
#ifdef PACKAGE_CONFIGPATH
#define CONFIG_PATH PACKAGE_CONFIGPATH
#else
#define CONFIG_PATH "/etc/ebusd"
#endif

/** the opened PID file, or NULL. */
static FILE* pidFile = NULL;

Expand All @@ -50,20 +64,20 @@ static bool isDaemon = false;
static struct options opt = {
"/dev/ttyUSB0", // device
false, // noDeviceCheck
"/etc/ebusd", // configPath
CONFIG_PATH, // configPath
false, // checkConfig
5, // pollInterval
0xFF, // address
false, // answer
9400, // acquireTimeout
2, // acquireRetries
2, // sendRetries
15000, // receiveTimeout
SLAVE_RECV_TIMEOUT, // receiveTimeout
5, // masterCount
false, // foreground
8888, // port
false, // localOnly
"/var/log/ebusd.log", // logFile
PACKAGE_LOGFILE, // logFile
false, // logRaw
false, // dump
"/tmp/ebus_dump.bin", // dumpFile
Expand Down Expand Up @@ -105,7 +119,7 @@ static const struct argp_option argpoptions[] = {
{"nodevicecheck", 'n', NULL, 0, "Skip serial eBUS device test", 0 },

{NULL, 0, NULL, 0, "Message configuration options:", 2 },
{"configpath", 'c', "PATH", 0, "Read CSV config files from PATH [/etc/ebusd]", 0 },
{"configpath", 'c', "PATH", 0, "Read CSV config files from PATH [" CONFIG_PATH "]", 0 },
{"checkconfig", O_CHKCFG, NULL, 0, "Only check CSV config files, then stop", 0 },
{"pollinterval", O_POLINT, "SEC", 0, "Poll for data every SEC seconds (0=disable) [5]", 0 },

Expand All @@ -124,8 +138,8 @@ static const struct argp_option argpoptions[] = {
{"localhost", O_LOCAL, NULL, 0, "Listen on 127.0.0.1 interface only", 0 },

{NULL, 0, NULL, 0, "Log options:", 5 },
{"logfile", 'l', "FILE", 0, "Write log to FILE (only for daemon) [/var/log/ebusd.log]", 0 },
{"logareas", O_LOGARE, "AREAS", 0, "Only write log for matching AREAS: main,network,bus,update,all [all]", 0 },
{"logfile", 'l', "FILE", 0, "Write log to FILE (only for daemon) [" PACKAGE_LOGFILE "]", 0 },
{"logareas", O_LOGARE, "AREAS", 0, "Only write log for matching AREA(S): main,network,bus,update,all [all]", 0 },
{"loglevel", O_LOGLEV, "LEVEL", 0, "Only write log below or equal to LEVEL: error/notice/info/debug [notice]", 0 },
{"lograwdata", O_LOGRAW, NULL, 0, "Log each received/sent byte on the bus", 0 },

Expand All @@ -134,7 +148,6 @@ static const struct argp_option argpoptions[] = {
{"dumpfile", O_DMPFIL, "FILE", 0, "Dump received bytes to FILE [/tmp/ebus_dump.bin]", 0 },
{"dumpsize", O_DMPSIZ, "SIZE", 0, "Make dump files no larger than SIZE kB [100]", 0 },

//{NULL, 0, NULL, 0, "Other:", 7 },
{NULL, 0, NULL, 0, NULL, 0 },
};

Expand Down Expand Up @@ -317,7 +330,7 @@ void daemonize()

// Change the current working directory. This prevents the current
// directory from being locked; hence not being able to remove it.
if (chdir("/tmp") < 0) { // TODO use constant
if (chdir("/tmp") < 0) {
logError(lf_main, "daemon chdir() failed");
exit(EXIT_FAILURE);
}
Expand Down

0 comments on commit 2ca6be5

Please sign in to comment.