Skip to content

Commit

Permalink
add -f/--foreground option,
Browse files Browse the repository at this point in the history
this is intentionally not available via the config-file.
partially reverts 1d4972d
  • Loading branch information
r00t- committed Feb 21, 2021
1 parent abf1b5f commit 2510c84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions include/Config_Options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Config_Options {

bool channel_index() const { return _channel_index; }
bool local() const { return _local; }
bool foreground() const { return _foreground; }

bool doRegistration() const { return _doRegistration; }

Expand All @@ -90,6 +91,8 @@ class Config_Options {

void local(const bool v) { _local = v; }

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

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

PushDataServer *pushDataServer() const { return _pds; }
Expand All @@ -109,6 +112,7 @@ 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 _local : 1; // enable local interface
int _foreground : 1; /* dont fork in background */
int _doRegistration : 1; // FIXME
};

Expand Down
4 changes: 2 additions & 2 deletions src/Config_Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +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), _local(false) {
_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), _local(false) {
_buffer_length(-1), _retry_pause(15), _local(false), _foreground(false) {
_logfd = NULL;
}

Expand Down
8 changes: 7 additions & 1 deletion src/vzlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ std::mutex
const struct option long_options[] = {
{"config", required_argument, 0, 'c'},
{"log", required_argument, 0, 'o'},
{"foreground", no_argument, 0, 'f'},
#ifdef LOCAL_SUPPORT
{"httpd", no_argument, 0, 'l'},
{"httpd-port", required_argument, 0, 'p'},
Expand All @@ -92,6 +93,7 @@ const struct option long_options[] = {
const char *long_options_descs[] = {
"configuration file",
"log file",
"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 @@ -304,6 +306,10 @@ int config_parse_cli(int argc, char *argv[], Config_Options *options) {
break;
#endif /* LOCAL_SUPPORT */

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

case 'c': /* config file */
options->config(optarg);
break;
Expand Down Expand Up @@ -421,7 +427,7 @@ int main(int argc, char *argv[]) {

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

if (true) {
if (!options.foreground()) {
print(log_info, "Daemonize process...", (char *)0);
daemonize();
} else {
Expand Down

0 comments on commit 2510c84

Please sign in to comment.