1 /* 2 * Copyright (C) 2006 Tresys Technology, LLC 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 #ifndef _SEPOL_INTERNAL_DEBUG_H_ 20 #define _SEPOL_INTERNAL_DEBUG_H_ 21 22 #include <stdio.h> 23 #include <sepol/debug.h> 24 #include "handle.h" 25 26 #define STATUS_SUCCESS 0 27 #define STATUS_ERR -1 28 #define STATUS_NODATA 1 29 30 /* FIXME: this needs to become a real function. Declaring variables 31 * in a macro is _evil_ as it can shadow other variables in local scope. 32 * The variable h has been renamed to _sepol_h to reduce this chance, but 33 * it is still wrong. 34 */ 35 #define msg_write(handle_arg, level_arg, \ 36 channel_arg, func_arg, ...) do { \ 37 sepol_handle_t *_sepol_h = (handle_arg) ?: &sepol_compat_handle; \ 38 if (_sepol_h->msg_callback) { \ 39 _sepol_h->msg_fname = func_arg; \ 40 _sepol_h->msg_channel = channel_arg; \ 41 _sepol_h->msg_level = level_arg; \ 42 \ 43 _sepol_h->msg_callback( \ 44 _sepol_h->msg_callback_arg, \ 45 _sepol_h, __VA_ARGS__); \ 46 } \ 47 } while(0) 48 49 #define ERR(handle, ...) \ 50 msg_write(handle, SEPOL_MSG_ERR, "libsepol", \ 51 __FUNCTION__, __VA_ARGS__) 52 53 #define INFO(handle, ...) \ 54 msg_write(handle, SEPOL_MSG_INFO, "libsepol", \ 55 __FUNCTION__, __VA_ARGS__) 56 57 #define WARN(handle, ...) \ 58 msg_write(handle, SEPOL_MSG_WARN, "libsepol", \ 59 __FUNCTION__, __VA_ARGS__) 60 61 #ifdef __GNUC__ 62 __attribute__ ((format(printf, 3, 4))) 63 #endif 64 extern void sepol_msg_default_handler(void *varg, 65 sepol_handle_t * msg, 66 const char *fmt, ...); 67 68 extern struct sepol_handle sepol_compat_handle; 69 70 #endif 71