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;
42 * @format: format string
43 * @Varargs: list of arguments
45 * Output general information
47 void connman_info(const char *format, ...)
53 vsyslog(LOG_INFO, format, ap);
60 * @format: format string
61 * @Varargs: list of arguments
63 * Output warning messages
65 void connman_warn(const char *format, ...)
71 vsyslog(LOG_WARNING, format, ap);
78 * @format: format string
79 * @varargs: list of arguments
81 * Output error messages
83 void connman_error(const char *format, ...)
89 vsyslog(LOG_ERR, format, ap);
96 * @format: format string
97 * @varargs: list of arguments
99 * Output debug message
101 void connman_debug(const char *format, ...)
105 va_start(ap, format);
107 vsyslog(LOG_DEBUG, format, ap);
112 static void signal_handler(int signo)
114 connman_error("Aborting (signal %d) [%s]", signo, program_exec);
116 print_backtrace(program_path, program_exec, 2);
121 static void signal_setup(sighandler_t handler)
127 sa.sa_handler = handler;
130 sigaction(SIGBUS, &sa, NULL);
131 sigaction(SIGILL, &sa, NULL);
132 sigaction(SIGFPE, &sa, NULL);
133 sigaction(SIGSEGV, &sa, NULL);
134 sigaction(SIGABRT, &sa, NULL);
135 sigaction(SIGPIPE, &sa, NULL);
138 extern struct connman_debug_desc __start___debug[];
139 extern struct connman_debug_desc __stop___debug[];
141 static gchar **enabled = NULL;
143 static bool is_enabled(struct connman_debug_desc *desc)
150 for (i = 0; enabled[i]; i++) {
151 if (desc->name && g_pattern_match_simple(enabled[i],
154 if (desc->file && g_pattern_match_simple(enabled[i],
162 void __connman_log_enable(struct connman_debug_desc *start,
163 struct connman_debug_desc *stop)
165 struct connman_debug_desc *desc;
166 const char *name = NULL, *file = NULL;
171 for (desc = start; desc < stop; desc++) {
172 if (desc->flags & CONNMAN_DEBUG_FLAG_ALIAS) {
179 if (g_strcmp0(desc->file, file) == 0) {
186 if (is_enabled(desc))
187 desc->flags |= CONNMAN_DEBUG_FLAG_PRINT;
191 int __connman_log_init(const char *program, const char *debug,
192 gboolean detach, gboolean backtrace,
193 const char *program_name, const char *program_version)
195 static char path[PATH_MAX];
196 int option = LOG_NDELAY | LOG_PID;
198 program_exec = program;
199 program_path = getcwd(path, sizeof(path));
202 enabled = g_strsplit_set(debug, ":, ", 0);
204 __connman_log_enable(__start___debug, __stop___debug);
207 option |= LOG_PERROR;
210 signal_setup(signal_handler);
212 openlog(basename(program), option, LOG_DAEMON);
214 syslog(LOG_INFO, "%s version %s", program_name, program_version);
219 void __connman_log_cleanup(gboolean backtrace)
221 syslog(LOG_INFO, "Exit");
226 signal_setup(SIG_DFL);