Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion etc/vzlogger.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

{
// General settings
"daemon": false, // run periodically
"verbosity": 5, // log verbosity (0=log_alert, 1=log_error, 3=log_warning, 5=log_info, 10=log_debug, 15=log_finest)
"log": "/var/log/vzlogger.log", // log file, optional
"retry": 30, // http retry delay in seconds
Expand Down
7 changes: 0 additions & 7 deletions etc/vzlogger_generic.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1036,12 +1036,6 @@
"type": "integer",
"description": "How long to sleep between failed requests, in seconds"
},
"daemon": {
"id": "/daemon",
"type": "boolean",
"default": "true",
"description": "Enable daemon mode"
},
"verbosity": {
"id": "/verbosity",
"type": "integer",
Expand All @@ -1066,7 +1060,6 @@
}
},
"required": [
"daemon",
"log"
]
}
12 changes: 5 additions & 7 deletions include/Config_Options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ class Config_Options {
int retry_pause() const { return _retry_pause; }

bool channel_index() const { return _channel_index; }
bool daemon() const { return _daemon; }
bool local() const { return _local; }
bool logging() const { return _logging; }
bool foreground() const { return _foreground; }

bool doRegistration() const { return _doRegistration; }

Expand All @@ -90,9 +89,9 @@ class Config_Options {
_verbosity = v;
}

void daemon(const bool v) { _daemon = v; }
void local(const bool v) { _local = v; }
void logging(const bool v) { _logging = v; }

void foreground(const bool v) { _foreground = v; }

void doRegistration(const bool v) { _doRegistration = v; }

Expand All @@ -112,10 +111,9 @@ class Config_Options {

// boolean bitfields, padding at the end of struct
int _channel_index : 1; // give a index of all available channels via local interface
int _daemon : 1; // run in background
int _local : 1; // enable local interface
int _logging : 1; // start logging threads, depends on local & daemon
int _doRegistration : 1; // start logging threads, depends on local & daemon
int _foreground : 1; // don't daemonize
int _doRegistration : 1; // FIXME
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Channel::Channel(const std::list<Option> &pOptions, const std::string apiProtoco
}

/**
* Free all allocated memory recursivly
* Free all allocated memory recursively
*/
Channel::~Channel() {
// this hangs is the readingthread was pthread_cancelled during wait!
Expand Down
12 changes: 7 additions & 5 deletions src/Config_Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ static const char *option_type_str[] = {"null", "boolean", "double", "int",

Config_Options::Config_Options()
: _config("/etc/vzlogger.conf"), _log(""), _pds(0), _port(8080), _verbosity(0),
_comet_timeout(30), _buffer_length(-1), _retry_pause(15), _daemon(false), _local(false),
_logging(true) {
_comet_timeout(30), _buffer_length(-1), _retry_pause(15), _local(false), _foreground(false) {
_logfd = NULL;
}

Config_Options::Config_Options(const std::string filename)
: _config(filename), _log(""), _pds(0), _port(8080), _verbosity(0), _comet_timeout(30),
_buffer_length(-1), _retry_pause(15), _daemon(false), _local(false), _logging(true) {
_buffer_length(-1), _retry_pause(15), _local(false), _foreground(false) {
_logfd = NULL;
}

Expand Down Expand Up @@ -118,7 +117,10 @@ void Config_Options::config_parse(MapContainer &mappings) {
enum json_type type = json_object_get_type(value);

if (strcmp(key, "daemon") == 0 && type == json_type_boolean) {
_daemon = json_object_get_boolean(value);
if (!json_object_get_boolean(value)) {
throw vz::VZException("\"daemon\" option is not supported anymore, "
"you probably want to use -f instead.");
}
} else if (strcmp(key, "log") == 0 && type == json_type_string) {
_log = json_object_get_string(value);
} else if (strcmp(key, "retry") == 0 && type == json_type_int) {
Expand Down Expand Up @@ -267,7 +269,7 @@ void Config_Options::config_parse_channel(Json &jso, MeterMap &mapping) {
}
// check if identifier is set. If not, use default
if (id_str == NULL) {
print(log_error, "Identifier is not set. Set it to default value 'NilIdentifier'.", NULL);
print(log_error, "Identifier is not set. Using default value 'NilIdentifier'.", NULL);
id_str = "NilIdentifier";
}
// if (middleware == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/Meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Meter::Meter(std::list<Option> pOptions) : _name("meter") {
// enable
_enable = optlist.lookup_bool(pOptions, "enabled");
} catch (vz::OptionNotFoundException &e) {
_enable = false; /* bye default meter is disabled */
_enable = false; /* by default meter is disabled */
} catch (vz::VZException &e) {
print(log_alert, "Invalid type for enable", name());
throw;
Expand Down
4 changes: 2 additions & 2 deletions src/MeterMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void MeterMap::start() {
}
}

void MeterMap::cancel() { // get's called from MapContainer::quit that get's called from sigint
void MeterMap::cancel() { // is called from MapContainer::quit which is called from sigint handler
// handler ::quit
print(log_finest, "MeterMap::cancel entered...", _meter->name());
if (_meter->isEnabled() && running()) {
Expand Down Expand Up @@ -115,7 +115,7 @@ void MeterMap::registration() {
print(log_debug, "Using InfluxDB api", (*ch)->name());
} else if (0 == strcasecmp((*ch)->apiProtocol().c_str(), "null")) {
api = vz::ApiIF::Ptr(new vz::api::Null(*ch, (*ch)->options()));
print(log_debug, "Using null api- meter data available via local httpd if enabled.",
print(log_debug, "Using null api - meter data available via local httpd if enabled.",
(*ch)->name());
} else {
if (strcasecmp((*ch)->apiProtocol().c_str(), "volkszaehler"))
Expand Down
2 changes: 1 addition & 1 deletion src/api/InfluxDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void vz::api::InfluxDB::send() {

print(log_debug, "Buffer has %i items", channel()->name(), buf->size());

// delete items if the buffer gets too big
// delete items if the buffer grows too large
if (buf->size() > (unsigned)_max_buffer_size) {
print(log_warning,
"Buffer too big (%i items). Deleting items. (This indicates a connection problem)",
Expand Down
4 changes: 2 additions & 2 deletions src/api/MySmartGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void vz::api::MySmartGrid::send() {
/* householding */
json_object_put(json_obj);

if (options.daemon() && (curl_code != CURLE_OK || http_code != 200)) {
if ((curl_code != CURLE_OK || http_code != 200)) {
print(log_info, "Waiting %i secs for next request due to previous failure",
channel()->name(), options.retry_pause());
sleep(options.retry_pause());
Expand Down Expand Up @@ -299,7 +299,7 @@ void vz::api::MySmartGrid::_send(const std::string &url, json_object *json_obj)
/* householding */
json_object_put(json_obj);

if (options.daemon() && (curl_code != CURLE_OK || http_code != 200)) {
if ((curl_code != CURLE_OK || http_code != 200)) {
print(log_info, "Waiting %i secs for next request due to previous failure",
channel()->name(), options.retry_pause());
sleep(options.retry_pause());
Expand Down
2 changes: 1 addition & 1 deletion src/api/Volkszaehler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void vz::api::Volkszaehler::send() {
free(response.data);
json_object_put(json_obj);

if (options.daemon() && (curl_code != CURLE_OK || http_code != 200)) {
if ((curl_code != CURLE_OK || http_code != 200)) {
print(log_info, "Waiting %i secs for next request due to previous failure",
channel()->name(), options.retry_pause());
sleep(options.retry_pause());
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/MeterS0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ void timespec_add_ms(struct timespec &a, unsigned long ms) {
}

void MeterS0::check_ref_for_overflow() {
// check whether _ms_last_impulse get's too long
// and has risk for overflow (roughly once a month with 32bit unsigned long)
// protect against _ms_last_impulse overflwing,
// it would overflow roughly once a month with 32bit unsigned long

if (_ms_last_impulse > (1ul << 30)) {
// now we enter a race condition so there might be wrong impulse now!
Expand Down
10 changes: 4 additions & 6 deletions src/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ void *reading_thread(void *arg) {
;

print(log_debug, "Number of readers: %d", mtr->name(), details->max_readings);
print(log_debug, "Config.daemon: %d", mtr->name(), options.daemon());
print(log_debug, "Config.local: %d", mtr->name(), options.local());

try {
Expand Down Expand Up @@ -171,7 +170,7 @@ void *reading_thread(void *arg) {
print(log_info, "Next reading in %i seconds", mtr->name(), mtr->interval());
sleep(mtr->interval());
}
} while (options.daemon() || options.local());
} while (true);
} catch (std::exception &e) {
std::stringstream oss;
oss << e.what();
Expand All @@ -185,14 +184,13 @@ void *reading_thread(void *arg) {
return NULL;
}

void *logging_thread(void *arg) { // get's started from Channel::start and stopped via
void *logging_thread(void *arg) { // is started by Channel::start and stopped via
// Channel::cancel via pthread_cancel!
Channel *__this =
static_cast<Channel *>(arg); // retrieve the pointer to the corresponding Channel
Channel::Ptr ch = __this->_this_forthread; // And get a copy of the Channel owner's shared_ptr
// for passing it on.
print(log_debug, "Start logging thread for %s-api. Running as daemon: %s", ch->name(),
ch->apiProtocol().c_str(), options.daemon() ? "yes" : "no");
print(log_debug, "Start logging thread for %s-api.", ch->name(), ch->apiProtocol().c_str());

// create configured api interfaces
// NOTE: if additional APIs are introduced both threads.cpp and MeterMap.cpp need to be updated
Expand Down Expand Up @@ -228,7 +226,7 @@ void *logging_thread(void *arg) { // get's started from Channel::start and stopp

} while (true); // endless?!

print(log_debug, "Stopped logging. (daemon=%d)", ch->name(), options.daemon());
print(log_debug, "Stopped logging.", ch->name());
pthread_exit(0);

return NULL;
Expand Down
16 changes: 8 additions & 8 deletions src/vzlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ std::mutex
const struct option long_options[] = {
{"config", required_argument, 0, 'c'},
{"log", required_argument, 0, 'o'},
{"daemon", required_argument, 0, 'd'},
{"foreground", no_argument, 0, 'f'},
#ifdef LOCAL_SUPPORT
{"httpd", no_argument, 0, 'l'},
{"httpd-port", required_argument, 0, 'p'},
Expand All @@ -93,7 +93,7 @@ const struct option long_options[] = {
const char *long_options_descs[] = {
"configuration file",
"log file",
"run in background",
"run in foreground, do not daemonize",
#ifdef LOCAL_SUPPORT
"activate local interface (tiny HTTPd which serves live readings)",
"TCP port for HTTPd",
Expand Down Expand Up @@ -285,7 +285,7 @@ void signalHandlerQuit(int sig) {
*/
int config_parse_cli(int argc, char *argv[], Config_Options *options) {
while (1) {
int c = getopt_long(argc, argv, "c:o:p:lhrVdfv:", long_options, NULL);
int c = getopt_long(argc, argv, "c:o:p:lhrVfv:", long_options, NULL);

/* detect the end of the options. */
if (c == -1)
Expand All @@ -306,8 +306,8 @@ int config_parse_cli(int argc, char *argv[], Config_Options *options) {
break;
#endif /* LOCAL_SUPPORT */

case 'd':
options->daemon(1);
case 'f':
options->foreground(1);
break;

case 'c': /* config file */
Expand Down Expand Up @@ -425,13 +425,13 @@ int main(int argc, char *argv[]) {
return (0);
}

print(log_debug, "daemon=%d, local=%d", "main", options.daemon(), options.local());
print(log_debug, "local=%d", "main", options.local());

if (options.daemon()) {
if (!options.foreground()) {
print(log_info, "Daemonize process...", (char *)0);
daemonize();
} else {
print(log_info, "Process not daemonized...", (char *)0);
print(log_info, "Process not daemonized...", (char *)0);
}

/* open logfile */
Expand Down