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[]) {
43 char* sport = argv[1];
44 unix_sock_file = argv[2];
45 char* slog_level = argv[3];
48 if(!sport || !unix_sock_file || !slog_level) {
50 "usage: %s <port> <path_to_unix_sock_file> <log_level [1-4]"
51 "(4 is the highest)> [log_file (optional, goes to stderr otherwise)]\n"
52 "e.g: %s 5222 /tmp/server.sock 1 /tmp/server.log\n",
58 log_level = atoi(slog_level);
61 warning_handler("invalid port (%d), falling back to 5222");
65 if(log_level < 1 || log_level > 4) {
66 warning_handler("log level (%d) is not recognized, falling back to WARN", log_level);
70 fprintf(stderr, "Launching with port %d, unix sock %s, log level %d, log file %s\n",
71 port, unix_sock_file, log_level, log_file );
73 if (daemonize() == -1) {
74 fprintf(stderr, "!!! Error forking the daemon! Going away now... :(\n");
78 signal(SIGHUP, &sig_hup_handler);
79 signal(SIGINT, &sig_int_handler);
80 signal(SIGTERM, &sig_int_handler);
86 void launch_server() {
88 log_init(log_level, log_file);
89 info_handler("Booting jserver-c on port %d and "
90 "sock file %s", port, unix_sock_file);
93 unlink(unix_sock_file);
94 if(jserver_connect(js, port, unix_sock_file) < 0)
95 fatal_handler("Could not connect...");