From 8b5e3d520825f3376ec0fd00ba3aadc60c625d5f Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 18 May 2014 19:26:36 -0400 Subject: Allow multiple instances of the daemon --- other/bootstrap_daemon/tox_bootstrap_daemon.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index 2c8f7014..0d18d411 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -485,8 +485,7 @@ int main(int argc, char *argv[]) // Check if the PID file exists if (fopen(pid_file_path, "r")) { - syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists. Exiting.\n", pid_file_path); - return 1; + syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists.\n", pid_file_path); } IP ip; @@ -555,10 +554,10 @@ int main(int argc, char *argv[]) print_public_key(dht->self_public_key); // Write the PID file - FILE *pidf = fopen(pid_file_path, "w"); + FILE *pidf = fopen(pid_file_path, "a+"); if (pidf == NULL) { - syslog(LOG_ERR, "Can't open the PID file for writing: %s. Exiting.\n", pid_file_path); + syslog(LOG_ERR, "Couldn't open the PID file for writing: %s. Exiting.\n", pid_file_path); return 1; } @@ -575,7 +574,7 @@ int main(int argc, char *argv[]) } if (pid > 0) { - fprintf(pidf, "%d\n", pid); + fprintf(pidf, "%d ", pid); fclose(pidf); syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid); return 0; -- cgit v1.2.3 From 261a70353ff316cc993c23faf07cb0f60e2e5819 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 18 May 2014 19:28:18 -0400 Subject: Fixed a bug --- other/bootstrap_daemon/tox_bootstrap_daemon.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index 0d18d411..afe2b2ac 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -164,8 +164,8 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int } (*tcp_relay_ports)[*tcp_relay_port_count] = config_setting_get_int(elem); - if ((*tcp_relay_ports)[i] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[i] > MAX_ALLOWED_PORT) { - syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, (*tcp_relay_ports)[i], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); + if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { + syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); continue; } @@ -173,7 +173,7 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int } // the loop above skips invalid ports, so we adjust the allocated memory size - *tcp_relay_ports = realloc(*tcp_relay_ports, *tcp_relay_port_count * sizeof(uint16_t)); + *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); } // Gets general config options -- cgit v1.2.3 From fe1694fa6963ca0eceb898e4a07c60c123f23184 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 18 May 2014 19:31:50 -0400 Subject: Added default ports to the .c file, included 33445 port --- other/bootstrap_daemon/conf | 4 +-- other/bootstrap_daemon/tox_bootstrap_daemon.c | 45 ++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/other/bootstrap_daemon/conf b/other/bootstrap_daemon/conf index bbdf7652..23580d9d 100644 --- a/other/bootstrap_daemon/conf +++ b/other/bootstrap_daemon/conf @@ -22,9 +22,9 @@ enable_lan_discovery = true enable_tcp_relay = true -// Tox uses 443 and 3389 ports by default, so it's highly recommended to keep +// Tox uses 443, 3389 and 33445 ports by default, so it's highly recommended to keep // them. -tcp_relay_ports = [443, 3389] +tcp_relay_ports = [443, 3389, 33445] // It's planned to use message of the day as a convenient method of checking // whether a node is up or not, though there are other methods of doing that. diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index afe2b2ac..66271288 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -58,14 +58,16 @@ #define SLEEP_TIME_MILLISECONDS 30 #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) -#define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid" -#define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys" -#define DEFAULT_PORT 33445 -#define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false -#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false -#define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false -#define DEFAULT_ENABLE_MOTD 1 // 1 - true, 0 - false -#define DEFAULT_MOTD DAEMON_NAME +#define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid" +#define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys" +#define DEFAULT_PORT 33445 +#define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false +#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false +#define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false +#define DEFAULT_TCP_RELAY_PORTS 443, 3389, 33445 // comma-separated list of ports. make sure to adjust DEFAULT_TCP_RELAY_PORTS_COUNT accordingly +#define DEFAULT_TCP_RELAY_PORTS_COUNT 3 +#define DEFAULT_ENABLE_MOTD 1 // 1 - true, 0 - false +#define DEFAULT_MOTD DAEMON_NAME #define MIN_ALLOWED_PORT 1 #define MAX_ALLOWED_PORT 65535 @@ -129,6 +131,33 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int if (ports_array == NULL) { syslog(LOG_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS); + syslog(LOG_WARNING, "Using default '%s':\n", NAME_TCP_RELAY_PORTS); + + uint16_t default_ports[DEFAULT_TCP_RELAY_PORTS_COUNT] = {DEFAULT_TCP_RELAY_PORTS}; + + int i; + + for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { + syslog(LOG_WARNING, "Port #%d: %u\n", i, default_ports[i]); + } + + // similar procedure to the one of reading config file below + *tcp_relay_ports = malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t)); + + for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { + + (*tcp_relay_ports)[*tcp_relay_port_count] = default_ports[i]; + if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { + syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); + continue; + } + + (*tcp_relay_port_count) ++; + } + + // the loop above skips invalid ports, so we adjust the allocated memory size + *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); + return; } -- cgit v1.2.3 From 286d8d966166c590b2a775b05a7ee7be0f69fe70 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 18 May 2014 19:38:45 -0400 Subject: Made config file more consistent with default values --- other/bootstrap_daemon/conf | 4 ++-- other/bootstrap_daemon/tox_bootstrap_daemon.c | 2 +- other/bootstrap_daemon/tox_bootstrap_daemon.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/other/bootstrap_daemon/conf b/other/bootstrap_daemon/conf index 23580d9d..c05beff1 100644 --- a/other/bootstrap_daemon/conf +++ b/other/bootstrap_daemon/conf @@ -6,13 +6,13 @@ port = 33445 // A key file is like a password, so keep it where no one can read it. // The daemon should have permission to read/write to it. // Remember to replace the provided example with your own path. -keys_file_path = "/home/tom/.tox_bootstrap_daemon/keys" +keys_file_path = "/home/tom/.tox_bootstrap_daemon/.tox_bootstrap_daemon.keys" // The PID file written to by daemon. // Make sure that the user who runs the daemon has permissions to write to the // PID file. // Remember to replace the provided example with your own path. -pid_file_path = "/home/tom/.tox_bootstrap_daemon/pid" +pid_file_path = "/home/tom/.tox_bootstrap_daemon/.tox_bootstrap_daemon.pid" // Enable IPv6. enable_ipv6 = false diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index 66271288..ceb4fded 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -53,7 +53,7 @@ #define DAEMON_NAME "tox_bootstrap_daemon" -#define DAEMON_VERSION_NUMBER 2014051700UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day +#define DAEMON_VERSION_NUMBER 2014051800UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day #define SLEEP_TIME_MILLISECONDS 30 #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.sh b/other/bootstrap_daemon/tox_bootstrap_daemon.sh index e083ea0b..787498ec 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.sh +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.sh @@ -18,7 +18,7 @@ USER=tom CFG=/home/$USER/.$NAME/conf DAEMON=/home/$USER/.$NAME/$NAME DAEMON_ARGS="$CFG" -PIDFILE=/home/$USER/.$NAME/pid +PIDFILE=/home/$USER/.$NAME/."$NAME".pid SCRIPTNAME=/etc/init.d/$NAME # Exit if the package is not installed -- cgit v1.2.3