Whamcloud - gitweb
e2fsck: merge options after threads finish
[tools/e2fsprogs.git] / e2fsck / logfile.c
index 63e9a12..46ec2ac 100644 (file)
@@ -16,6 +16,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <assert.h>
 
 #include "e2fsck.h"
 #include <pwd.h>
@@ -32,7 +33,7 @@ static void alloc_string(struct string *s, int len)
 {
        s->s = malloc(len);
 /* e2fsck_allocate_memory(ctx, len, "logfile name"); */
-       s->len = len;
+       s->len = s->s ? len : 0;
        s->end = 0;
 }
 
@@ -155,6 +156,9 @@ static void expand_percent_expression(e2fsck_t ctx, char ch,
        case 'Y':
                sprintf(buf, "%d", tm->tm_year + 1900);
                break;
+       default:
+               sprintf(buf, "%%%c", ch);
+               break;
        }
        append_string(s, buf, 0);
 }
@@ -291,6 +295,7 @@ static FILE *set_up_log_file(e2fsck_t ctx, const char *key, const char *fn)
        struct string s, s1, s2;
        char *s0 = 0, *log_dir = 0, *log_fn = 0;
        int log_dir_wait = 0;
+       char string_index[10];
 
        s.s = s1.s = s2.s = 0;
 
@@ -307,6 +312,15 @@ static FILE *set_up_log_file(e2fsck_t ctx, const char *key, const char *fn)
                goto out;
 
        expand_logfn(ctx, log_fn, &s);
+#ifdef HAVE_PTHREAD
+       if (ctx->global_ctx) {
+               sprintf(string_index, "%d",
+                       ctx->thread_info.et_thread_index);
+               append_string(&s, ".", 1);
+               append_string(&s, string_index, 0);
+       }
+#endif
+
        if ((log_fn[0] == '/') || !log_dir || !log_dir[0])
                s0 = s.s;
 
@@ -325,7 +339,6 @@ static FILE *set_up_log_file(e2fsck_t ctx, const char *key, const char *fn)
                append_string(&s2, log_dir, 0);
                append_string(&s2, "/", 1);
                append_string(&s2, s.s, 0);
-               printf("%s\n", s2.s);
        }
 
        if (s0)