annotate libfdproto/log.c @ 882:ae96ae28f3dd 1.1.5

Limit python version to avoid using python3 (not compatible)
author Sebastien Decugis <sdecugis@freediameter.net>
date Sat, 03 Nov 2012 18:45:41 +0100
parents cb84f5be889d
children b839a1b1c1da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 735
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
788
cb84f5be889d Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 784
diff changeset
5 * Copyright (c) 2012, WIDE Project and NICT *
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 653
diff changeset
36 #include "fdproto-internal.h"
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 #include <stdarg.h>
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 pthread_mutex_t fd_log_lock = PTHREAD_MUTEX_INITIALIZER;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41 pthread_key_t fd_log_thname;
735
da8bfb070900 Fix the logic of local + global debug level
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
42 int fd_g_debug_lvl = INFO;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43
174
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
44 /* These may be used to pass specific debug requests via the command-line parameters */
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
45 char * fd_debug_one_function = NULL;
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
46 char * fd_debug_one_file = NULL;
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
47
183
960764fbc68f Fix compilation error
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
48 /* Useless function, only to ease setting up a breakpoint in gdb (break fd_breakhere) -- use TRACE_HERE */
960764fbc68f Fix compilation error
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
49 int fd_breaks = 0;
960764fbc68f Fix compilation error
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
50 int fd_breakhere(void) { return ++fd_breaks; }
174
2b2f78036749 Added simple command-line switch to turn on full debug for specific function or file
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
51
784
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
52 /* Allow passing of the log and debug information from base stack to extensions */
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
53 void (*fd_external_logger)( const char * format, va_list *args ) = NULL;
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
54
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
55 /* Register an dexternal call back for tracing and debug */
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
56 int fd_log_handler_register( void (*logger)(const char * format, va_list *args))
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
57 {
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
58 CHECK_PARAMS( logger );
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
59
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
60 if ( fd_external_logger != NULL )
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
61 {
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
62 return EALREADY; /* only one registeration allowed */
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
63 }
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
64 else
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
65 {
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
66 fd_external_logger = logger;
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
67 }
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
68 return 0;
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
69 }
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
70
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
71 /* Implement a simple reset function here */
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
72 int fd_log_handler_unregister ( void )
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
73 {
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
74 fd_external_logger = NULL;
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
75 return 0; /* Successfull in all cases. */
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
76 }
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
77
200
ff557d8b48d7 Fix deadlock in some circumstances
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 183
diff changeset
78 static void fd_cleanup_mutex_silent( void * mutex )
ff557d8b48d7 Fix deadlock in some circumstances
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 183
diff changeset
79 {
ff557d8b48d7 Fix deadlock in some circumstances
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 183
diff changeset
80 (void)pthread_mutex_unlock((pthread_mutex_t *)mutex);
ff557d8b48d7 Fix deadlock in some circumstances
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 183
diff changeset
81 }
ff557d8b48d7 Fix deadlock in some circumstances
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 183
diff changeset
82
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
83 /* Log a debug message */
687
026802543f57 Prepare for new message log facility
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
84 void fd_log_debug_fstr ( FILE * fstr, const char * format, ... )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
85 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86 va_list ap;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
88 (void)pthread_mutex_lock(&fd_log_lock);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
89
200
ff557d8b48d7 Fix deadlock in some circumstances
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 183
diff changeset
90 pthread_cleanup_push(fd_cleanup_mutex_silent, &fd_log_lock);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
91
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
92 va_start(ap, format);
784
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
93 if ( fd_external_logger != NULL )
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
94 {
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
95 fd_external_logger( format, &ap );
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
96 }
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
97 else
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
98 {
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
99 vfprintf( fstr ?: stdout, format, ap);
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
100 fflush(fstr ?: stdout);
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
101 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102 va_end(ap);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
103
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
104 pthread_cleanup_pop(0);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
105
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
106 (void)pthread_mutex_unlock(&fd_log_lock);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
107 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
108
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
109 /* Function to set the thread's friendly name */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
110 void fd_log_threadname ( char * name )
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
111 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
112 void * val = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
113
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
114 TRACE_ENTRY("%p(%s)", name, name?:"/");
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
115
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
116 /* First, check if a value is already assigned to the current thread */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
117 val = pthread_getspecific(fd_log_thname);
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 687
diff changeset
118 if (TRACE_BOOL(ANNOYING)) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 687
diff changeset
119 if (val) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 687
diff changeset
120 fd_log_debug("(Thread '%s' renamed to '%s')\n", (char *)val, name);
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 687
diff changeset
121 } else {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 687
diff changeset
122 fd_log_debug("(Thread %p named '%s')\n", pthread_self(), name?:"(nil)");
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 687
diff changeset
123 }
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 687
diff changeset
124 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
125 if (val != NULL) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
126 free(val);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
127 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
128
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
129 /* Now create the new string */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
130 if (name == NULL) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
131 CHECK_POSIX_DO( pthread_setspecific(fd_log_thname, NULL), /* continue */);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
132 return;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
133 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
134
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
135 CHECK_MALLOC_DO( val = strdup(name), return );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
136
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
137 CHECK_POSIX_DO( pthread_setspecific(fd_log_thname, val), /* continue */);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
138 return;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
139 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
140
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
141 /* Write time into a buffer */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
142 char * fd_log_time ( struct timespec * ts, char * buf, size_t len )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
143 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
144 int ret;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
145 size_t offset = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
146 struct timespec tp;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
147 struct tm tm;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
148
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
149 /* Get current time */
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
150 if (!ts) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
151 ret = clock_gettime(CLOCK_REALTIME, &tp);
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
152 if (ret != 0) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
153 snprintf(buf, len, "%s", strerror(ret));
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
154 return buf;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
155 }
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
156 ts = &tp;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
157 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
159 offset += strftime(buf + offset, len - offset, "%D,%T", localtime_r( &ts->tv_sec , &tm ));
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
160 offset += snprintf(buf + offset, len - offset, ".%6.6ld", ts->tv_nsec / 1000);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162 return buf;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163 }
"Welcome to our mercurial repository"