source: roaraudio/libroar/trap.c @ 5921:2fa512f52879

Last change on this file since 5921:2fa512f52879 was 5823:f9f70dbaa376, checked in by phi, 11 years ago

updated copyright

File size: 4.1 KB
Line 
1//*.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2013
5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "libroar.h"
37
38static struct _group {
39 unsigned int id;
40 const char * name;
41} _libroar_trap_groups[] = {
42 {ROAR_TRAP_GROUP_LIBROAR, "libroar"},
43 {ROAR_TRAP_GROUP_ROARD,   "roard"},
44 {ROAR_TRAP_GROUP_APP,     "app"},
45 {ROAR_TRAP_GROUP_LIB,     "lib"},
46 {ROAR_TRAP_GROUP_NETWORK, "network"},
47 {ROAR_TRAP_GROUP_PROTO,   "proto"},
48 {-1, NULL}
49};
50
51unsigned int roar_trap_register_group(const char * name) {
52 static unsigned int state = ROAR_TRAP_GROUP_USER_MIN;
53 unsigned int ret;
54 size_t i;
55
56 for (i = 0;
57      i < (sizeof(_libroar_trap_groups)/sizeof(*_libroar_trap_groups)) && _libroar_trap_groups[i].id != (unsigned int)-1;
58      i++);
59 if ( i == (sizeof(_libroar_trap_groups)/sizeof(*_libroar_trap_groups)) )
60  return -1;
61
62 ret = state++;
63 _libroar_trap_groups[i].id   = ret;
64 _libroar_trap_groups[i].name = name;
65
66 return ret;
67}
68
69const char * roar_trap_get_groupname(const unsigned int group) {
70 size_t i;
71
72 for (i = 0;
73      i < (sizeof(_libroar_trap_groups)/sizeof(*_libroar_trap_groups)) && _libroar_trap_groups[i].id != (unsigned int)-1;
74      i++) {
75  if ( _libroar_trap_groups[i].id == group )
76   return _libroar_trap_groups[i].name;
77 }
78
79 return NULL;
80}
81
82unsigned int roar_trap_get_groupid(const char * name) {
83 size_t i;
84
85 for (i = 0;
86      i < (sizeof(_libroar_trap_groups)/sizeof(*_libroar_trap_groups)) && _libroar_trap_groups[i].id != (unsigned int)-1;
87      i++) {
88  if ( !strcasecmp(_libroar_trap_groups[i].name, name) )
89   return _libroar_trap_groups[i].id;
90 }
91
92 return -1;
93}
94
95void roar_strap_impl(const unsigned int group, const char * name, unsigned int line, const char * file, const char * prefix) {
96#ifdef ROAR_SUPPORT_TRAP
97 struct roar_libroar_config * config = roar_libroar_get_config();
98 enum roar_trap_policy policy = config->trap_policy;
99
100 // need to search for the correct policy for this specific trap.
101
102 switch (policy) {
103  case ROAR_TRAP_IGNORE:
104    return;
105   break;
106  case ROAR_TRAP_WARN:
107    ROAR_DBG("roar_strap_impl(group=%u(\"%s\"), name='%s', line=%u, file='%s') = (void)",
108               group, roar_trap_get_groupname(group), name, line, file);
109    roar_debug_msg(ROAR_DEBUG_TYPE_WARNING, line, file, prefix, "Trap %s of group %s.",
110                   name, roar_trap_get_groupname(group));
111   break;
112  case ROAR_TRAP_ABORT:
113    abort();
114   break;
115#ifdef SIGKILL
116  case ROAR_TRAP_KILL:
117    raise(SIGKILL);
118   break;
119#endif
120#ifdef SIGSTOP
121  case ROAR_TRAP_STOP:
122    raise(SIGSTOP);
123   break;
124#endif
125  case ROAR_TRAP_DIE:
126    roar_debug_msg(ROAR_DEBUG_TYPE_WARNING, line, file, prefix, "Trap %s of group %s, terminating program.",
127                   name, roar_trap_get_groupname(group));
128#ifdef SIGKILL
129    raise(SIGKILL);
130#else
131    abort();
132#endif
133   break;
134 }
135#else
136 (void)group, (void)name, (void)line, (void)file, (void)prefix;
137 return;
138#endif
139}
140
141//ll
Note: See TracBrowser for help on using the repository browser.