5 * Copyright (C) 2007-2013 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 static const char *program_exec;
38 static const char *program_path;
40 /* This makes sure we always have a __debug section. */
41 CONNMAN_DEBUG_DEFINE(dummy);
45 * @format: format string
46 * @Varargs: list of arguments
48 * Output general information
50 void connman_info(const char *format, ...)
56 vsyslog(LOG_INFO, format, ap);
63 * @format: format string
64 * @Varargs: list of arguments
66 * Output warning messages
68 void connman_warn(const char *format, ...)
74 vsyslog(LOG_WARNING, format, ap);
81 * @format: format string
82 * @varargs: list of arguments
84 * Output error messages
86 void connman_error(const char *format, ...)
92 vsyslog(LOG_ERR, format, ap);
99 * @format: format string
100 * @varargs: list of arguments
102 * Output debug message
104 void connman_debug(const char *format, ...)
108 va_start(ap, format);
110 vsyslog(LOG_DEBUG, format, ap);
115 static void signal_handler(int signo)
117 connman_error("Aborting (signal %d) [%s]", signo, program_exec);
119 print_backtrace(program_path, program_exec, 2);
124 static void signal_setup(sighandler_t handler)
130 sa.sa_handler = handler;
133 sigaction(SIGBUS, &sa, NULL);
134 sigaction(SIGILL, &sa, NULL);
135 sigaction(SIGFPE, &sa, NULL);
136 sigaction(SIGSEGV, &sa, NULL);
137 sigaction(SIGABRT, &sa, NULL);
138 sigaction(SIGPIPE, &sa, NULL);
141 extern struct connman_debug_desc __start___debug[];
142 extern struct connman_debug_desc __stop___debug[];
144 static gchar **enabled = NULL;
146 static bool is_enabled(struct connman_debug_desc *desc)
153 for (i = 0; enabled[i]; i++) {
154 if (desc->name && g_pattern_match_simple(enabled[i],
157 if (desc->file && g_pattern_match_simple(enabled[i],
165 void __connman_log_enable(struct connman_debug_desc *start,
166 struct connman_debug_desc *stop)
168 struct connman_debug_desc *desc;
169 const char *name = NULL, *file = NULL;
174 for (desc = start; desc < stop; desc++) {
175 if (desc->flags & CONNMAN_DEBUG_FLAG_ALIAS) {
182 if (g_strcmp0(desc->file, file) == 0) {
189 if (is_enabled(desc))
190 desc->flags |= CONNMAN_DEBUG_FLAG_PRINT;
194 int __connman_log_init(const char *program, const char *debug,
195 gboolean detach, gboolean backtrace,
196 const char *program_name, const char *program_version)
198 static char path[PATH_MAX];
199 int option = LOG_NDELAY | LOG_PID;
201 program_exec = program;
202 program_path = getcwd(path, sizeof(path));
205 enabled = g_strsplit_set(debug, ":, ", 0);
207 __connman_log_enable(__start___debug, __stop___debug);
210 option |= LOG_PERROR;
213 signal_setup(signal_handler);
215 openlog(basename(program), option, LOG_DAEMON);
217 syslog(LOG_INFO, "%s version %s", program_name, program_version);
222 void __connman_log_cleanup(gboolean backtrace)
224 syslog(LOG_INFO, "Exit");
229 signal_setup(SIG_DFL);