X-Git-Url: http://www.average.org/gitweb/?p=pulsecounter.git;a=blobdiff_plain;f=linux%2Fpulsecounter.c;h=89568c98597a972c45fb24e562c03642558e58a9;hp=5f629f14b96b41125c9023687e1502cb5b6eeded;hb=757a8cd063d57fa1dc7628cac5e8cde9d45c10b9;hpb=9e60d66129fbe12edece200733bd42a7566ab10e diff --git a/linux/pulsecounter.c b/linux/pulsecounter.c index 5f629f1..89568c9 100644 --- a/linux/pulsecounter.c +++ b/linux/pulsecounter.c @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -32,6 +33,7 @@ static int opt_mtu = 0; static int opt_psm = 0; static char *opt_sec_level = NULL; static char *opt_dbconffile = NULL; +static gboolean opt_daemon = FALSE; static GMainLoop *event_loop; @@ -48,11 +50,33 @@ static GOptionEntry options[] = { "Specify the PSM for GATT/ATT over BR/EDR", "PSM" }, { "sec-level", 'l', 0, G_OPTION_ARG_STRING, &opt_sec_level, "Set security level. Default: low", "[low | medium | high]"}, - { "dbconfig", 'c', 0, G_OPTION_ARG_STRING, &opt_dbconffile, + { "dbconfig", 'c', 0, G_OPTION_ARG_FILENAME, &opt_dbconffile, + "Specify file name with database configuration", "cfile"}, + { "daemon", 'd', 0, G_OPTION_ARG_NONE, &opt_daemon, "Specify file name with database configuration", "cfile"}, { NULL }, }; +void local_log_handler(const gchar *log_domain, GLogLevelFlags log_level, + const gchar *message, gpointer log_context) +{ + int syslog_level; + + switch (log_level) { + case G_LOG_LEVEL_CRITICAL: syslog_level = LOG_CRIT; break; + case G_LOG_LEVEL_ERROR: syslog_level = LOG_ERR; break; + case G_LOG_LEVEL_WARNING: syslog_level = LOG_WARNING; break; + case G_LOG_LEVEL_MESSAGE: syslog_level = LOG_NOTICE; break; + case G_LOG_LEVEL_INFO: syslog_level = LOG_INFO; break; + case G_LOG_LEVEL_DEBUG: syslog_level = LOG_DEBUG; break; + default: syslog_level = LOG_INFO; + } + if (!log_domain || (log_domain[0] == '\0')) + syslog(syslog_level, "%s", message); + else + syslog(syslog_level, "%s: %s", log_domain, message); +} + static gboolean channel_watcher(GIOChannel *chan, GIOCondition cond, gpointer user_data) { @@ -132,7 +156,7 @@ int main(int argc, char *argv[]) gboolean got_error = FALSE; g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL - | G_LOG_FLAG_RECURSION, g_log_default_handler, NULL); + | G_LOG_FLAG_RECURSION, local_log_handler, NULL); opt_dst_type = g_strdup("public"); opt_sec_level = g_strdup("low"); opt_dbconffile = g_strdup("/etc/pulsecounter.db"); @@ -154,6 +178,7 @@ int main(int argc, char *argv[]) got_error = TRUE; goto done; } + if (opt_daemon) daemon(0, 0); while (1) { chan = gatt_connect(opt_src, opt_dst, opt_dst_type, opt_sec_level, opt_psm, opt_mtu, connect_cb, &gerr);