Update code
This commit is contained in:
@@ -1228,6 +1228,9 @@ static int _dns_decode_opt_ecs(struct dns_context *context, struct dns_opt_ecs *
|
|||||||
memcpy(ecs->addr, context->ptr, len);
|
memcpy(ecs->addr, context->ptr, len);
|
||||||
context->ptr += len;
|
context->ptr += len;
|
||||||
|
|
||||||
|
tlog(TLOG_DEBUG, "ECS: family:%d, source_prefix:%d, scope_prefix:%d, len:%d", ecs->family, ecs->source_prefix, ecs->scope_prefix, len);
|
||||||
|
tlog(TLOG_DEBUG, "%d.%d.%d.%d", ecs->addr[0], ecs->addr[1], ecs->addr[2], ecs->addr[3]);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1283,9 +1286,11 @@ static int _dns_decode_opt(struct dns_context *context, dns_rr_type type, unsign
|
|||||||
}
|
}
|
||||||
ever = ever;
|
ever = ever;
|
||||||
|
|
||||||
|
tlog(TLOG_DEBUG, "decode opt.");
|
||||||
while (context->ptr - start < rr_len) {
|
while (context->ptr - start < rr_len) {
|
||||||
opt_code = dns_read_short(&context->ptr);
|
opt_code = dns_read_short(&context->ptr);
|
||||||
opt_len = dns_read_short(&context->ptr);
|
opt_len = dns_read_short(&context->ptr);
|
||||||
|
tlog(TLOG_DEBUG, "opt type %d", opt_code);
|
||||||
switch (opt_code) {
|
switch (opt_code) {
|
||||||
case DNS_OPT_T_ECS: {
|
case DNS_OPT_T_ECS: {
|
||||||
struct dns_opt_ecs ecs;
|
struct dns_opt_ecs ecs;
|
||||||
|
|||||||
61
src/tlog.c
61
src/tlog.c
@@ -1,5 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
|
* ttinylog
|
||||||
* Copyright (C) 2018 Ruilin Peng (Nick) <pymumu@gmail.com>
|
* Copyright (C) 2018 Ruilin Peng (Nick) <pymumu@gmail.com>
|
||||||
|
* https://github.com/pymumu/tinylog
|
||||||
*/
|
*/
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
@@ -252,8 +254,8 @@ static int _tlog_log_buffer(char *buff, int maxlen, tlog_level level, const char
|
|||||||
struct tlog_info info;
|
struct tlog_info info;
|
||||||
|
|
||||||
if (tlog_format == NULL) {
|
if (tlog_format == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level >= TLOG_END) {
|
if (level >= TLOG_END) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -293,9 +295,9 @@ int tlog_vext(tlog_level level, const char *file, int line, const char *func, vo
|
|||||||
|
|
||||||
if (tlog.buff == NULL) {
|
if (tlog.buff == NULL) {
|
||||||
vprintf(format, ap);
|
vprintf(format, ap);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&tlog.lock);
|
pthread_mutex_lock(&tlog.lock);
|
||||||
do {
|
do {
|
||||||
@@ -407,8 +409,8 @@ static int _tlog_list_dir(const char *path, list_callback callback, void *userpt
|
|||||||
}
|
}
|
||||||
|
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
while ((ent = readdir(dir)) != NULL) {
|
||||||
if (strncmp(".", ent->d_name, 2) == 0 || strncmp("..", ent->d_name, 3) == 0) {
|
if (strncmp(".", ent->d_name, 2) == 0 || strncmp("..", ent->d_name, 3) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ret = callback(path, ent, userptr);
|
ret = callback(path, ent, userptr);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
@@ -588,43 +590,46 @@ static void _tlog_wait_pid(int wait_hang)
|
|||||||
|
|
||||||
static void _tlog_close_all_fd(void)
|
static void _tlog_close_all_fd(void)
|
||||||
{
|
{
|
||||||
char path_name[PATH_MAX];
|
char path_name[PATH_MAX];
|
||||||
DIR *dir = NULL;
|
DIR *dir = NULL;
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
|
int dir_fd = -1;
|
||||||
|
|
||||||
snprintf(path_name, sizeof(path_name), "/proc/self/fd/");
|
snprintf(path_name, sizeof(path_name), "/proc/self/fd/");
|
||||||
dir = opendir(path_name);
|
dir = opendir(path_name);
|
||||||
if (dir == NULL) {
|
if (dir == NULL) {
|
||||||
fprintf(stderr, "open directory failed, %s\n", strerror(errno));
|
fprintf(stderr, "open directory failed, %s\n", strerror(errno));
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
dir_fd = dirfd(dir);
|
||||||
int fd = atoi(ent->d_name);
|
|
||||||
if (fd < 0 || dirfd(dir) == fd) {
|
while ((ent = readdir(dir)) != NULL) {
|
||||||
continue;
|
int fd = atoi(ent->d_name);
|
||||||
}
|
if (fd < 0 || dir_fd == fd) {
|
||||||
switch (fd) {
|
continue;
|
||||||
|
}
|
||||||
|
switch (fd) {
|
||||||
case STDIN_FILENO:
|
case STDIN_FILENO:
|
||||||
case STDOUT_FILENO:
|
case STDOUT_FILENO:
|
||||||
case STDERR_FILENO:
|
case STDERR_FILENO:
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
errout:
|
errout:
|
||||||
if (dir) {
|
if (dir) {
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _tlog_archive_log(void)
|
static int _tlog_archive_log(void)
|
||||||
@@ -662,16 +667,16 @@ static int _tlog_archive_log(void)
|
|||||||
if (tlog.zip_pid <= 0) {
|
if (tlog.zip_pid <= 0) {
|
||||||
int pid = vfork();
|
int pid = vfork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
_tlog_close_all_fd();
|
_tlog_close_all_fd();
|
||||||
execl("/bin/sh", "sh", "-c", gzip_cmd, NULL);
|
execl("/bin/sh", "sh", "-c", gzip_cmd, NULL);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
} else if (pid < 0) {
|
} else if (pid < 0) {
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
tlog.zip_pid = pid;
|
tlog.zip_pid = pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
errout:
|
errout:
|
||||||
_tlog_log_unlock();
|
_tlog_log_unlock();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
|
* tinylog
|
||||||
* Copyright (C) 2018 Ruilin Peng (Nick) <pymumu@gmail.com>
|
* Copyright (C) 2018 Ruilin Peng (Nick) <pymumu@gmail.com>
|
||||||
|
* https://github.com/pymumu/tinylog
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TLOG_H
|
#ifndef TLOG_H
|
||||||
|
|||||||
Reference in New Issue
Block a user