Fixed bug in reqstat.
[doldaconnect.git] / daemon / reqstat.c
index 41ca1c6..cbe1c72 100644 (file)
@@ -40,7 +40,7 @@ void filelog(char *format, ...)
 {
     FILE *out;
     va_list args;
-    char *b;
+    char *b, *t, *p;
     time_t now;
     
     if(fn == NULL)
@@ -53,7 +53,10 @@ void filelog(char *format, ...)
     va_start(args, format);
     b = vsprintf2(format, args);
     va_end(args);
-    fprintf(out, "%s: %s\n", ctime(&now), b);
+    t = ctime(&now);
+    if((p = strchr(t, '\n')) != NULL)
+       *p = 0;
+    fprintf(out, "%s: %s\n", t, b);
     free(b);
     fclose(out);
 }
@@ -65,12 +68,12 @@ void request(struct transfer *transfer, struct trdata *data)
 
 void start(struct transfer *transfer, struct trdata *data)
 {
-    filelog("start %ls at %zi\n", transfer->path, data->startpos);
+    filelog("start %ls at %zi", transfer->path, data->startpos);
 }
 
 void finish(struct transfer *transfer, struct trdata *data)
 {
-    filelog("finish %ls at %zi, total %zi\n", transfer->path, transfer->curpos, transfer->curpos - data->startpos);
+    filelog("finish %ls at %zi, total %zi", transfer->path, transfer->curpos, transfer->curpos - data->startpos);
 }
 
 static int chattr(struct transfer *transfer, wchar_t *attrib, struct trdata *data)
@@ -92,7 +95,8 @@ static int chattr(struct transfer *transfer, wchar_t *attrib, struct trdata *dat
 
 static int destroy(struct transfer *transfer, struct trdata *data)
 {
-    finish(transfer, data);
+    if(transfer->curpos > data->startpos)
+       finish(transfer, data);
     free(data);
     return(0);
 }
@@ -113,7 +117,7 @@ static int chfile(struct configvar *var, void *uudata)
 {
     if(fn != NULL)
        free(fn);
-    if(var->val.str[0] == L'0') {
+    if(var->val.str[0] == L'\0') {
        fn = NULL;
     } else {
        if((fn = icwcstombs(var->val.str, NULL)) == NULL)
@@ -122,12 +126,14 @@ static int chfile(struct configvar *var, void *uudata)
     return(0);
 }
 
-static void preinit(int hup)
+static int init(int hup)
 {
     if(!hup) {
        GCBREG(newtransfercb, reg, NULL);
+       chfile(confgetvar("reqstat", "file"), NULL);
        CBREG(confgetvar("reqstat", "file"), conf_update, chfile, NULL, NULL);
     }
+    return(0);
 }
 
 static struct configvar myvars[] = {
@@ -141,8 +147,8 @@ static struct module me = {
     .conf = {
        .vars = myvars
     },
-    .preinit = preinit,
+    .init = init,
     .name = "reqstat"
 };
 
-MODULE(me);
+MODULE(me)