|
@@ -15,7 +15,9 @@
|
|
#include <stdbool.h>
|
|
#include <stdbool.h>
|
|
#include <glib.h>
|
|
#include <glib.h>
|
|
#include <getopt.h>
|
|
#include <getopt.h>
|
|
|
|
+#ifndef _WIN32
|
|
#include <syslog.h>
|
|
#include <syslog.h>
|
|
|
|
+#endif
|
|
#include "json-streamer.h"
|
|
#include "json-streamer.h"
|
|
#include "json-parser.h"
|
|
#include "json-parser.h"
|
|
#include "qint.h"
|
|
#include "qint.h"
|
|
@@ -44,6 +46,7 @@ struct GAState {
|
|
|
|
|
|
static struct GAState *ga_state;
|
|
static struct GAState *ga_state;
|
|
|
|
|
|
|
|
+#ifndef _WIN32
|
|
static void quit_handler(int sig)
|
|
static void quit_handler(int sig)
|
|
{
|
|
{
|
|
g_debug("received signal num %d, quitting", sig);
|
|
g_debug("received signal num %d, quitting", sig);
|
|
@@ -73,6 +76,7 @@ static gboolean register_signal_handlers(void)
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+#endif
|
|
|
|
|
|
static void usage(const char *cmd)
|
|
static void usage(const char *cmd)
|
|
{
|
|
{
|
|
@@ -87,7 +91,9 @@ static void usage(const char *cmd)
|
|
" -f, --pidfile specify pidfile (default is %s)\n"
|
|
" -f, --pidfile specify pidfile (default is %s)\n"
|
|
" -v, --verbose log extra debugging information\n"
|
|
" -v, --verbose log extra debugging information\n"
|
|
" -V, --version print version information and exit\n"
|
|
" -V, --version print version information and exit\n"
|
|
|
|
+#ifndef _WIN32
|
|
" -d, --daemonize become a daemon\n"
|
|
" -d, --daemonize become a daemon\n"
|
|
|
|
+#endif
|
|
" -b, --blacklist comma-separated list of RPCs to disable (no spaces, \"?\""
|
|
" -b, --blacklist comma-separated list of RPCs to disable (no spaces, \"?\""
|
|
" to list available RPCs)\n"
|
|
" to list available RPCs)\n"
|
|
" -h, --help display this help and exit\n"
|
|
" -h, --help display this help and exit\n"
|
|
@@ -143,9 +149,13 @@ static void ga_log(const gchar *domain, GLogLevelFlags level,
|
|
}
|
|
}
|
|
|
|
|
|
level &= G_LOG_LEVEL_MASK;
|
|
level &= G_LOG_LEVEL_MASK;
|
|
|
|
+#ifndef _WIN32
|
|
if (domain && strcmp(domain, "syslog") == 0) {
|
|
if (domain && strcmp(domain, "syslog") == 0) {
|
|
syslog(LOG_INFO, "%s: %s", level_str, msg);
|
|
syslog(LOG_INFO, "%s: %s", level_str, msg);
|
|
} else if (level & s->log_level) {
|
|
} else if (level & s->log_level) {
|
|
|
|
+#else
|
|
|
|
+ if (level & s->log_level) {
|
|
|
|
+#endif
|
|
g_get_current_time(&time);
|
|
g_get_current_time(&time);
|
|
fprintf(s->log_file,
|
|
fprintf(s->log_file,
|
|
"%lu.%lu: %s: %s\n", time.tv_sec, time.tv_usec, level_str, msg);
|
|
"%lu.%lu: %s: %s\n", time.tv_sec, time.tv_usec, level_str, msg);
|
|
@@ -153,6 +163,7 @@ static void ga_log(const gchar *domain, GLogLevelFlags level,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#ifndef _WIN32
|
|
static void become_daemon(const char *pidfile)
|
|
static void become_daemon(const char *pidfile)
|
|
{
|
|
{
|
|
pid_t pid, sid;
|
|
pid_t pid, sid;
|
|
@@ -203,6 +214,7 @@ fail:
|
|
g_critical("failed to daemonize");
|
|
g_critical("failed to daemonize");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
+#endif
|
|
|
|
|
|
static int send_response(GAState *s, QObject *payload)
|
|
static int send_response(GAState *s, QObject *payload)
|
|
{
|
|
{
|
|
@@ -466,10 +478,12 @@ int main(int argc, char **argv)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#ifndef _WIN32
|
|
if (daemonize) {
|
|
if (daemonize) {
|
|
g_debug("starting daemon");
|
|
g_debug("starting daemon");
|
|
become_daemon(pidfile);
|
|
become_daemon(pidfile);
|
|
}
|
|
}
|
|
|
|
+#endif
|
|
|
|
|
|
s = g_malloc0(sizeof(GAState));
|
|
s = g_malloc0(sizeof(GAState));
|
|
s->log_file = log_file;
|
|
s->log_file = log_file;
|
|
@@ -482,10 +496,12 @@ int main(int argc, char **argv)
|
|
ga_command_state_init_all(s->command_state);
|
|
ga_command_state_init_all(s->command_state);
|
|
json_message_parser_init(&s->parser, process_event);
|
|
json_message_parser_init(&s->parser, process_event);
|
|
ga_state = s;
|
|
ga_state = s;
|
|
|
|
+#ifndef _WIN32
|
|
if (!register_signal_handlers()) {
|
|
if (!register_signal_handlers()) {
|
|
g_critical("failed to register signal handlers");
|
|
g_critical("failed to register signal handlers");
|
|
goto out_bad;
|
|
goto out_bad;
|
|
}
|
|
}
|
|
|
|
+#endif
|
|
|
|
|
|
s->main_loop = g_main_loop_new(NULL, false);
|
|
s->main_loop = g_main_loop_new(NULL, false);
|
|
if (!channel_init(ga_state, method, path)) {
|
|
if (!channel_init(ga_state, method, path)) {
|