8 char* unix_sock_file = NULL;
10 char* log_file = NULL;
12 /* starts the logging and server processes */
16 /* shut down, clean up, and restart */
17 void sig_hup_handler( int a ) {
18 warning_handler(" +++ Re-launching server for SIGHUP");
22 unlink(unix_sock_file);
29 void sig_int_handler( int a ) {
30 warning_handler(" +++ Shutting down because of user signal");
33 unlink(unix_sock_file);
39 /* loads the command line settings and launches the server */
40 int main(int argc, char* argv[]) {
42 signal(SIGHUP, &sig_hup_handler);
43 signal(SIGINT, &sig_int_handler);
44 signal(SIGTERM, &sig_int_handler);
47 char* sport = argv[1];
48 unix_sock_file = argv[2];
49 char* slog_level = argv[3];
52 if(!sport || !unix_sock_file || !slog_level) {
54 "usage: %s <port> <path_to_unix_sock_file> <log_level [1-4]"
55 "(4 is the highest)> [log_file (optional, goes to stderr otherwise)]\n"
56 "e.g: %s 5222 /tmp/server.sock 1 /tmp/server.log\n",
62 log_level = atoi(slog_level);
65 warning_handler("invalid port (%d), falling back to 5222");
69 if(log_level < 1 || log_level > 4) {
70 warning_handler("log level (%d) is not recognized, falling back to WARN", log_level);
74 fprintf(stderr, "Launching with port %d, unix sock %s, log level %d, log file %s\n",
75 port, unix_sock_file, log_level, log_file );
81 void launch_server() {
83 log_init(log_level, log_file);
84 info_handler("Booting jserver-c on port %d and "
85 "sock file %s", port, unix_sock_file);
88 if(jserver_connect(js, port, unix_sock_file) < 0)
89 fatal_handler("Could not connect...");