includedir = @includedir@/connman
-noinst_HEADERS = plugin.h iface.h rtnl.h dhcp.h
+noinst_HEADERS = log.h plugin.h iface.h rtnl.h dhcp.h
MAINTAINERCLEANFILES = Makefile.in
--- /dev/null
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2007 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __CONNMAN_LOG_H
+#define __CONNMAN_LOG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DBG(fmt, arg...) connman_debug(fmt, ## arg)
+
+extern void connman_info(const char *format, ...);
+extern void connman_error(const char *format, ...);
+extern void connman_debug(const char *format, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_LOG_H */
sbin_PROGRAMS = connmand
-connmand_SOURCES = main.c connman.h manager.c agent.c plugin.c \
- iface.c iface-storage.c iface-helper.c \
- iface-inet.c rtnl.c dhcp.c
+connmand_SOURCES = main.c connman.h log.c manager.c agent.c plugin.c \
+ iface.c iface-storage.c iface-helper.c \
+ iface-inet.c rtnl.c dhcp.c
connmand_LDADD = @HAL_LIBS@ @GDBUS_LIBS@ @GMODULE_LIBS@
#include <stdio.h>
-#define DBG(fmt, arg...) printf("%s: " fmt "\n" , __FUNCTION__ , ## arg)
-//#define DBG(fmt, arg...)
-
#include <dbus/dbus.h>
#define CONNMAN_SERVICE "org.freedesktop.connman"
int __connman_agent_register(const char *sender, const char *path);
int __connman_agent_unregister(const char *sender, const char *path);
+#include <connman/log.h>
+
+int __connman_log_init(int syslog, int debug);
+void __connman_log_cleanup(void);
+
#include <connman/plugin.h>
int __connman_plugin_init(void);
--- /dev/null
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2007 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdarg.h>
+#include <syslog.h>
+
+#include "connman.h"
+
+static volatile int debug_enabled = 0;
+
+void connman_info(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+
+ vsyslog(LOG_INFO, format, ap);
+
+ va_end(ap);
+}
+
+void connman_error(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+
+ vsyslog(LOG_ERR, format, ap);
+
+ va_end(ap);
+}
+
+void connman_debug(const char *format, ...)
+{
+ va_list ap;
+
+ if (!debug_enabled)
+ return;
+
+ va_start(ap, format);
+
+ vsyslog(LOG_DEBUG, format, ap);
+
+ va_end(ap);
+}
+
+int __connman_log_init(int syslog, int debug)
+{
+ int option = LOG_NDELAY | LOG_PID;
+
+ if (!syslog)
+ option |= LOG_PERROR;
+
+ openlog("connmand", option, LOG_DAEMON);
+
+ syslog(LOG_INFO, "Connection Manager version %s", VERSION);
+
+ debug_enabled = debug;
+
+ return 0;
+}
+
+void __connman_log_cleanup(void)
+{
+ syslog(LOG_INFO, "Exit");
+
+ closelog();
+}
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-#include <syslog.h>
#include <signal.h>
#include <getopt.h>
#include <sys/stat.h>
static struct option options[] = {
{ "nodaemon", 0, 0, 'n' },
{ "compat", 0, 0, 'c' },
+ { "debug", 0, 0, 'd' },
{ "help", 0, 0, 'h' },
{ }
};
DBusConnection *conn;
DBusError err;
struct sigaction sa;
- int log_option = LOG_NDELAY | LOG_PID;
- int opt, detach = 1, compat = 0;
+ int opt, detach = 1, compat = 0, debug = 0;
- while ((opt = getopt_long(argc, argv, "+nch", options, NULL)) != EOF) {
- switch(opt) {
+ while ((opt = getopt_long(argc, argv, "+ncdh", options, NULL)) != EOF) {
+ switch (opt) {
case 'n':
detach = 0;
break;
case 'c':
compat = 1;
break;
+ case 'd':
+ debug = 1;
+ break;
case 'h':
default:
usage();
perror("Can't start daemon");
exit(1);
}
- } else
- log_option |= LOG_PERROR;
-
- openlog("connmand", log_option, LOG_DAEMON);
+ }
mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
compat = 0;
}
+ __connman_log_init(detach, debug);
+
__connman_agent_init(conn);
__connman_manager_init(conn, compat);
__connman_agent_cleanup();
+ __connman_log_cleanup();
+
g_dbus_cleanup_connection(conn);
g_main_loop_unref(main_loop);
rmdir(STATEDIR);
- closelog();
-
return 0;
}