⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 log.c

📁 IBM的Linux上的PKCS#11实现
💻 C
📖 第 1 页 / 共 2 页
字号:
             IBM is the initial Agreement Steward. IBM may assign the             responsibility to serve as the Agreement Steward to a             suitable separate entity. Each new version of the             Agreement will be given a distinguishing version number.             The Program (including Contributions) may always be             distributed subject to the version of the Agreement under             which it was received. In addition, after a new version of             the Agreement is published, Contributor may elect to             distribute the Program (including its Contributions) under             the new version. Except as expressly stated in Sections             2(a) and 2(b) above, Recipient receives no rights or             licenses to the intellectual property of any Contributor             under this Agreement, whether expressly, by implication,             estoppel or otherwise. All rights in the Program not             expressly granted under this Agreement are reserved.             This Agreement is governed by the laws of the State of New             York and the intellectual property laws of the United             States of America. No party to this Agreement will bring a             legal action under this Agreement more than one year after             the cause of action arose. Each party waives its rights to             a jury trial in any resulting litigation. *//* (C) COPYRIGHT International Business Machines Corp. 2001,2002          */#include <pthread.h>#include <stdlib.h>#include <stdio.h>#include <dlfcn.h>#include <errno.h>#include <sys/syslog.h>#if defined(AIX)#include <sys/mode.h>#endif#include <sys/ipc.h>#include <stdarg.h>#include <pthread.h>#include <pkcs11types.h>#include "defs.h"#include "host_defs.h"#include "tok_spec_struct.h"extern token_spec_t token_specific;#include "tokenlocal.h"#include "msg.h"  // HACK  #if defined(AIX)struct syslog_data log_data = SYSLOG_DATA_INIT;#endifvoid stlogit(char *, ...);//extern char **err_msg;#include <sys/types.h>#include <sys/stat.h>#if (LINUX)#if 0extern FILE  *debugfile;char  lfname[1024];#elseextern int  debugfile;#endifpthread_mutex_t  lmtx=PTHREAD_MUTEX_INITIALIZER;#endifstatic int enabled=0;static int logging=0;static int env_log_check=0; // Logging types.  Ultimately this will allow// us to log to different log files.  The logger will also// handle keeping the files to a decent size.// Much work needs to be done on this capability... // Other logging types need to be implementedvoid stloginit(){   char *logval;   if (!env_log_check){      logval = getenv("PKCS_ERROR_LOG");      env_log_check = 1;      if (logval != NULL)         logging = 1;      else         logging = 0;   }   if (!enabled && logging){      enabled=1;#if defined(AIX)      openlog_r(DBGTAG,LOG_PID|LOG_NDELAY,LOG_LOCAL6,&log_data);      setlogmask_r(LOG_UPTO(LOG_DEBUG),&log_data);#elif (LINUX)      openlog(DBGTAG,LOG_PID|LOG_NDELAY,LOG_LOCAL6);      setlogmask(LOG_UPTO(LOG_DEBUG));#ifdef DEBUG      debugfile = 1;#else      debugfile = 0;#endif#if 0      sprintf(lfname,"/etc/pkcs11/%s.%d",DBGTAG,getpid());      debugfile = fopen(lfname,"w+");      if (debugfile) {         fchmod(fileno(debugfile),         S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);      }#endif      stlogit("Logg initialized");#endif    }}voidstlogterm(){  enabled = 0;}voidstlogit2(int type,char *fmt, ...){      int n;      va_list pvar;      char *env;      char buffer[4096*4];      char buf1[4096];   if (!enabled)  stloginit();   if ( enabled && debugfile){//         sprintf(buf1,"Tid %d",pthread_self());//         syslog_r(LOG_DEBUG,&log_data,buf1);         va_start(pvar, fmt);         vsprintf(buffer,fmt,pvar);         va_end(pvar);#if defined(AIX)         syslog_r(LOG_DEBUG,&log_data,buffer);#elif (LINUX)         pthread_mutex_lock(&lmtx);         syslog(LOG_DEBUG,buffer);         pthread_mutex_unlock(&lmtx);#if 0	if (debugfile) {         pthread_mutex_lock(&lmtx);         fprintf(debugfile,"[%d]:%s\n",getpid(),buffer);          fflush(debugfile);         pthread_mutex_unlock(&lmtx); 	}#endif#endif   }}voidstlogit(char *fmt, ...){      int n;      va_list pvar;      char *env;      char buffer[4096*4];   if (!enabled)  stloginit();   if ( enabled && debugfile){         va_start(pvar, fmt);         vsprintf(buffer,fmt,pvar);         va_end(pvar);#if defined(AIX)         syslog_r(LOG_DEBUG,&log_data,buffer);#else         pthread_mutex_lock(&lmtx);         syslog(LOG_DEBUG,buffer);         pthread_mutex_unlock(&lmtx);#if 0	if (debugfile) {         pthread_mutex_lock(&lmtx);         fprintf(debugfile,"[%d]:%s\n",getpid(),buffer);          fflush(debugfile);         pthread_mutex_unlock(&lmtx); 	}#endif#endif   }}/*voidst_err_log(char *fmt, ...){      int n;      va_list pvar;      char *env;      char buffer[4096*4];   if (!enabled)  stloginit();   if ( enabled ){         va_start(pvar, fmt);         vsprintf(buffer,fmt,pvar);         va_end(pvar);#if defined(AIX)         syslog_r(LOG_ERR,&log_data,buffer);#else         pthread_mutex_lock(&lmtx);         syslog(LOG_ERR,buffer);         pthread_mutex_unlock(&lmtx);#endif   }}*/voidst_err_log(int num, ...){      int n;      va_list pvar;      char *env;      char buffer[4096*4];   if (!enabled && logging)  stloginit();   if ( enabled ){         va_start(pvar,num);         vsprintf(buffer,err_msg[num].msg,pvar);         va_end(pvar);#if defined(AIX)         syslog_r(LOG_ERR,&log_data,buffer);#else         pthread_mutex_lock(&lmtx);         syslog(LOG_ERR,buffer);         pthread_mutex_unlock(&lmtx);#endif   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -