annotate libfdproto/log.c @ 1554:566bb46cc73f

Updated copyright information
author Sebastien Decugis <sdecugis@freediameter.net>
date Tue, 06 Oct 2020 21:34:53 +0800
parents d4a4ab5239c7
children
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 * *
1554
566bb46cc73f Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1407
diff changeset
5 * Copyright (c) 2020, 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;
1088
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
42 int fd_g_debug_lvl = FD_LOG_NOTICE;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
44 static void fd_internal_logger( int, const char *, va_list );
966
8862d9dece66 Use color output on consoles
Sebastien Decugis <sdecugis@freediameter.net>
parents: 965
diff changeset
45 static int use_colors = 0; /* 0: not init, 1: yes, 2: no */
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
46
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
47 /* 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
48 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
49 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
50
183
960764fbc68f Fix compilation error
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
51 /* 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
52 int fd_breaks = 0;
960764fbc68f Fix compilation error
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 174
diff changeset
53 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
54
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
55 /* Allow passing of the log and debug information from base stack to extensions */
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
56 void (*fd_logger)( int loglevel, const char * format, va_list args ) = fd_internal_logger;
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
57
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
58 /* Register an external call back for tracing and debug */
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
59 int fd_log_handler_register( void (*logger)(int loglevel, const char * format, va_list args) )
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
60 {
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 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
62
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
63 if ( fd_logger != fd_internal_logger )
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
64 {
905
Sebastien Decugis <sdecugis@freediameter.net>
parents: 904
diff changeset
65 return EALREADY; /* only one registration allowed */
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
66 }
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 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
68 {
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
69 fd_logger = logger;
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
70 }
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
71
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
72 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
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
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 /* 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
76 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
77 {
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
78 fd_logger = fd_internal_logger;
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
79 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
80 }
e87d083d0342 Added ability to register another log function; thanks to Zack for the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
81
200
ff557d8b48d7 Fix deadlock in some circumstances
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 183
diff changeset
82 static void fd_cleanup_mutex_silent( void * mutex )
ff557d8b48d7 Fix deadlock in some circumstances
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 183
diff changeset
83 {
ff557d8b48d7 Fix deadlock in some circumstances
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 183
diff changeset
84 (void)pthread_mutex_unlock((pthread_mutex_t *)mutex);
ff557d8b48d7 Fix deadlock in some circumstances
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 183
diff changeset
85 }
ff557d8b48d7 Fix deadlock in some circumstances
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 183
diff changeset
86
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
87
1088
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
88 static void fd_internal_logger( int printlevel, const char *format, va_list ap )
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
89 {
945
284608b307ee Add timestamp to default logger.
Thomas Klausner <tk@giga.or.at>
parents: 941
diff changeset
90 char buf[25];
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
91
1088
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
92 /* Do we need to trace this ? */
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
93 if (printlevel < fd_g_debug_lvl)
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
94 return;
945
284608b307ee Add timestamp to default logger.
Thomas Klausner <tk@giga.or.at>
parents: 941
diff changeset
95
284608b307ee Add timestamp to default logger.
Thomas Klausner <tk@giga.or.at>
parents: 941
diff changeset
96 /* add timestamp */
1243
7c5f662c4eef Shortened log timestamp format when DEBUG_WITHOUT_META is defined
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
97 printf("%s ", fd_log_time(NULL, buf, sizeof(buf),
1295
a22d9e907d48 Make the stripped output the default. Define DEBUG_WITH_META to get longer format.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1243
diff changeset
98 #if (defined(DEBUG) && defined(DEBUG_WITH_META))
1243
7c5f662c4eef Shortened log timestamp format when DEBUG_WITHOUT_META is defined
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
99 1, 1
1295
a22d9e907d48 Make the stripped output the default. Define DEBUG_WITH_META to get longer format.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1243
diff changeset
100 #else /* (defined(DEBUG) && defined(DEBUG_WITH_META)) */
1243
7c5f662c4eef Shortened log timestamp format when DEBUG_WITHOUT_META is defined
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
101 0, 0
1295
a22d9e907d48 Make the stripped output the default. Define DEBUG_WITH_META to get longer format.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1243
diff changeset
102 #endif /* (defined(DEBUG) && defined(DEBUG_WITH_META)) */
1243
7c5f662c4eef Shortened log timestamp format when DEBUG_WITHOUT_META is defined
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
103 ));
966
8862d9dece66 Use color output on consoles
Sebastien Decugis <sdecugis@freediameter.net>
parents: 965
diff changeset
104 /* Use colors on stdout ? */
8862d9dece66 Use color output on consoles
Sebastien Decugis <sdecugis@freediameter.net>
parents: 965
diff changeset
105 if (!use_colors) {
8862d9dece66 Use color output on consoles
Sebastien Decugis <sdecugis@freediameter.net>
parents: 965
diff changeset
106 if (isatty(STDOUT_FILENO))
8862d9dece66 Use color output on consoles
Sebastien Decugis <sdecugis@freediameter.net>
parents: 965
diff changeset
107 use_colors = 1;
8862d9dece66 Use color output on consoles
Sebastien Decugis <sdecugis@freediameter.net>
parents: 965
diff changeset
108 else
8862d9dece66 Use color output on consoles
Sebastien Decugis <sdecugis@freediameter.net>
parents: 965
diff changeset
109 use_colors = 2;
8862d9dece66 Use color output on consoles
Sebastien Decugis <sdecugis@freediameter.net>
parents: 965
diff changeset
110 }
8862d9dece66 Use color output on consoles
Sebastien Decugis <sdecugis@freediameter.net>
parents: 965
diff changeset
111
1088
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
112 switch(printlevel) {
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
113 case FD_LOG_ANNOYING: printf("%s A ", (use_colors == 1) ? "\e[0;37m" : ""); break;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
114 case FD_LOG_DEBUG: printf("%s DBG ", (use_colors == 1) ? "\e[0;37m" : ""); break;
1407
d4a4ab5239c7 add log level FD_LOG_INFO
Luke Mewburn <luke@mewburn.net>
parents: 1305
diff changeset
115 case FD_LOG_INFO: printf("%sINFO ", (use_colors == 1) ? "\e[1;37m" : ""); break;
1088
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
116 case FD_LOG_NOTICE: printf("%sNOTI ", (use_colors == 1) ? "\e[1;37m" : ""); break;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
117 case FD_LOG_ERROR: printf("%sERROR ", (use_colors == 1) ? "\e[0;31m" : ""); break;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
118 case FD_LOG_FATAL: printf("%sFATAL! ", (use_colors == 1) ? "\e[0;31m" : ""); break;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
119 default: printf("%s ??? ", (use_colors == 1) ? "\e[0;31m" : "");
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
120 }
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
121 vprintf(format, ap);
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
122 if (use_colors == 1)
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
123 printf("\e[00m");
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
124 printf("\n");
966
8862d9dece66 Use color output on consoles
Sebastien Decugis <sdecugis@freediameter.net>
parents: 965
diff changeset
125
1088
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
126 fflush(stdout);
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
127 }
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
128
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
129 /* Log a debug message */
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
130 void fd_log ( int loglevel, const char * format, ... )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
131 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
132 va_list ap;
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 (void)pthread_mutex_lock(&fd_log_lock);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
135
200
ff557d8b48d7 Fix deadlock in some circumstances
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 183
diff changeset
136 pthread_cleanup_push(fd_cleanup_mutex_silent, &fd_log_lock);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
137
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
138 va_start(ap, format);
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
139 fd_logger(loglevel, format, ap);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
140 va_end(ap);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
141
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
142 pthread_cleanup_pop(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 (void)pthread_mutex_unlock(&fd_log_lock);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
145 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
146
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
147 /* Log a debug message */
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
148 void fd_log_va ( int loglevel, const char * format, va_list args )
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
149 {
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
150 (void)pthread_mutex_lock(&fd_log_lock);
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
151
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
152 pthread_cleanup_push(fd_cleanup_mutex_silent, &fd_log_lock);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
153 fd_logger(loglevel, format, args);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
154 pthread_cleanup_pop(0);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
155
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
156 (void)pthread_mutex_unlock(&fd_log_lock);
941
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
157 }
64088de91f7f Initial logging rework by Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 909
diff changeset
158
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159 /* Function to set the thread's friendly name */
904
b839a1b1c1da Make freeDiameter headers more C++ friendly -- thank you Thomas
Sebastien Decugis <sdecugis@freediameter.net>
parents: 788
diff changeset
160 void fd_log_threadname ( const char * name )
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 void * val = NULL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164 TRACE_ENTRY("%p(%s)", name, name?:"/");
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 /* 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
167 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
168 if (TRACE_BOOL(ANNOYING)) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 687
diff changeset
169 if (val) {
974
2091bf698fb1 Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents: 966
diff changeset
170 fd_log_debug("(Thread '%s' renamed to '%s')", (char *)val, name?:"(nil)");
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 687
diff changeset
171 } else {
1027
0117a7746b21 Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents: 990
diff changeset
172 fd_log_debug("(Thread %p named '%s')", (void *)pthread_self(), name?:"(nil)");
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 687
diff changeset
173 }
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 687
diff changeset
174 }
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
175 if (val != NULL) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
176 free(val);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
177 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
178
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
179 /* Now create the new string */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
180 if (name == NULL) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
181 CHECK_POSIX_DO( pthread_setspecific(fd_log_thname, NULL), /* continue */);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
182 return;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
183 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185 CHECK_MALLOC_DO( val = strdup(name), return );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
186
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 CHECK_POSIX_DO( pthread_setspecific(fd_log_thname, val), /* continue */);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
188 return;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
189 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
190
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
191 /* Write time into a buffer */
1243
7c5f662c4eef Shortened log timestamp format when DEBUG_WITHOUT_META is defined
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
192 char * fd_log_time ( struct timespec * ts, char * buf, size_t len, int incl_date, int incl_ms )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
193 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
194 int ret;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195 size_t offset = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196 struct timespec tp;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
197 struct tm tm;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
198
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199 /* Get current time */
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
200 if (!ts) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
201 ret = clock_gettime(CLOCK_REALTIME, &tp);
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
202 if (ret != 0) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
203 snprintf(buf, len, "%s", strerror(ret));
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
204 return buf;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
205 }
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 2
diff changeset
206 ts = &tp;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
207 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
208
1243
7c5f662c4eef Shortened log timestamp format when DEBUG_WITHOUT_META is defined
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
209 offset += strftime(buf + offset, len - offset, incl_date?"%D,%T":"%T", localtime_r( &ts->tv_sec , &tm ));
7c5f662c4eef Shortened log timestamp format when DEBUG_WITHOUT_META is defined
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
210 if (incl_ms)
7c5f662c4eef Shortened log timestamp format when DEBUG_WITHOUT_META is defined
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
211 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
212
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
213 return buf;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
214 }
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
215
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
216
1088
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
217 static size_t sys_mempagesz = 0;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
218
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
219 static size_t get_mempagesz(void) {
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
220 if (!sys_mempagesz) {
1119
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1094
diff changeset
221 sys_mempagesz = sysconf(_SC_PAGESIZE); /* We alloc buffer by memory pages for efficiency. This can be readjusted if too memory consuming */
1088
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
222 if (sys_mempagesz <= 0)
1119
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1094
diff changeset
223 sys_mempagesz = 256; /* default size if above call failed */
1088
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
224 }
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
225 return sys_mempagesz;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
226 }
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
227
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
228
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
229 /* Helper function for fd_*_dump. Prints the format string from 'offset' into '*buf', extends if needed. The location of buf can be updated by this function. */
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
230 char * fd_dump_extend(char ** buf, size_t *len, size_t *offset, const char * format, ... )
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
231 {
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
232 va_list ap;
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
233 int to_write;
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
234 size_t o = 0;
1088
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
235 size_t mempagesz = get_mempagesz();
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
236
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
237 /* we do not TRACE_ENTRY this one on purpose */
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
238
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
239 CHECK_PARAMS_DO(buf && len, return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
240
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
241 if (*buf == NULL) {
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
242 CHECK_MALLOC_DO(*buf = malloc(mempagesz), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
243 *len = mempagesz;
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
244 }
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
245
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
246 if (offset)
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
247 o = *offset;
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
248
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
249 va_start(ap, format);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
250 to_write = vsnprintf(*buf + o, *len - o, format, ap);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
251 va_end(ap);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
252
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
253 if (to_write + o >= *len) {
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
254 /* There was no room in the buffer, we extend and redo */
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
255 size_t new_len = (((to_write + o) / mempagesz) + 1) * mempagesz;
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
256 CHECK_MALLOC_DO(*buf = realloc(*buf, new_len), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
257 *len = new_len;
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
258
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
259 va_start(ap, format);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
260 to_write = vsnprintf(*buf + o, *len - o, format, ap);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
261 va_end(ap);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
262 }
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
263
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
264 if (offset)
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
265 *offset += to_write;
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
266
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
267 return *buf;
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1027
diff changeset
268 }
1088
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
269
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
270 char * fd_dump_extend_hexdump(char ** buf, size_t *len, size_t *offset, uint8_t *data, size_t datalen, size_t trunc, size_t wrap )
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
271 {
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
272 int truncated = 0;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
273 size_t towrite = 0;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
274 size_t o = 0;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
275 int i;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
276 char * p;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
277 size_t mempagesz = get_mempagesz();
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
278 #define TRUNK_MARK "[...]"
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
279
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
280 CHECK_PARAMS_DO(buf && len && data, return NULL);
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
281
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
282 if (trunc && (datalen > trunc)) {
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
283 datalen = trunc;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
284 truncated = 1;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
285 }
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
286
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
287 towrite = datalen * 2;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
288
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
289 if (wrap)
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
290 towrite += datalen / wrap; /* add 1 '\n' every wrap byte */
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
291
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
292 if (truncated)
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
293 towrite += CONSTSTRLEN(TRUNK_MARK);
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
294
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
295
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
296 if (offset)
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
297 o = *offset;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
298
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
299 if (*buf == NULL) {
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
300 /* Directly allocate the size we need */
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
301 *len = (((towrite + o) / mempagesz) + 1 ) * mempagesz;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
302 CHECK_MALLOC_DO(*buf = malloc(*len), return NULL);
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
303 } else if ((towrite + o) >= *len) {
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
304 /* There is no room in the buffer, we extend and redo */
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
305 size_t new_len = (((towrite + o) / mempagesz) + 1) * mempagesz;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
306 CHECK_MALLOC_DO(*buf = realloc(*buf, new_len), return NULL);
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
307 *len = new_len;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
308 }
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
309
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
310 p = *buf + o;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
311 for (i = 0; i < datalen; i++) {
1094
eab8cad30b4c Additional cosmetics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1088
diff changeset
312 sprintf(p, "%02hhX", data[i]);
1088
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
313 p+=2;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
314 if ((wrap) && ((i+1) % wrap == 0)) {
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
315 *p++='\n'; *p ='\0'; /* we want to ensure the buffer is always 0-terminated */
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
316 }
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
317 }
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
318
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
319 if (truncated)
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
320 memcpy(p, TRUNK_MARK, CONSTSTRLEN(TRUNK_MARK));
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
321
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
322 if (offset)
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
323 *offset += towrite;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
324
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
325 return *buf;
1d1a20a0779d Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
326 }
"Welcome to our mercurial repository"