tags 369840 + patch quit On Fri, Jun 02, 2006 at 03:28:15PM +0000, Gerrit Pape wrote: > On Fri, Jun 02, 2006 at 04:59:39PM +0200, Andras Korn wrote: > > OK, here is a test scenario. > > Thanks Andras, I can reproduce it, and'll take a look soon.
Hi, could you try this patch? Thanks, Gerrit.
Index: man/svlogd.8 =================================================================== RCS file: /cvs/runit/man/svlogd.8,v retrieving revision 1.14 diff -u -r1.14 svlogd.8 --- man/svlogd.8 10 Apr 2006 06:09:37 -0000 1.14 +++ man/svlogd.8 6 Jun 2006 14:11:50 -0000 @@ -113,12 +113,12 @@ If the .I processor finishes successfully, -.RI @ timestamp\fR.u -is deleted and .RI @ timestamp\fR.t is renamed to .RI @ timestamp\fR.s, -otherwise +and +.RI @ timestamp\fR.u +is deleted; otherwise .RI @ timestamp\fR.t is deleted and the .I processor Index: src/svlogd.c =================================================================== RCS file: /cvs/runit/src/svlogd.c,v retrieving revision 1.18 diff -u -r1.18 svlogd.c --- src/svlogd.c 10 Apr 2006 06:09:43 -0000 1.18 +++ src/svlogd.c 6 Jun 2006 13:09:14 -0000 @@ -200,8 +200,6 @@ pause1("unable to change to initial working directory"); return(ld->processor.len ? 0 : 1); } - if (unlink(ld->fnsave) == -1) - strerr_warn5(WARNING, "unable to unlink: ", ld->name, "/", ld->fnsave, 0); ld->fnsave[26] ='t'; byte_copy(f, 26, ld->fnsave); f[26] ='s'; f[27] =0; @@ -209,6 +207,9 @@ pause2("unable to rename processed", ld->name); while (chmod(f, 0744) == -1) pause2("unable to set mode of processed", ld->name); + ld->fnsave[26] ='u'; + if (unlink(ld->fnsave) == -1) + strerr_warn5(WARNING, "unable to unlink: ", ld->name, "/", ld->fnsave, 0); while (rename("newstate", "state") == -1) pause2("unable to rename state", ld->name); if (verbose) strerr_warn5(INFO, "processed: ", ld->name, "/", f, 0); @@ -217,12 +218,40 @@ return(1); } -unsigned int rotate(struct logdir *ld) { +void rmoldest(struct logdir *ld) { DIR *d; direntry *f; + char oldest[FMT_PTIME]; int n =0; + + oldest[0] ='A'; oldest[1] =oldest[27] =0; + while (! (d =opendir("."))) + pause2("unable to open directory, want rotate", ld->name); + errno =0; + while ((f =readdir(d))) + if ((f->d_name[0] == '@') && (str_len(f->d_name) == 27)) { + if (f->d_name[26] == 't') { + if (unlink(f->d_name) == -1) + warn2("unable to unlink processor leftover", f->d_name); + } + else { + ++n; + if (str_diff(f->d_name, oldest) < 0) byte_copy(oldest, 27, f->d_name); + } + errno =0; + } + if (errno) warn2("unable to read directory", ld->name); + closedir(d); + + if (ld->nmax && (n > ld->nmax)) { + if (verbose) strerr_warn5(INFO, "delete: ", ld->name, "/", oldest, 0); + if ((*oldest == '@') && (unlink(oldest) == -1)) + warn2("unable to unlink oldest logfile", ld->name); + } +} + +unsigned int rotate(struct logdir *ld) { char tmp[FMT_ULONG +1]; - char oldest[FMT_PTIME]; if (ld->fddir == -1) { ld->tmax =0; return(0); } if (ld->ppid) while(! processorstop(ld)); @@ -269,24 +298,7 @@ ld->size =0; while (fchmod(ld->fdcur, 0644) == -1) pause2("unable to set mode of current", ld->name); - - oldest[0] ='A'; oldest[1] =oldest[27] =0; - while (! (d =opendir("."))) - pause2("unable to open directory, want rotate", ld->name); - errno =0; - while ((f =readdir(d))) - if ((f->d_name[0] == '@') && (str_len(f->d_name) == 27)) { - ++n; - if (str_diff(f->d_name, oldest) < 0) byte_copy(oldest, 27, f->d_name); - } - if (errno) warn2("unable to read directory", ld->name); - closedir(d); - - if (ld->nmax && (n >= ld->nmax)) { - if (verbose) strerr_warn5(INFO, "delete: ", ld->name, "/", oldest, 0); - if ((*oldest == '@') && (unlink(oldest) == -1)) - warn2("unable to unlink oldest logfile", ld->name); - } + rmoldest(ld); processorstart(ld); } @@ -526,6 +538,7 @@ } while ((stat(ld->fnsave, &st) != -1) || (errno != error_noent)); while (rename("current", ld->fnsave) == -1) pause2("unable to rename current", ld->name); + rmoldest(ld); i =-1; } else