From owner-freebsd-hackers Thu Dec 21 02:44:47 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id CAA29858 for hackers-outgoing; Thu, 21 Dec 1995 02:44:47 -0800 (PST) Received: from DATAPLEX.NET (SHARK.DATAPLEX.NET [199.183.109.241]) by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id CAA29837 for ; Thu, 21 Dec 1995 02:44:37 -0800 (PST) Received: from [199.183.109.242] by DATAPLEX.NET with SMTP (MailShare 1.0fc5); Thu, 21 Dec 1995 04:44:20 -0600 X-Sender: rkw@shark.dataplex.net Message-Id: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Thu, 21 Dec 1995 04:44:24 -0600 To: =?KOI8-R?Q?=E1=CE=C4=D2=C5=CA_=FE=C5=D2=CE=CF=D7?=(aka Andrey A. Chernov, Black Mage) From: rkw@dataplex.net (Richard Wackerbarth) Subject: Re: weekly/monthly logs rotating idea (commit candidate) Cc: hackers@freebsd.org Sender: owner-hackers@freebsd.org Precedence: bulk OBJECTION!!!!!!!! We do not have locking on the logs. As a result, there is a race condition in your code. The daemon wants to write a multi-write message to the log. An incomplete message ends up in the log. Or worse yet, a message gets lost entirely between the copy and the truncate. The present code is correct with the addition of the "restart" event (SIG-HUP?) to tell the daemon to reopen its log file. >Current logs rotating code > ... > if [ -f $i.1 ]; then mv -f $i.1 $i.2; fi > if [ -f $i.0 ]; then mv -f $i.0 $i.1; fi > if [ -f $i ]; then mv -f $i $i.0; fi > >$i >isn't good for daemons, because thet keep log descriptor open. >It means that daemon_log moved to daemon_log.0 and diagnostics >still writted to daemon_log.0! New daemon_log leaves zero-sized >until reboot. > >What I suggest: > > if [ -f $i.0 ]; then mv -f $i.0 $i.1; fi > if [ -f $i ]; then cp -fp $i $i.0; fi > >$i > >It means that you copy log preserving file times and then >zero the same descriptor. > >If I not see objections with explanations, I plan to commit it. ---- Richard Wackerbarth rkw@dataplex.net