[Pkg-voip-commits] [bctoolbox] 46/60: fix bctbx_dirname and allows different extension for log file
Bernhard Schmidt
berni at moszumanska.debian.org
Sun Oct 15 22:42:28 UTC 2017
This is an automated email from the git hooks/post-receive script.
berni pushed a commit to branch debian/sid
in repository bctoolbox.
commit d7b2719e27908a047c8a925c37803e30036b2a7c
Author: Benjamin Reis <benjamin.reis at belledonne-communications.com>
Date: Fri Jun 23 11:46:18 2017 +0200
fix bctbx_dirname and allows different extension for log file
---
src/logging/logging.c | 42 ++++++++++++++++++++++++++----------------
src/utils/port.c | 8 ++++----
tester/bctoolbox_tester.c | 2 +-
3 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/src/logging/logging.c b/src/logging/logging.c
index ea56c80..015b159 100644
--- a/src/logging/logging.c
+++ b/src/logging/logging.c
@@ -116,7 +116,7 @@ bctbx_log_handler_t* bctbx_create_log_handler(BctbxLogHandlerFunc func, BctbxLog
bctbx_log_handler_t* bctbx_create_file_log_handler(uint64_t max_size, const char* path, const char* name, FILE* f) {
bctbx_log_handler_t* handler = (bctbx_log_handler_t*)bctbx_malloc0(sizeof(bctbx_log_handler_t));
bctbx_file_log_handler_t* filehandler = (bctbx_file_log_handler_t*)bctbx_malloc(sizeof(bctbx_file_log_handler_t));
- char *full_name = bctbx_strdup_printf("%s/%s.log",
+ char *full_name = bctbx_strdup_printf("%s/%s",
path,
name);
struct stat buf;
@@ -504,7 +504,7 @@ static int _try_open_log_collection_file(bctbx_file_log_handler_t *filehandler)
struct stat statbuf;
char *log_filename;
- log_filename = bctbx_strdup_printf("%s/%s.log",
+ log_filename = bctbx_strdup_printf("%s/%s",
filehandler->path,
filehandler->name);
filehandler->file = fopen(log_filename, "a");
@@ -524,43 +524,53 @@ static int _try_open_log_collection_file(bctbx_file_log_handler_t *filehandler)
static void _rotate_log_collection_files(bctbx_file_log_handler_t *filehandler) {
char *log_filename;
char *log_filename2;
+ char *extension = strrchr(filehandler->name, '.');
+ char *file_no_extension = bctbx_strdup(filehandler->name);
+ file_no_extension[extension - file_no_extension] = '\0';
int n = 1;
- log_filename = bctbx_strdup_printf("%s/%s_1.log",
+ log_filename = bctbx_strdup_printf("%s/%s_1.%s",
filehandler->path,
- filehandler->name);
+ file_no_extension,
+ extension);
while(access(log_filename, F_OK) != -1) {
// file exists
n++;
- log_filename = bctbx_strdup_printf("%s/%s_%d.log",
+ log_filename = bctbx_strdup_printf("%s/%s_%d.%s",
filehandler->path,
- filehandler->name,
- n);
+ file_no_extension,
+ n,
+ extension);
}
while(n > 1) {
- log_filename = bctbx_strdup_printf("%s/%s_%d.log",
+ log_filename = bctbx_strdup_printf("%s/%s_%d.%s",
filehandler->path,
- filehandler->name,
- n-1);
- log_filename2 = bctbx_strdup_printf("%s/%s_%d.log",
+ file_no_extension,
+ n-1,
+ extension);
+ log_filename2 = bctbx_strdup_printf("%s/%s_%d.%s",
filehandler->path,
- filehandler->name,
- n);
+ file_no_extension,
+ n,
+ extension);
n--;
rename(log_filename, log_filename2);
}
- log_filename = bctbx_strdup_printf("%s/%s.log",
+ log_filename = bctbx_strdup_printf("%s/%s",
filehandler->path,
filehandler->name);
- log_filename2 = bctbx_strdup_printf("%s/%s_1.log",
+ log_filename2 = bctbx_strdup_printf("%s/%s_1.%s",
filehandler->path,
- filehandler->name);
+ file_no_extension,
+ extension);
rename(log_filename, log_filename2);
bctbx_free(log_filename);
bctbx_free(log_filename2);
+ bctbx_free(extension);
+ bctbx_free(file_no_extension);
}
static void _open_log_collection_file(bctbx_file_log_handler_t *filehandler) {
diff --git a/src/utils/port.c b/src/utils/port.c
index 070f486..59a927b 100644
--- a/src/utils/port.c
+++ b/src/utils/port.c
@@ -112,14 +112,14 @@ char * bctbx_dirname(const char *path) {
char *dname = bctbx_strdup(path);
bool_t found = FALSE;
- ptr = strchr(path, '/');
+ ptr = strrchr(path, '/');
if (ptr != NULL) {
- dname[ptr - path + 1] = '\0';
+ dname[ptr - path] = '\0';
found = TRUE;
} else {
- ptr = strchr(path, '\\');
+ ptr = strrchr(path, '\\');
if (ptr != NULL) {
- dname[ptr - path + 1] = '\0';
+ dname[ptr - path] = '\0';
found = TRUE;
}
}
diff --git a/tester/bctoolbox_tester.c b/tester/bctoolbox_tester.c
index 8d2f267..d9a5eab 100644
--- a/tester/bctoolbox_tester.c
+++ b/tester/bctoolbox_tester.c
@@ -63,7 +63,7 @@ int bctoolbox_tester_set_log_file(const char *filename) {
if (log_file) {
fclose(log_file);
}
- log_file = fopen(filename, "w");
+ log_file = fopen(filename, "a");
if (!log_file) {
bctbx_error("Cannot open file [%s] for writing logs because [%s]", filename, strerror(errno));
return -1;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/bctoolbox.git
More information about the Pkg-voip-commits
mailing list