diff --git a/src/dns.c b/src/dns.c index 69f4787..150ec3a 100644 --- a/src/dns.c +++ b/src/dns.c @@ -1228,6 +1228,9 @@ static int _dns_decode_opt_ecs(struct dns_context *context, struct dns_opt_ecs * memcpy(ecs->addr, 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; } @@ -1283,9 +1286,11 @@ static int _dns_decode_opt(struct dns_context *context, dns_rr_type type, unsign } ever = ever; + tlog(TLOG_DEBUG, "decode opt."); while (context->ptr - start < rr_len) { opt_code = dns_read_short(&context->ptr); opt_len = dns_read_short(&context->ptr); + tlog(TLOG_DEBUG, "opt type %d", opt_code); switch (opt_code) { case DNS_OPT_T_ECS: { struct dns_opt_ecs ecs; diff --git a/src/tlog.c b/src/tlog.c index 40f82e9..04feca7 100644 --- a/src/tlog.c +++ b/src/tlog.c @@ -1,5 +1,7 @@ /* - * Copyright (C) 2018 Ruilin Peng (Nick) + * ttinylog + * Copyright (C) 2018 Ruilin Peng (Nick) + * https://github.com/pymumu/tinylog */ #define _GNU_SOURCE #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; if (tlog_format == NULL) { - return -1; - } + return -1; + } if (level >= TLOG_END) { 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) { vprintf(format, ap); - printf("\n"); - return -1; - } + printf("\n"); + return -1; + } pthread_mutex_lock(&tlog.lock); do { @@ -407,8 +409,8 @@ static int _tlog_list_dir(const char *path, list_callback callback, void *userpt } while ((ent = readdir(dir)) != NULL) { - if (strncmp(".", ent->d_name, 2) == 0 || strncmp("..", ent->d_name, 3) == 0) { - continue; + if (strncmp(".", ent->d_name, 2) == 0 || strncmp("..", ent->d_name, 3) == 0) { + continue; } ret = callback(path, ent, userptr); if (ret != 0) { @@ -588,43 +590,46 @@ static void _tlog_wait_pid(int wait_hang) static void _tlog_close_all_fd(void) { - char path_name[PATH_MAX]; + char path_name[PATH_MAX]; DIR *dir = NULL; 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); if (dir == NULL) { fprintf(stderr, "open directory failed, %s\n", strerror(errno)); goto errout; } - while ((ent = readdir(dir)) != NULL) { - int fd = atoi(ent->d_name); - if (fd < 0 || dirfd(dir) == fd) { - continue; - } - switch (fd) { + dir_fd = dirfd(dir); + + while ((ent = readdir(dir)) != NULL) { + int fd = atoi(ent->d_name); + if (fd < 0 || dir_fd == fd) { + continue; + } + switch (fd) { case STDIN_FILENO: case STDOUT_FILENO: case STDERR_FILENO: continue; break; default: - break; + break; } - close(fd); - } + close(fd); + } - closedir(dir); + closedir(dir); - return; + return; errout: if (dir) { - closedir(dir); - } - return; + closedir(dir); + } + return; } static int _tlog_archive_log(void) @@ -662,16 +667,16 @@ static int _tlog_archive_log(void) if (tlog.zip_pid <= 0) { int pid = vfork(); if (pid == 0) { - _tlog_close_all_fd(); - execl("/bin/sh", "sh", "-c", gzip_cmd, NULL); - _exit(1); + _tlog_close_all_fd(); + execl("/bin/sh", "sh", "-c", gzip_cmd, NULL); + _exit(1); } else if (pid < 0) { goto errout; } tlog.zip_pid = pid; - } + } - return 0; + return 0; errout: _tlog_log_unlock(); diff --git a/src/tlog.h b/src/tlog.h index 354aad1..57e4ce1 100644 --- a/src/tlog.h +++ b/src/tlog.h @@ -1,5 +1,7 @@ /* - * Copyright (C) 2018 Ruilin Peng (Nick) + * tinylog + * Copyright (C) 2018 Ruilin Peng (Nick) + * https://github.com/pymumu/tinylog */ #ifndef TLOG_H