1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
/*
* Copyright © Jan Engelhardt, 2006 - 2009
*
* This file is part of pam_mount; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*/
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdbool.h>
#include <syslog.h>
#include "libcryptmount.h"
#include "pam_mount.h"
static unsigned int ehd_log_ft[__EHD_LOGFT_MAX];
EXPORT_SYMBOL int ehd_logctl(enum ehd_log_feature ft, ...)
{
va_list ap;
va_start(ap, ft);
int a = va_arg(ap, int);
if (a == EHD_LOG_GET) {
return ehd_log_ft[ft];
} else if (a == EHD_LOG_SET) {
++ehd_log_ft[ft];
} else if (a == EHD_LOG_UNSET) {
if (ehd_log_ft[ft] == 0)
fprintf(stderr, "%s: feature %u is already zero\n",
__func__, ft);
else
--ehd_log_ft[ft];
}
return 1;
}
/**
* ehd_err - log an error/warning
* @format: printf(3)-style format specifier
*/
EXPORT_SYMBOL int ehd_err(const char *format, ...)
{
va_list args, arg2;
int ret = 0;
assert(format != NULL);
if (!ehd_log_ft[EHD_LOGFT_NOSYSLOG]) {
va_start(args, format);
va_copy(arg2, args);
vsyslog(LOG_AUTH | LOG_ERR, format, arg2);
va_end(arg2);
}
ret = vfprintf(stderr, format, args);
va_end(args);
return ret;
}
/**
* ehd_dbg - log informational messages
* @format: printf(3)-style format specifier
*
* If debugging is turned on, the message is logged to syslog and %stderr.
* Use this for debugging messages.
*
* Do not call this function directly; use the w4rn() macro instead, so that
* file name and line number show up.
*/
EXPORT_SYMBOL int ehd_dbg(const char *format, ...)
{
va_list args, arg2;
int ret = 0;
assert(format != NULL);
if (!ehd_log_ft[EHD_LOGFT_DEBUG])
return 0;
va_start(args, format);
if (!ehd_log_ft[EHD_LOGFT_NOSYSLOG]) {
va_copy(arg2, args);
vsyslog(LOG_AUTH | LOG_ERR, format, arg2);
va_end(arg2);
}
ret = vfprintf(stderr, format, args);
va_end(args);
return ret;
}
|