Add the PID to the output on Win32.
[openssl.git] / crypto / bio / bss_log.c
index cb2779855b58f888e8c91485690d99ba4c2a031a..497c8aee615b5a5efa9f52d7cb1cf0506414b5df 100644 (file)
 
 */
 
+
 #include <stdio.h>
 #include <errno.h>
 
 #ifndef WIN32
+#ifdef __ultrix
+#include <sys/syslog.h>
+#else
 #include <syslog.h>
 #endif
+#else
+#include <process.h>
+#endif
 
 #include "cryptlib.h"
-#include "buffer.h"
-#include "err.h"
+#include <openssl/buffer.h>
+#include <openssl/err.h>
+#ifndef NO_SYSLOG
+
 
-#ifndef NOPROTO
 static int MS_CALLBACK slg_write(BIO *h,char *buf,int num);
 static int MS_CALLBACK slg_puts(BIO *h,char *str);
 static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2);
 static int MS_CALLBACK slg_new(BIO *h);
 static int MS_CALLBACK slg_free(BIO *data);
-#else
-static int MS_CALLBACK slg_write();
-static int MS_CALLBACK slg_puts();
-static long MS_CALLBACK slg_ctrl();
-static int MS_CALLBACK slg_new();
-static int MS_CALLBACK slg_free();
-#endif
-
-static int xopenlog(BIO* bp, char* name, int level);
+static int xopenlog(BIO* bp, const char* name, int level);
 static int xcloselog(BIO* bp);
 
 static BIO_METHOD methods_slg=
@@ -102,13 +102,12 @@ static BIO_METHOD methods_slg=
        slg_free,
        };
 
-BIO_METHOD *BIO_s_log()
+BIO_METHOD *BIO_s_log(void)
        {
        return(&methods_slg);
        }
 
-static int MS_CALLBACK slg_new(bi)
-BIO *bi;
+static int MS_CALLBACK slg_new(BIO *bi)
        {
        bi->init=1;
        bi->num=0;
@@ -121,25 +120,24 @@ BIO *bi;
        return(1);
        }
 
-static int MS_CALLBACK slg_free(a)
-BIO *a;
+static int MS_CALLBACK slg_free(BIO *a)
        {
        if (a == NULL) return(0);
        xcloselog(a);
        return(1);
        }
        
-static int MS_CALLBACK slg_write(b,in,inl)
-BIO *b;
-char *in;
-int inl;
+static int MS_CALLBACK slg_write(BIO *b, char *in, int inl)
        {
        int ret= inl;
        char* buf= in;
        char* pp;
 #if defined(WIN32)
-       LPTSTR lpszStrings[1];
+       LPTSTR lpszStrings[2];
        WORD evtype= EVENTLOG_ERROR_TYPE;
+       int pid = _getpid();
+       char pidbuf[20];
+       int pidbufl;
 #else
        int priority;
 #endif
@@ -163,10 +161,13 @@ int inl;
                evtype= EVENTLOG_ERROR_TYPE;
                pp= buf;
        }
-       lpszStrings[0]= pp;
+
+       sprintf(pidbuf, "[%d] ", pid);
+       lpszStrings[0] = pidbuf;
+       lpszStrings[1] = pp;
 
        if(b->ptr)
-               ReportEvent(b->ptr, evtype, 0, 1024, NULL, 1, 0,
+               ReportEvent(b->ptr, evtype, 0, 1024, NULL, 2, 0,
                                lpszStrings, NULL);
 #else
        if(strncmp(buf, "ERR ", 4) == 0){
@@ -189,11 +190,7 @@ int inl;
        return(ret);
        }
 
-static long MS_CALLBACK slg_ctrl(b,cmd,num,ptr)
-BIO *b;
-int cmd;
-long num;
-char *ptr;
+static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr)
        {
        switch (cmd)
                {
@@ -207,9 +204,7 @@ char *ptr;
        return(0);
        }
 
-static int MS_CALLBACK slg_puts(bp,str)
-BIO *bp;
-char *str;
+static int MS_CALLBACK slg_puts(BIO *bp, char *str)
        {
        int n,ret;
 
@@ -218,7 +213,7 @@ char *str;
        return(ret);
        }
 
-static int xopenlog(BIO* bp, char* name, int level)
+static int xopenlog(BIO* bp, const char* name, int level)
 {
 #if defined(WIN32)
        if((bp->ptr= (char *)RegisterEventSource(NULL, name)) == NULL){
@@ -242,3 +237,4 @@ static int xcloselog(BIO* bp)
        return(1);
 }
 
+#endif