Added the ability for newsyslog to archive logs with a timestamp, in addition to the normal log rotation. In addition, the number of log files to maintain (numlogs) was not checked and caused newsyslog to hang when it was set to a negative value in /etc/newsyslog.conf. The included patch now checks this value. The man page was also updated to describe the new functionality. Fix: __________________________________________________ Terrorist Attacks on U.S. - How can you help? Donate cash, emergency relief information http://dailynews.yahoo.com/fc/US/Emergency_Information/--uHYHekwYJTD9zH9LQKVJMYrQtyOVSaraT6r1SyB3xtbqS35y Content-Type: text/plain; name="file.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="file.diff" *** newsyslog.c.orig Mon Sep 17 22:20:06 2001 --- newsyslog.c Tue Sep 18 20:26:53 2001 *************** *** 351,357 **** if (!*parse) errx(1, "malformed line (missing fields):\n%s", errline); *parse = '\0'; ! if (!sscanf(q, "%d", &working->numlogs)) errx(1, "error in config file; bad number:\n%s", errline); --- 351,357 ---- if (!*parse) errx(1, "malformed line (missing fields):\n%s", errline); *parse = '\0'; ! if (!sscanf(q, "%d", &working->numlogs) || working->numlogs < -1) errx(1, "error in config file; bad number:\n%s", errline); *************** *** 480,488 **** --- 480,491 ---- char dirpart[MAXPATHLEN], namepart[MAXPATHLEN]; char file1[MAXPATHLEN], file2[MAXPATHLEN]; char zfile1[MAXPATHLEN], zfile2[MAXPATHLEN]; + char tmp[MAXPATHLEN]; + char logdate[BUFSIZ]; int notified, need_notification, fd, _numdays; struct stat st; pid_t pid; + time_t logtime; #ifdef _IBMR2 /* *************** *** 493,498 **** --- 496,504 ---- if (owner_uid == -1) owner_uid = geteuid(); #endif + /* build date extension */ + logtime = time(NULL); + (void) strftime(logdate, BUFSIZ-1, "%Y%m%d%H%M%S", localtime(&logtime)); if (archtodir) { char *p; *************** *** 520,534 **** else strlcpy(namepart, p + 1, sizeof(namepart)); ! /* name of oldest log */ ! (void) snprintf(file1, sizeof(file1), "%s/%s.%d", dirpart, namepart, numdays); (void) snprintf(zfile1, sizeof(zfile1), "%s%s", file1, COMPRESS_POSTFIX); } else { ! /* name of oldest log */ ! (void) snprintf(file1, sizeof(file1), "%s.%d", log, numdays); (void) snprintf(zfile1, sizeof(zfile1), "%s%s", file1, COMPRESS_POSTFIX); } if (noaction) { --- 526,553 ---- else strlcpy(namepart, p + 1, sizeof(namepart)); ! if (numdays > -1) { ! /* name of oldest log */ ! (void) snprintf(file1, sizeof(file1), "%s/%s.%d", dirpart, namepart, numdays); ! } else { ! /* name of dated log */ ! (void) snprintf(file1, sizeof(file1), "%s/%s.%s", dirpart, namepart, logdate); ! } ! /* name of compressed log */ (void) snprintf(zfile1, sizeof(zfile1), "%s%s", file1, COMPRESS_POSTFIX); + } else { ! if (numdays > -1) { ! /* name of oldest log */ ! (void) snprintf(file1, sizeof(file1), "%s/%s.%d", dirpart, namepart, numdays); ! } else { ! /* name of dated log */ ! (void) snprintf(file1, sizeof(file1), "%s.%s", log, logdate); ! } (void) snprintf(zfile1, sizeof(zfile1), "%s%s", file1, COMPRESS_POSTFIX); + } if (noaction) { *************** *** 541,547 **** /* Move down log files */ _numdays = numdays; /* preserve */ ! while (numdays--) { (void) strlcpy(file2, file1, sizeof(file2)); --- 560,566 ---- /* Move down log files */ _numdays = numdays; /* preserve */ ! while (--numdays > 0) { (void) strlcpy(file2, file1, sizeof(file2)); *************** *** 628,634 **** if (need_notification && !notified) warnx("log %s not compressed because daemon not notified", log); else if (noaction) ! printf("Compress %s.0\n", log); else { if (notified) { if (verbose) --- 647,656 ---- if (need_notification && !notified) warnx("log %s not compressed because daemon not notified", log); else if (noaction) ! if (numdays > -1) ! printf("Compress %s.0\n", log); ! else ! printf("Compress %s.%s\n", log, logdate); else { if (notified) { if (verbose) *************** *** 636,645 **** sleep(10); } if (archtodir) { ! (void) snprintf(file1, sizeof(file1), "%s/%s", dirpart, namepart); compress_log(file1); } else { ! compress_log(log); } } } --- 658,671 ---- sleep(10); } if (archtodir) { ! /* (void) snprintf(file1, sizeof(file1), "%s/%s", dirpart, namepart); */ compress_log(file1); } else { ! if (numdays > 0) ! (void) snprintf(tmp, sizeof(tmp), "%s.0", log); ! else ! (void) snprintf(tmp, sizeof(tmp), "%s.%s", log, logdate); ! compress_log(tmp); } } } *************** *** 665,678 **** compress_log(char *log) { pid_t pid; - char tmp[MAXPATHLEN]; - (void) snprintf(tmp, sizeof(tmp), "%s.0", log); pid = fork(); if (pid < 0) err(1, "fork"); else if (!pid) { ! (void) execl(_PATH_GZIP, _PATH_GZIP, "-f", tmp, 0); err(1, _PATH_GZIP); } } --- 691,702 ---- compress_log(char *log) { pid_t pid; pid = fork(); if (pid < 0) err(1, "fork"); else if (!pid) { ! (void) execl(_PATH_GZIP, _PATH_GZIP, "-f", log, 0); err(1, _PATH_GZIP); } } How-To-Repeat: Set the number of log files to maintain to a negative value in /etc/newsyslog.conf and run newsyslog. It will not complete.
Responsible Changed From-To: freebsd-bugs->gad-bugs I'll look into this, as long as I'm working on some other changes to newsyslog.
Responsible Changed From-To: gad-bugs->gad I don't know how I keep changing 'responsible' to 'gad-bugs' when I *meant* to change it to just plain 'gad'...
. I have committed a change to -current which fixes the serious-bug part of this PR, so I have changed the severity to non-critical. I will MFC that to stable. Later on I'll look into the new feature of archiving logs by timestamp. -- Garance Alistair Drosehn = drosih@rpi.edu Senior Systems Programmer or gad@FreeBSD.org Rensselaer Polytechnic Institute; Troy, NY; USA
The bug-fix part of this PR has been MFC'ed to -stable. It may be a few more weeks before I implement some kind of timestamp-logfile ability. -- Garance Alistair Drosehn = gad@FreeBSD.org
I've "ported" the patch to FreeBSD 5.2.1, here it is: -- Sergey Svishchev
For bugs matching the following criteria: Status: In Progress Changed: (is less than) 2014-06-01 Reset to default assignee and clear in-progress tags. Mail being skipped
Npoow newsyslog(8) has "-t timefmt" flag implementing requested feature.