Compare commits

...

5 Commits

Author SHA1 Message Date
Hongcai Deng 1bdc163269
Merge a16fde8070 into ce4c5e23d4 2025-08-24 23:47:28 +08:00
YuQing ce4c5e23d4 upgrade version to 1.0.79 2025-08-24 22:58:33 +08:00
YuQing d59da03d60 use size_t instead int to avoid compile warning 2025-08-21 20:52:35 +08:00
YuQing 8e51f4de3e logger.h export function log_it_ex3 2025-08-20 17:54:29 +08:00
Hongcai Deng a16fde8070 fix: compile error when build .so using .a
```
src/libfastcommon.a(hash.o): relocation R_X86_64_32 against `.data' can not be used when making a shared object; recompile with -fPIC
```

env: Ubuntu 14.04, gcc 4.8
2017-01-29 14:20:18 +08:00
8 changed files with 63 additions and 42 deletions

View File

@ -1,4 +1,7 @@
Version 1.79 2025-08-20
* logger.h export function log_it_ex3
Version 1.78 2025-08-07
* getIpaddrByName: normalize ip addr when input addr is IPv4 or IPv6
* add files: spinlock.[hc]

View File

@ -3,7 +3,7 @@
%define CommitVersion %(echo $COMMIT_VERSION)
Name: libfastcommon
Version: 1.0.78
Version: 1.0.79
Release: 1%{?dist}
Summary: c common functions library extracted from my open source projects FastDFS
License: LGPL

View File

@ -66,7 +66,7 @@ libfastcommon.a: $(FAST_STATIC_OBJS)
.c:
$(COMPILE) -o $@ $< $(FAST_STATIC_OBJS) $(LIB_PATH) $(INC_PATH)
.c.o:
$(COMPILE) -c -o $@ $< $(INC_PATH)
$(COMPILE) -c -fPIC -o $@ $< $(INC_PATH)
.c.lo:
$(COMPILE) -c -fPIC -o $@ $< $(INC_PATH)
install:

View File

@ -115,7 +115,7 @@ static inline int fast_buffer_append_char(FastBuffer *buffer, const char ch)
return 0;
}
static inline int fast_buffer_append_int(FastBuffer *buffer, const int n)
static inline int fast_buffer_append_int32(FastBuffer *buffer, const int n)
{
int result;
@ -143,6 +143,9 @@ static inline int fast_buffer_append_int64(FastBuffer *buffer, const int64_t n)
return 0;
}
#define fast_buffer_append_int(buffer, n) \
fast_buffer_append_int64(buffer, n)
int fast_buffer_append_file(FastBuffer *buffer, const char *filename);
static inline int fast_buffer_append_string(FastBuffer *buffer, const char *str)

View File

@ -112,7 +112,7 @@ int log_init_ex(LogContext *pContext)
}
pContext->pcurrent_buff = pContext->log_buff;
if ((result=init_pthread_lock(&(pContext->log_thread_lock))) != 0)
if ((result=init_pthread_lock(&(pContext->lock))) != 0)
{
return result;
}
@ -296,9 +296,9 @@ void log_set_header_callback(LogContext *pContext, LogHeaderCallback header_call
{
int64_t current_size;
pthread_mutex_lock(&(pContext->log_thread_lock));
pthread_mutex_lock(&(pContext->lock));
current_size = pContext->current_size;
pthread_mutex_unlock(&(pContext->log_thread_lock));
pthread_mutex_unlock(&(pContext->lock));
if (current_size == 0)
{
log_print_header(pContext);
@ -347,7 +347,7 @@ void log_destroy_ex(LogContext *pContext)
close(pContext->log_fd);
pContext->log_fd = STDERR_FILENO;
pthread_mutex_destroy(&pContext->log_thread_lock);
pthread_mutex_destroy(&pContext->lock);
}
if (pContext->log_buff != NULL)
@ -918,19 +918,19 @@ static int log_fsync(LogContext *pContext, const bool bNeedLock)
{
if (bNeedLock)
{
pthread_mutex_lock(&(pContext->log_thread_lock));
pthread_mutex_lock(&(pContext->lock));
}
result = log_check_rotate(pContext);
if (bNeedLock)
{
pthread_mutex_unlock(&(pContext->log_thread_lock));
pthread_mutex_unlock(&(pContext->lock));
}
return result;
}
}
if (bNeedLock && ((lock_res=pthread_mutex_lock( \
&(pContext->log_thread_lock))) != 0))
&(pContext->lock))) != 0))
{
fprintf(stderr, "file: "__FILE__", line: %d, " \
"call pthread_mutex_lock fail, " \
@ -966,7 +966,7 @@ static int log_fsync(LogContext *pContext, const bool bNeedLock)
}
if (bNeedLock && ((lock_res=pthread_mutex_unlock( \
&(pContext->log_thread_lock))) != 0))
&(pContext->lock))) != 0))
{
fprintf(stderr, "file: "__FILE__", line: %d, " \
"call pthread_mutex_unlock fail, " \
@ -977,8 +977,8 @@ static int log_fsync(LogContext *pContext, const bool bNeedLock)
return result;
}
static void doLogEx(LogContext *pContext, struct timeval *tv, \
const char *caption, const char *text, const int text_len, \
void log_it_ex3(LogContext *pContext, struct timeval *tv,
const char *caption, const char *text, const int text_len,
const bool bNeedSync, const bool bNeedLock)
{
struct tm tm;
@ -1003,7 +1003,7 @@ static void doLogEx(LogContext *pContext, struct timeval *tv, \
}
}
if (bNeedLock && (result=pthread_mutex_lock(&pContext->log_thread_lock)) != 0)
if (bNeedLock && (result=pthread_mutex_lock(&pContext->lock)) != 0)
{
fprintf(stderr, "file: "__FILE__", line: %d, " \
"call pthread_mutex_lock fail, " \
@ -1018,12 +1018,12 @@ static void doLogEx(LogContext *pContext, struct timeval *tv, \
__LINE__, LOG_BUFF_SIZE, text_len + 64);
if (bNeedLock)
{
pthread_mutex_unlock(&(pContext->log_thread_lock));
pthread_mutex_unlock(&(pContext->lock));
}
return;
}
if ((pContext->pcurrent_buff - pContext->log_buff) + text_len + 64 \
if ((pContext->pcurrent_buff - pContext->log_buff) + text_len + 64
> LOG_BUFF_SIZE)
{
log_fsync(pContext, false);
@ -1067,7 +1067,7 @@ static void doLogEx(LogContext *pContext, struct timeval *tv, \
log_fsync(pContext, false);
}
if (bNeedLock && (result=pthread_mutex_unlock(&(pContext->log_thread_lock))) != 0)
if (bNeedLock && (result=pthread_mutex_unlock(&(pContext->lock))) != 0)
{
fprintf(stderr, "file: "__FILE__", line: %d, " \
"call pthread_mutex_unlock fail, " \
@ -1076,8 +1076,8 @@ static void doLogEx(LogContext *pContext, struct timeval *tv, \
}
}
void log_it_ex2(LogContext *pContext, const char *caption, \
const char *text, const int text_len, \
void log_it_ex2(LogContext *pContext, const char *caption,
const char *text, const int text_len,
const bool bNeedSync, const bool bNeedLock)
{
struct timeval tv;
@ -1092,10 +1092,10 @@ void log_it_ex2(LogContext *pContext, const char *caption, \
gettimeofday(&tv, NULL);
}
doLogEx(pContext, &tv, caption, text, text_len, bNeedSync, bNeedLock);
log_it_ex3(pContext, &tv, caption, text, text_len, bNeedSync, bNeedLock);
}
void log_it_ex1(LogContext *pContext, const int priority, \
void log_it_ex1(LogContext *pContext, const int priority,
const char *text, const int text_len)
{
bool bNeedSync;
@ -1291,7 +1291,7 @@ void logAccess(LogContext *pContext, struct timeval *tvStart, \
{
len = sizeof(text) - 1;
}
doLogEx(pContext, tvStart, NULL, text, len, false, true);
log_it_ex3(pContext, tvStart, NULL, text, len, false, true);
}
const char *log_get_level_caption_ex(LogContext *pContext)

View File

@ -62,7 +62,7 @@ typedef struct log_context
char *pcurrent_buff;
/* mutext lock */
pthread_mutex_t log_thread_lock;
pthread_mutex_t lock;
/*
rotate the log when the log file exceeds this parameter
@ -343,7 +343,7 @@ void log_it_ex(LogContext *pContext, const int priority, \
* text_len: text string length (bytes)
* return: none
*/
void log_it_ex1(LogContext *pContext, const int priority, \
void log_it_ex1(LogContext *pContext, const int priority,
const char *text, const int text_len);
/** log to file
@ -355,10 +355,13 @@ void log_it_ex1(LogContext *pContext, const int priority, \
* bNeedSync: if sync to file immediatelly
* return: none
*/
void log_it_ex2(LogContext *pContext, const char *caption, \
const char *text, const int text_len, \
void log_it_ex2(LogContext *pContext, const char *caption,
const char *text, const int text_len,
const bool bNeedSync, const bool bNeedLock);
void log_it_ex3(LogContext *pContext, struct timeval *tv,
const char *caption, const char *text, const int text_len,
const bool bNeedSync, const bool bNeedLock);
/** sync log buffer to log file
* parameters:

View File

@ -1632,7 +1632,7 @@ static inline int fc_ltostr(int64_t n, char *buff)
static inline size_t fc_strlcpy(char *dest, const char *src, const size_t size)
{
int len;
size_t len;
len = strlen(src);
if (len < size) {

View File

@ -29,6 +29,7 @@
#include <netinet/tcp.h>
#include <netdb.h>
#include "common_define.h"
#include "shared_func.h"
#define FC_NET_TYPE_NONE 0
#define FC_NET_TYPE_OUTER 1 //extranet IP
@ -53,16 +54,6 @@
#define FAST_WRITE_BUFF_SIZE (256 * 1024)
#define FC_FORMAT_IP_ADDRESS(old_ip_addr, new_ip_addr) \
char new_ip_addr[FORMATTED_IP_SIZE]; \
do { \
if (is_ipv6_addr(old_ip_addr)) { \
sprintf(new_ip_addr, "[%s]", old_ip_addr); \
} else { \
strcpy(new_ip_addr, old_ip_addr); \
} \
} while (0)
typedef struct fast_if_config {
char name[IF_NAMESIZE]; //if name
char mac[64];
@ -719,7 +710,16 @@ static inline const char *format_ip_address(const char *ip, char *buff)
{
if (is_ipv6_addr(ip))
{
sprintf(buff, "[%s]", ip);
int ip_len;
char *p;
ip_len = strlen(ip);
p = buff;
*p++ = '[';
memcpy(p, ip, ip_len);
p += ip_len;
*p++ = ']';
*p = '\0';
}
else
{
@ -732,14 +732,26 @@ static inline const char *format_ip_address(const char *ip, char *buff)
static inline const char *format_ip_port(const char *ip,
const int port, char *buff)
{
if (is_ipv6_addr(ip))
int ip_len;
bool is_ipv6;
char *p;
is_ipv6 = is_ipv6_addr(ip);
ip_len = strlen(ip);
p = buff;
if (is_ipv6)
{
sprintf(buff, "[%s]:%u", ip, port);
*p++ = '[';
}
else
memcpy(p, ip, ip_len);
p += ip_len;
if (is_ipv6)
{
sprintf(buff, "%s:%u", ip, port);
*p++ = ']';
}
*p++ = ':';
p += fc_itoa(port, p);
*p = '\0';
return buff;
}