am f10492d8: am 066cde92: am 223e0798: Merge "Enable building init with -Wall -Werror."

* commit 'f10492d8c0c907fad6f87c871fec6b2fac41a02c':
  Enable building init with -Wall -Werror.
This commit is contained in:
Nick Kralevich 2014-02-19 19:23:13 +00:00 committed by Android Git Automerger
commit 202be73b62
3 changed files with 46 additions and 11 deletions

View file

@ -18,6 +18,7 @@
#define _CUTILS_KLOG_H_
#include <sys/cdefs.h>
#include <stdarg.h>
__BEGIN_DECLS
@ -26,14 +27,21 @@ void klog_set_level(int level);
/* TODO: void klog_close(void); - and make klog_fd users thread safe. */
void klog_write(int level, const char *fmt, ...)
__attribute__ ((format(printf, 2, 3)));
void klog_vwrite(int level, const char *fmt, va_list ap);
__END_DECLS
#define KLOG_ERROR(tag,x...) klog_write(3, "<3>" tag ": " x)
#define KLOG_WARNING(tag,x...) klog_write(4, "<4>" tag ": " x)
#define KLOG_NOTICE(tag,x...) klog_write(5, "<5>" tag ": " x)
#define KLOG_INFO(tag,x...) klog_write(6, "<6>" tag ": " x)
#define KLOG_DEBUG(tag,x...) klog_write(7, "<7>" tag ": " x)
#define KLOG_ERROR_LEVEL 3
#define KLOG_WARNING_LEVEL 4
#define KLOG_NOTICE_LEVEL 5
#define KLOG_INFO_LEVEL 6
#define KLOG_DEBUG_LEVEL 7
#define KLOG_ERROR(tag,x...) klog_write(KLOG_ERROR_LEVEL, "<3>" tag ": " x)
#define KLOG_WARNING(tag,x...) klog_write(KLOG_WARNING_LEVEL, "<4>" tag ": " x)
#define KLOG_NOTICE(tag,x...) klog_write(KLOG_NOTICE_LEVEL, "<5>" tag ": " x)
#define KLOG_INFO(tag,x...) klog_write(KLOG_INFO_LEVEL, "<6>" tag ": " x)
#define KLOG_DEBUG(tag,x...) klog_write(KLOG_DEBUG_LEVEL, "<7>" tag ": " x)
#define KLOG_DEFAULT_LEVEL 3 /* messages <= this level are logged */

View file

@ -933,12 +933,33 @@ int selinux_reload_policy(void)
return 0;
}
int audit_callback(void *data, security_class_t cls, char *buf, size_t len)
static int audit_callback(void *data, security_class_t cls __attribute__((unused)), char *buf, size_t len)
{
snprintf(buf, len, "property=%s", !data ? "NULL" : (char *)data);
return 0;
}
static int log_callback(int type, const char *fmt, ...)
{
int level;
va_list ap;
switch (type) {
case SELINUX_WARNING:
level = KLOG_WARNING_LEVEL;
break;
case SELINUX_INFO:
level = KLOG_INFO_LEVEL;
break;
default:
level = KLOG_ERROR_LEVEL;
break;
}
va_start(ap, fmt);
klog_vwrite(level, fmt, ap);
va_end(ap);
return 0;
}
static void selinux_initialize(void)
{
if (selinux_is_disabled()) {
@ -1012,7 +1033,7 @@ int main(int argc, char **argv)
process_kernel_cmdline();
union selinux_callback cb;
cb.func_log = klog_write;
cb.func_log = log_callback;
selinux_set_callback(SELINUX_CB_LOG, cb);
cb.func_audit = audit_callback;

View file

@ -49,18 +49,24 @@ void klog_init(void)
#define LOG_BUF_MAX 512
void klog_write(int level, const char *fmt, ...)
void klog_vwrite(int level, const char *fmt, va_list ap)
{
char buf[LOG_BUF_MAX];
va_list ap;
if (level > klog_level) return;
if (klog_fd < 0) klog_init();
if (klog_fd < 0) return;
va_start(ap, fmt);
vsnprintf(buf, LOG_BUF_MAX, fmt, ap);
buf[LOG_BUF_MAX - 1] = 0;
va_end(ap);
write(klog_fd, buf, strlen(buf));
}
void klog_write(int level, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
klog_vwrite(level, fmt, ap);
va_end(ap);
}