suer のブログ

メモメモ. はてダ → http://d.hatena.ne.jp/suer/

CentOS 5 32bit で fluent-agent-hydra を無理やり動かす

環境

  • CentOS 5.5 (Linux kernel 2.6.18)
  • Go 1.4.2
  • fluent-agent-hydra v0.1.3

問題

Go は CentOS 5 をサポートしていないせいか、 CentOS 5 32bit (Linux kernel 2.6.18) 上で fujiwara/fluent-agent-hydra · GitHub の32bit バイナリを動かすと以下のエラーを吐いて死ぬ。

# /usr/local/bin/fluent-agent-hydra -c /etc/fluent-agent-hydra.toml
2015/06/24 15:14:47 [info] Loading config file: /etc/fluent-agent-hydra.toml
2015/06/24 15:14:47 [info] set ReadBufferSize 1048576
2015/06/24 15:14:47 [info] Server localhost:24224 connected
2015/06/24 15:14:47 [info] ServerRoundRobin enabled
2015/06/24 15:14:47 [error] Couldn't create file watcher function not implemented
2015/06/24 15:14:47 [error] function not implemented
2015/06/24 15:14:47 [info] watching events of directory /var/log/httpd
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x80b3f01]

goroutine 1 [running]:
github.com/fujiwara/fluent-agent-hydra/hydra.(*Watcher).WatchFile(0x0, 0x1894a690, 0x1e, 0x1e, 0x0, 0x0)
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/hydra/in_tail.go:71 +0x151
github.com/fujiwara/fluent-agent-hydra/hydra.NewInTail(0x18944b40, 0x0, 0x18944c40, 0x18944c80, 0x18944c80, 0x0, 0x0)
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/hydra/in_tail.go:105 +0x94
main.run(0x18944880)
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/cmd/fluent-agent-hydra/main.go:127 +0x525
main.main()
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/cmd/fluent-agent-hydra/main.go:69 +0x869

goroutine 6 [syscall]:
os/signal.loop()
        /usr/local/Cellar/go/1.4.2/libexec/src/os/signal/signal_unix.go:21 +0x21
created by os/signal.init·1
        /usr/local/Cellar/go/1.4.2/libexec/src/os/signal/signal_unix.go:27 +0x34

goroutine 7 [chan receive]:
github.com/fujiwara/fluent-agent-hydra/hydra.(*Stats).Run(0x189a0580, 0x18944c80)
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/hydra/monitor.go:115 +0x48
created by github.com/fujiwara/fluent-agent-hydra/hydra.NewMonitor
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/hydra/monitor.go:134 +0x17b

goroutine 14 [runnable]:
github.com/fujiwara/fluent-agent-hydra/hydra.(*OutForward).Run(0x189a1360)
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/hydra/out_forward.go:44
created by main.run
        /Users/fujiwara/src/github.com/fujiwara/fluent-agent-hydra/cmd/fluent-agent-hydra/main.go:117 +0x96d

goroutine 13 [sleep]:
net.func·019()
        /usr/local/Cellar/go/1.4.2/libexec/src/net/dnsclient_unix.go:240 +0x54
created by net.loadConfig
        /usr/local/Cellar/go/1.4.2/libexec/src/net/dnsclient_unix.go:269 +0x1aa

問題の箇所

[error] Couldn't create file watcher function not implemented というエラーメッセージを頼りに追っていくと fsnotify が以下の箇所で syscall.Pipe2 を呼んでいるところでエラーが発生していることを突き止めた。

https://github.com/go-fsnotify/fsnotify/blob/6549b98005f3e4026ad9f50ef7d5011f40ba1397/inotify_poller.go#L47

修正

  • (注意1) Go の流儀をよく理解しないまま対応しているので、もっと良い方法があるかもしれない。
  • (注意2) NONBLOCK でなくなっているので性能が落ちる可能性がある

$GOPATH/src/gopkg.in/fsnotify.v1/inotify_poller.go

diff --git a/inotify_poller.go b/inotify_poller.go
index 3b41784..9f2b172 100644
--- a/inotify_poller.go
+++ b/inotify_poller.go
@@ -44,7 +44,7 @@ func newFdPoller(fd int) (*fdPoller, error) {
                return nil, errno
        }
        // Create pipe; pipe[0] is the read end, pipe[1] the write end.
-       errno = syscall.Pipe2(poller.pipe[:], syscall.O_NONBLOCK)
+       errno = syscall.Pipe(poller.pipe[:])
        if errno != nil {
                return nil, errno
        }

まとめ

さっさと CentOS 6 以上に上げよう。