xref: /aosp_15_r20/external/selinux/libsemanage/src/debug.h (revision 2d543d20722ada2425b5bdab9d0d1d29470e7bba)
1 /* Author: Joshua Brindle <[email protected]>
2  *         Jason Tang     <[email protected]>
3  *         Ivan Gyurdiev  <[email protected]>
4  *
5  * Copyright (C) 2005 Tresys Technology, LLC
6  * Copyright (C) 2005 Red Hat Inc.
7  *
8  *  This library is free software; you can redistribute it and/or
9  *  modify it under the terms of the GNU Lesser General Public
10  *  License as published by the Free Software Foundation; either
11  *  version 2.1 of the License, or (at your option) any later version.
12  *
13  *  This library is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public
19  *  License along with this library; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22 
23 #ifndef _SEMANAGE_INTERNAL_DEBUG_H_
24 #define _SEMANAGE_INTERNAL_DEBUG_H_
25 
26 #include <stdio.h>
27 #include <semanage/debug.h>
28 #include <sepol/debug.h>
29 #include "handle.h"
30 
31 #define STATUS_SUCCESS 0
32 #define STATUS_ERR -1
33 #define STATUS_NODATA 1
34 
35 #define msg_write(handle_arg, level_arg,                   \
36 	          channel_arg, func_arg, ...) do {         \
37 	                                                   \
38         if ((handle_arg)->msg_callback) {                  \
39                 (handle_arg)->msg_fname = func_arg;        \
40                 (handle_arg)->msg_channel = channel_arg;   \
41                 (handle_arg)->msg_level = level_arg;       \
42                                                            \
43                 (handle_arg)->msg_callback(                \
44                         (handle_arg)->msg_callback_arg,    \
45                         handle_arg, __VA_ARGS__);          \
46         }                                                  \
47 } while(0)
48 
49 #define ERR(handle, ...) \
50 	msg_write(handle, SEMANAGE_MSG_ERR, "libsemanage", \
51 	__FUNCTION__, __VA_ARGS__)
52 
53 #define INFO(handle, ...) \
54 	msg_write(handle, SEMANAGE_MSG_INFO, "libsemanage", \
55 	__FUNCTION__, __VA_ARGS__)
56 
57 #define WARN(handle, ...) \
58 	msg_write(handle, SEMANAGE_MSG_WARN, "libsemanage", \
59 	__FUNCTION__, __VA_ARGS__)
60 
61 #ifdef __GNUC__
62 __attribute__ ((format(printf, 3, 4)))
63 #endif
64 extern void semanage_msg_default_handler(void *varg,
65 						semanage_handle_t * handle,
66 						const char *fmt, ...);
67 
68 #ifdef __GNUC__
69 __attribute__ ((format(printf, 3, 4)))
70 #endif
71 extern void semanage_msg_relay_handler(void *varg,
72 					      sepol_handle_t * handle,
73 					      const char *fmt, ...);
74 
75 #endif
76