summaryrefslogtreecommitdiff
path: root/other/bootstrap_serverdaemon
diff options
context:
space:
mode:
authorMaxim Biro <nurupo.contributions@gmail.com>2014-01-19 04:53:39 -0500
committerMaxim Biro <nurupo.contributions@gmail.com>2014-01-19 04:57:46 -0500
commit8a80b5e0ac49a292d13ec0347592b45de976a601 (patch)
tree7bd82d934143eb22b1cd5197dcc59b8dff7de610 /other/bootstrap_serverdaemon
parent50ad4e84c506a66489272493f7a3c7d6bad3a03a (diff)
Fixed comments and variables' names
Diffstat (limited to 'other/bootstrap_serverdaemon')
-rw-r--r--other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c b/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c
index 25d3d9a0..fe3fb852 100644
--- a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c
+++ b/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c
@@ -21,16 +21,16 @@
21 * 21 *
22 */ 22 */
23 23
24#include <sys/types.h> /* pid_t */ 24#include <sys/types.h>
25#include <sys/stat.h> /* umask */ 25#include <sys/stat.h>
26#include <unistd.h> /* POSIX things */ 26#include <unistd.h>
27#include <syslog.h> 27#include <syslog.h>
28 28
29#include <stdio.h> 29#include <stdio.h>
30#include <stdlib.h> 30#include <stdlib.h>
31#include <libconfig.h> 31#include <libconfig.h>
32#include <arpa/inet.h> /* htons() */ 32#include <arpa/inet.h>
33#include <string.h> /* strcpy() */ 33#include <string.h>
34 34
35#ifdef HAVE_CONFIG_H 35#ifdef HAVE_CONFIG_H
36#include "config.h" 36#include "config.h"
@@ -103,8 +103,8 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi
103 config_t cfg; 103 config_t cfg;
104 104
105 const char *NAME_PORT = "port"; 105 const char *NAME_PORT = "port";
106 const char *NAME_PID_FILE = "pid_file_path"; 106 const char *NAME_PID_FILE_PATH = "pid_file_path";
107 const char *NAME_KEYS_FILE = "keys_file_path"; 107 const char *NAME_KEYS_FILE_PATH = "keys_file_path";
108 const char *NAME_ENABLE_IPV6 = "enable_ipv6"; 108 const char *NAME_ENABLE_IPV6 = "enable_ipv6";
109 const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery"; 109 const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery";
110 110
@@ -127,9 +127,9 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi
127 // Get PID file location 127 // Get PID file location
128 const char *tmp_pid_file; 128 const char *tmp_pid_file;
129 129
130 if (config_lookup_string(&cfg, NAME_PID_FILE, &tmp_pid_file) == CONFIG_FALSE) { 130 if (config_lookup_string(&cfg, NAME_PID_FILE_PATH, &tmp_pid_file) == CONFIG_FALSE) {
131 syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_PID_FILE); 131 syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_PID_FILE_PATH);
132 syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_PID_FILE, DEFAULT_PID_FILE_PATH); 132 syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_PID_FILE_PATH, DEFAULT_PID_FILE_PATH);
133 tmp_pid_file = DEFAULT_PID_FILE_PATH; 133 tmp_pid_file = DEFAULT_PID_FILE_PATH;
134 } 134 }
135 *pid_file_path = malloc(strlen(tmp_pid_file) + 1); 135 *pid_file_path = malloc(strlen(tmp_pid_file) + 1);
@@ -138,9 +138,9 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi
138 // Get keys file location 138 // Get keys file location
139 const char *tmp_keys_file; 139 const char *tmp_keys_file;
140 140
141 if (config_lookup_string(&cfg, NAME_KEYS_FILE, &tmp_keys_file) == CONFIG_FALSE) { 141 if (config_lookup_string(&cfg, NAME_KEYS_FILE_PATH, &tmp_keys_file) == CONFIG_FALSE) {
142 syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_KEYS_FILE); 142 syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_KEYS_FILE_PATH);
143 syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_KEYS_FILE, DEFAULT_KEYS_FILE_PATH); 143 syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_KEYS_FILE_PATH, DEFAULT_KEYS_FILE_PATH);
144 tmp_keys_file = DEFAULT_KEYS_FILE_PATH; 144 tmp_keys_file = DEFAULT_KEYS_FILE_PATH;
145 } 145 }
146 *keys_file_path = malloc(strlen(tmp_keys_file) + 1); 146 *keys_file_path = malloc(strlen(tmp_keys_file) + 1);
@@ -163,8 +163,8 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi
163 config_destroy(&cfg); 163 config_destroy(&cfg);
164 164
165 syslog(LOG_DEBUG, "Successfully read:\n"); 165 syslog(LOG_DEBUG, "Successfully read:\n");
166 syslog(LOG_DEBUG, "'%s': %s\n", NAME_PID_FILE, *pid_file_path); 166 syslog(LOG_DEBUG, "'%s': %s\n", NAME_PID_FILE_PATH, *pid_file_path);
167 syslog(LOG_DEBUG, "'%s': %s\n", NAME_KEYS_FILE, *keys_file_path); 167 syslog(LOG_DEBUG, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path);
168 syslog(LOG_DEBUG, "'%s': %d\n", NAME_PORT, *port); 168 syslog(LOG_DEBUG, "'%s': %d\n", NAME_PORT, *port);
169 syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); 169 syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false");
170 syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); 170 syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false");
@@ -219,7 +219,7 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
219 return 0; 219 return 0;
220 } 220 }
221 221
222 /* Proceed only if all parts are present */ 222 // Proceed only if all parts are present
223 if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE || 223 if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE ||
224 config_setting_lookup_int (server, NAME_PORT, &bs_port) == CONFIG_FALSE || 224 config_setting_lookup_int (server, NAME_PORT, &bs_port) == CONFIG_FALSE ||
225 config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE ) { 225 config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE ) {
@@ -336,7 +336,7 @@ int main(int argc, char *argv[])
336 return 1; 336 return 1;
337 } 337 }
338 338
339 // Check if the PId file exists 339 // Check if the PID file exists
340 if (fopen(pid_file_path, "r")) { 340 if (fopen(pid_file_path, "r")) {
341 syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists. Exiting.\n", pid_file_path); 341 syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists. Exiting.\n", pid_file_path);
342 return 1; 342 return 1;
@@ -408,20 +408,19 @@ int main(int argc, char *argv[])
408 fprintf(pidf, "%d\n", pid); 408 fprintf(pidf, "%d\n", pid);
409 fclose(pidf); 409 fclose(pidf);
410 410
411 /* Create a new SID for the child process */ 411 // Create a new SID for the child process
412
413 if (setsid() < 0) { 412 if (setsid() < 0) {
414 syslog(LOG_ERR, "SID creation failure. Exiting.\n"); 413 syslog(LOG_ERR, "SID creation failure. Exiting.\n");
415 return 1; 414 return 1;
416 } 415 }
417 416
418 /* Change the current working directory */ 417 // Change the current working directory
419 if ((chdir("/")) < 0) { 418 if ((chdir("/")) < 0) {
420 syslog(LOG_ERR, "Couldn't change working directory to '/'. Exiting.\n"); 419 syslog(LOG_ERR, "Couldn't change working directory to '/'. Exiting.\n");
421 return 1; 420 return 1;
422 } 421 }
423 422
424 /* Go quiet */ 423 // Go quiet
425 close(STDOUT_FILENO); 424 close(STDOUT_FILENO);
426 close(STDIN_FILENO); 425 close(STDIN_FILENO);
427 close(STDERR_FILENO); 426 close(STDERR_FILENO);