Date: Fri, 5 Jan 2007 14:00:22 -0600 From: David Kelly <dkelly@hiwaay.net> To: Andrew Falanga <af300wsm@gmail.com> Cc: freebsd-questions <freebsd-questions@freebsd.org> Subject: Re: Need to make sure my understanding of newsyslog is correct for a daemon I'm writing Message-ID: <20070105200022.GD58672@Grumpy.DynDNS.org> In-Reply-To: <340a29540701051104v28d9f2acx5052485350dde6de@mail.gmail.com> References: <340a29540701051104v28d9f2acx5052485350dde6de@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jan 05, 2007 at 12:04:56PM -0700, Andrew Falanga wrote: > > Basically, I'm installing a signal handler for SIGHUP to do the following: > > reset the put pointer to the beginning of the file; > flush any data that may be in the buffer; > close the file; > reopen file; > > > Does this sound correct? Correct if you desire to truncate your own log file. Don't move to the beginning. Just flush any pending data to exactly where you were going to write them in the first place. > 1) copy file x contents to x.0 Not copy, rename. Can rename a file out from under a process that the process will still have the original (renamed) file open. > 2) truncate file x to zero bytes No, it creates a new file of zero bytes with the original name. > 3) send SIGHUP to process id Yes, and now your process has the renamed x.0 open. SIGHUP is asking you to finish up, close, and open the new x file. You have 10 seconds before the optional compression starts. > Is this how newsyslog would truncate the file? Am I missing something? > Should my signal handler function look differently? You could log by the Open-append, Write, Close, method for each entry. Don't ask newyslog to SIGHUP you at all. Much simpler. Extra open/closes probably don't cost anything measurable. Or you could log via syslogd. -- David Kelly N4HHE, dkelly@HiWAAY.net ======================================================================== Whom computers would destroy, they must first drive mad.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070105200022.GD58672>