Stunnelでちょっとはまる

http://d.hatena.ne.jp/tokuhirom/20071112/1194867921 をみて、Perlで対応しなくても Stunnel でトンネル掘ればいいんじゃないか、というのは知識として知ってはいたけど実際に Stunnel を動かしたことはないので動かしてみたらちょっとはまった(長い)。

OSX leopard で、

$ tar zxvf stunnel-4.21.tar.gz
$ cd stunnel-4.21
$ ./configure
$ make
# make install

pop3s_stunnel.conf

client=yes
debug=debug
[pop_server]
accept=8110
connect=pop3s.example.com:995

で起動すると

$ stunell pop3s_stunnel.conf
2007.11.13 03:25:57 LOG7[9458:2684825440]: Snagged 64 random bytes from /Users/fujiwara/.rnd
2007.11.13 03:25:57 LOG7[9458:2684825440]: Wrote 1024 new random bytes to /Users/fujiwara/.rnd
2007.11.13 03:25:57 LOG7[9458:2684825440]: RAND_status claims sufficient entropy for the PRNG
2007.11.13 03:25:57 LOG7[9458:2684825440]: PRNG seeded successfully
2007.11.13 03:25:57 LOG7[9458:2684825440]: SSL context initialized for service pop_server

一見エラーなく起動した風に見えるが、プロセスは落ちている。なんで?

原因は /var/log/system.log に出ていた。(これに気が付くまであちこちググったり……

Nov 13 03:34:00 white stunnel[8862]: LOG3[8862:2684825440]: Cannot create pid file /usr/local/var/run/stunnel/stunnel.pid
Nov 13 03:34:00 white stunnel[8862]: LOG3[8862:2684825440]: create: No such file or directory (2)

/usr/local/var/run/stunnel ディレクトリが存在しなかったため。
ディレクトリを作ってパーミッションも与えたら動いた。
# Linuxだと /var/log/messages に出ます。コンソールにデバッグログを吐くのにエラーログは syslog only とは……