cronologを32bit環境下で動かすときの注意

lighttpdを使ってるとログローテートにcronologをよく使うと風の噂でよく聞きます。

そんなcronologをそのまま32bit環境下で動かすとファイルサイズ2GBを超えて書き込めないですねーというありがたい説法をid:kazuhookuさんにしてもらいました。

要は32bitアプリケーションがopen(2)で2GBを超えるファイルにアクセスするためにはフラグとしてO_LARGEFILEを指定する必要があるのですが、2002-01-24で開発が止まっているcronologはその指定がないのでパッチを当ててやる必要があります。

--- src/cronolog.c.org  2010-02-23 00:49:18.000000000 +0900
+++ src/cronolog.c  2010-02-23 00:50:27.000000000 +0900
@@ -82,6 +82,8 @@
  * written to "file" (e.g. /dev/console) or to stderr if "file" is "-".
  */

+#define _GNU_SOURCE 1
+
 #include "cronoutils.h"
 #include "getopt.h"

@@ -394,13 +396,13 @@
       timestamp(*pnext_period), *pnext_period,
       *pnext_period - time_now));

-    log_fd = open(pfilename, O_WRONLY|O_CREAT|O_APPEND, FILE_MODE);
+    log_fd = open(pfilename, O_WRONLY|O_CREAT|O_APPEND|O_LARGEFILE, FILE_MODE);

 #ifndef DONT_CREATE_SUBDIRS
     if ((log_fd < 0) && (errno == ENOENT))
     {
    create_subdirs(pfilename);
-   log_fd = open(pfilename, O_WRONLY|O_CREAT|O_APPEND, FILE_MODE);
+   log_fd = open(pfilename, O_WRONLY|O_CREAT|O_APPEND|O_LARGEFILE, FILE_MODE);
     }
 #endif

rpmforgeのパッケージにもパッチはあたっていないのでついでにrpmforgeのSPECファイルを変更するとこんな感じ。

# $Id: cronolog.spec 5040 2007-01-02 20:35:37Z dag $
# Authority: dag

Summary: Log file rotator
Name: cronolog
Version: 1.6.2
Release: 1
License: GPL
Group: Applications/File
URL: http://cronolog.org/

Source: http://cronolog.org/download/cronolog-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Patch: cronolog-large-file.patch

%description
cronolog is a simple filter program that reads log file entries from
standard input and writes each entry to the output file specified by
a filename template and the current date and time. When the expanded
filename changes, the current file is closed and a new one opened.

cronolog is intended to be used in conjunction with a Web server,
such as Apache, to split the access log into daily or monthly logs.

%prep
%setup
%patch -p0

%build
%configure
%{__make} %{?_smp_mflags}

%install
%{__rm} -rf %{buildroot}
%{__make} install DESTDIR="%{buildroot}"

%clean
%{__rm} -rf %{buildroot}

%files
%defattr(-, root, root, 0755)
%doc AUTHORS ChangeLog COPYING NEWS README TODO
%doc %{_mandir}/man1/cronolog.1m*
%doc %{_mandir}/man1/cronosplit.1m*
%doc %{_infodir}/cronolog.info*
%{_sbindir}/cronolog
%{_sbindir}/cronosplit

%changelog
* Thu Dec 28 2006 Dag Wieers <dag@wieers.com> - 1.6.2-1
- Initial package. (Contributed by Christoper Maser)

とっとと64bitに移行しなさいという天の声が聞こえました。