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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>LibU: syslog.c Source File</title>
<link href="kl.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">src</a></div>
<h1>syslog.c</h1><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#include "libu_conf.h"</span>
00002 <span class="preprocessor">#include <u/os.h></span>
00003 <span class="preprocessor">#ifndef HAVE_SYSLOG</span>
00004 <span class="preprocessor"></span>
00005 <span class="preprocessor">#ifdef OS_WIN</span>
00006 <span class="preprocessor"></span><span class="preprocessor">#include <windows.h></span>
00007 <span class="preprocessor">#include <io.h></span>
00008 <span class="preprocessor">#include <sys/locking.h></span>
00009 <span class="preprocessor">#include <errno.h></span>
00010 <span class="preprocessor">#include <stdio.h></span>
00011 <span class="preprocessor">#include <stdlib.h></span>
00012
00013 <span class="keywordtype">void</span> vsyslog(<span class="keywordtype">int</span> priority, <span class="keyword">const</span> <span class="keywordtype">char</span> *fmt, va_list ap)
00014 {
00015 <span class="preprocessor"> #define KLONED_WIN_LOGFILE "kloned.log"</span>
00016 <span class="preprocessor"></span> <span class="keyword">enum</span> { BUFSZ = 1024 };
00017 <span class="keyword">static</span> FILE *df = NULL, *lock = NULL;
00018 <span class="keywordtype">char</span> buf[BUFSZ];
00019 <span class="keywordtype">int</span> i;
00020
00021 <span class="comment">/* first time open the log file and the lock file */</span>
00022 <span class="keywordflow">if</span>(df == NULL)
00023 {
00024 df = fopen(KLONED_WIN_LOGFILE, <span class="stringliteral">"a+"</span>);
00025 lock = fopen(KLONED_WIN_LOGFILE <span class="stringliteral">".lock"</span>, <span class="stringliteral">"a+"</span>);
00026 <span class="keywordflow">if</span>(df == NULL || lock == NULL)
00027 exit(1);
00028 }
00029
00030 vsnprintf(buf, BUFSZ, fmt, ap);
00031
00032 <span class="comment">/* get the lock (i.e. lock the first byte of the lock file) */</span>
00033 <span class="keywordflow">for</span>(i = 0;
00034 _locking(fileno(lock), _LK_NBLCK, 1) == EACCES && i < 10; ++i)
00035 Sleep(100);
00036
00037 <span class="keywordflow">if</span>(i < 10)
00038 { <span class="comment">/* we have the lock, write the log msg */</span>
00039 fprintf(df, <span class="stringliteral">"%s\n"</span>, buf);
00040 fflush(df);
00041 <span class="comment">/* unlock the file */</span>
00042 _locking(fileno(lock), _LK_UNLCK, 1);
00043 } <span class="keywordflow">else</span> {
00044 <span class="comment">/* file is still locked after 10 tries, give up */</span>
00045 ;
00046 }
00047
00048 <span class="keywordflow">return</span>;
00049 }
00050
00051 <span class="keywordtype">void</span> syslog(<span class="keywordtype">int</span> priority, <span class="keyword">const</span> <span class="keywordtype">char</span> *fmt, ...)
00052 {
00053 va_list ap;
00054
00055 va_start(ap, fmt); <span class="comment">/* init variable list arguments */</span>
00056
00057 vsyslog(priority, fmt, ap);
00058
00059 va_end(ap);
00060 }
00061
00062 <span class="preprocessor">#endif </span><span class="comment">/* ifdef OS_WIN */</span>
00063
00064 <span class="preprocessor">#else </span><span class="comment">/* ifndef HAVE_SYSLOG */</span>
00065 <span class="preprocessor">#include <syslog.h></span>
00066 <span class="preprocessor">#include <stdarg.h></span>
00067 <span class="keywordtype">void</span> syslog(<span class="keywordtype">int</span> priority, <span class="keyword">const</span> <span class="keywordtype">char</span> *fmt, ...);
00068 <span class="keywordtype">void</span> vsyslog(<span class="keywordtype">int</span> priority, <span class="keyword">const</span> <span class="keywordtype">char</span> *fmt, va_list args);
00069 <span class="preprocessor">#endif </span>
</pre></div><hr>
<div>
<div style="text-align:left">
<a href="http://www.koanlogic.com/kl/cont/gb/html/products.html">←Products</a>
</div>
<div style="text-align:center;">
© 2005-2006 - <a href="http://www.koanlogic.com">KoanLogic S.r.l.</a> - All rights reserved
</div>
</div>
</body>
</html>
|