Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/bt-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>

#include <glib.h>
#include <glib/gstdio.h>
Expand Down Expand Up @@ -151,13 +152,23 @@ term_signal_handler(gpointer data)
return G_SOURCE_REMOVE;
}

static void print_handler(const gchar *msg) {
syslog(LOG_INFO, "%s", msg);
}

static void printerr_handler(const gchar *msg) {
syslog(LOG_ERR, "%s", msg);
}

static gchar *capability_arg = NULL;
static gboolean daemon_arg = FALSE;
static gboolean syslog_arg = FALSE;

static GOptionEntry entries[] = {
{"capability", 'c', 0, G_OPTION_ARG_STRING, &capability_arg, "Agent capability", "<capability>"},
{"pin", 'p', 0, G_OPTION_ARG_STRING, &pin_arg, "Path to the PIN's file"},
{"daemon", 'd', 0, G_OPTION_ARG_NONE, &daemon_arg, "Run in background (as daemon)"},
{"syslog", 's', 0, G_OPTION_ARG_NONE, &syslog_arg, "Redirect output to syslog"},
{NULL}
};

Expand Down Expand Up @@ -192,6 +203,12 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}

if (syslog_arg) {
openlog("bt-agent", LOG_PID | LOG_CONS, LOG_DAEMON);
g_set_print_handler(print_handler);
g_set_printerr_handler(printerr_handler);
}

if (capability_arg) {
if (
g_strcmp0(capability_arg, "DisplayOnly") != 0 &&
Expand Down Expand Up @@ -294,5 +311,9 @@ int main(int argc, char *argv[])

dbus_disconnect();

if (syslog_arg) {
closelog();
}

exit(EXIT_SUCCESS);
}