5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
37 * @format: format string
38 * @Varargs: list of arguments
40 * Output general information
42 void connman_info(const char *format, ...)
48 vsyslog(LOG_INFO, format, ap);
55 * @format: format string
56 * @Varargs: list of arguments
58 * Output warning messages
60 void connman_warn(const char *format, ...)
66 vsyslog(LOG_WARNING, format, ap);
73 * @format: format string
74 * @varargs: list of arguments
76 * Output error messages
78 void connman_error(const char *format, ...)
84 vsyslog(LOG_ERR, format, ap);
91 * @format: format string
92 * @varargs: list of arguments
94 * Output debug message
96 void connman_debug(const char *format, ...)
100 va_start(ap, format);
102 vsyslog(LOG_DEBUG, format, ap);
107 static void signal_handler(int signo)
114 n_ptrs = backtrace(frames, G_N_ELEMENTS(frames));
115 symbols = backtrace_symbols(frames, n_ptrs);
116 if (symbols == NULL) {
117 connman_error("No backtrace symbols");
121 connman_error("Aborting (signal %d)", signo);
122 connman_error("++++++++ backtrace ++++++++");
124 for (i = 1; i < n_ptrs; i++)
125 connman_error("[%d]: %s", i - 1, symbols[i]);
127 connman_error("+++++++++++++++++++++++++++");
133 static void signal_setup(sighandler_t handler)
139 sa.sa_handler = handler;
142 sigaction(SIGBUS, &sa, NULL);
143 sigaction(SIGILL, &sa, NULL);
144 sigaction(SIGFPE, &sa, NULL);
145 sigaction(SIGSEGV, &sa, NULL);
146 sigaction(SIGABRT, &sa, NULL);
147 sigaction(SIGPIPE, &sa, NULL);
150 extern struct connman_debug_desc __start___debug[];
151 extern struct connman_debug_desc __stop___debug[];
153 void __connman_debug_list_available(DBusMessageIter *iter, void *user_data)
155 struct connman_debug_desc *desc;
157 for (desc = __start___debug; desc < __stop___debug; desc++) {
158 if ((desc->flags & CONNMAN_DEBUG_FLAG_ALIAS) &&
160 dbus_message_iter_append_basic(iter,
161 DBUS_TYPE_STRING, &desc->name);
165 static gchar **enabled = NULL;
167 void __connman_debug_list_enabled(DBusMessageIter *iter, void *user_data)
174 for (i = 0; enabled[i] != NULL; i++)
175 dbus_message_iter_append_basic(iter,
176 DBUS_TYPE_STRING, &enabled[i]);
179 static connman_bool_t is_enabled(struct connman_debug_desc *desc)
186 for (i = 0; enabled[i] != NULL; i++) {
187 if (desc->name != NULL && g_pattern_match_simple(enabled[i],
190 if (desc->file != NULL && g_pattern_match_simple(enabled[i],
198 int __connman_log_init(const char *debug, connman_bool_t detach)
200 int option = LOG_NDELAY | LOG_PID;
201 struct connman_debug_desc *desc;
202 const char *name = NULL, *file = NULL;
205 enabled = g_strsplit_set(debug, ":, ", 0);
207 for (desc = __start___debug; desc < __stop___debug; desc++) {
208 if (desc->flags & CONNMAN_DEBUG_FLAG_ALIAS) {
214 if (file != NULL || name != NULL) {
215 if (g_strcmp0(desc->file, file) == 0) {
216 if (desc->name == NULL)
222 if (is_enabled(desc) == TRUE)
223 desc->flags |= CONNMAN_DEBUG_FLAG_PRINT;
227 option |= LOG_PERROR;
229 signal_setup(signal_handler);
231 openlog("connmand", option, LOG_DAEMON);
233 syslog(LOG_INFO, "Connection Manager version %s", VERSION);
238 void __connman_log_cleanup(void)
240 syslog(LOG_INFO, "Exit");
244 signal_setup(SIG_DFL);