Index: support/rotatelogs.c =================================================================== --- support/rotatelogs.c (revision 910985) +++ support/rotatelogs.c (working copy) @@ -70,7 +70,7 @@ fprintf(stderr, "%s\n", reason); } fprintf(stderr, - "Usage: %s [-l] [-f] " + "Usage: %s [-l] [-f] [-t] " "{|} " "[offset minutes from UTC]\n\n", argv0); @@ -91,7 +91,10 @@ "starts (N.B. if using a rotation time,\nthe time will always " "be a multiple of the rotation time, so you can synchronize\n" "cron scripts with it). At the end of each rotation time or " - "when the file size\nis reached a new log is started.\n"); + "when the file size\nis reached a new log is started. If the " + "-t option is specified, the specified\nfile will be truncated " + "instead of rotated, and is useful where tail is used to\n" + "process logs in real time.\n"); exit(1); } @@ -122,6 +125,7 @@ int bypass_io = 0; int now = 0; const char *szLogRoot; + int truncate = 0; apr_file_t *f_stdin, *nLogFD = NULL, *nLogFDprev = NULL; apr_pool_t *pool; apr_pool_t *pfile = NULL; @@ -137,7 +141,7 @@ apr_pool_create(&pool, NULL); apr_getopt_init(&opt, pool, argc, argv); - while ((rv = apr_getopt(opt, "lf", &c, &optarg)) == APR_SUCCESS) { + while ((rv = apr_getopt(opt, "lft", &c, &optarg)) == APR_SUCCESS) { switch (c) { case 'l': use_localtime = 1; @@ -145,6 +149,9 @@ case 'f': bypass_io = 1; break; + case 't': + truncate = 1; + break; } } @@ -248,12 +255,18 @@ apr_strftime(buf2, &rs, sizeof(buf2), szLogRoot, &e); } else { - sprintf(buf2, "%s.%010d", szLogRoot, tLogStart); + if (truncate) { + snprintf(buf2, sizeof(buf2), "%s", szLogRoot); + } + else { + snprintf(buf2, sizeof(buf2), "%s.%010d", szLogRoot, + tLogStart); + } } tLogEnd = tLogStart + tRotation; pfile_prev = pfile; apr_pool_create(&pfile, pool); - rv = apr_file_open(&nLogFD, buf2, APR_WRITE | APR_CREATE | APR_APPEND, + rv = apr_file_open(&nLogFD, buf2, APR_WRITE | APR_CREATE | APR_APPEND | (truncate ? APR_TRUNCATE : 0), APR_OS_DEFAULT, pfile); if (rv != APR_SUCCESS) { char error[120];