about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-06-07 23:48:44 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-06-07 23:48:44 +0200
commitbb4dd47a014e10457cc46d35a4725dfcfa3e3e0c (patch)
tree096dba07296fae2dcb8f0b7f8b354b203af95f30 /src
parent1f3d61e9f7f131333c8e5b3d3391ac137b5538ff (diff)
downloadprofani-tty-bb4dd47a014e10457cc46d35a4725dfcfa3e3e0c.tar.gz
Iterate logfiles until 100 are reached
Fix https://github.com/profanity-im/profanity/issues/519
Diffstat (limited to 'src')
-rw-r--r--src/log.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/log.c b/src/log.c
index b679eb1a..e8b2bcbd 100644
--- a/src/log.c
+++ b/src/log.c
@@ -227,14 +227,17 @@ log_level_from_string(char *log_level)
 static void
 _rotate_log_file(void)
 {
-    char *log_file = files_get_log_file();
+    gchar *log_file = files_get_log_file();
     size_t len = strlen(log_file);
-    char *log_file_new = malloc(len + 3);
+    gchar *log_file_new = malloc(len + 4);
+    int i = 1;
 
-    memcpy(log_file_new, log_file, len);
-    log_file_new[len] = '.';
-    log_file_new[len+1] = '1';
-    log_file_new[len+2] = 0;
+    // find an empty name. from .log -> log.01 -> log.99
+    for(; i<100; i++) {
+        g_sprintf(log_file_new, "%s.%02d", log_file, i);
+        if (!g_file_test(log_file_new, G_FILE_TEST_EXISTS))
+            break;
+    }
 
     log_close();
     rename(log_file, log_file_new);