SELinux有効化後 cgiが動かなくなった

自分のサーバで掲示板のようなcgiを動かしているのだが、SELinux有効化後に投稿したらInternal Server Errorになった。 特に何も変更していないので、すぐに「SELinuxのせいだ!」と思い、/var/log/messagesを見る。
Apr 30 05:16:08 god setroubleshoot[243206]: 
SELinux is preventing post.cgi from write access on the file temp.txt.
#012
#012*****  Plugin catchall (100. confidence) suggests   **************************
#012
#012If you believe that post.cgi should be allowed write access on the temp.txt file by default.
#012Then you should report this as a bug.
#012You can generate a local policy module to allow this access.
#012Do
#012allow this access for now by executing:
#012# ausearch -c 'post.cgi' --raw | audit2allow -M my-postcgi
#012# semodule -X 300 -i my-postcgi.pp
#012
cgiがファイルに書き込むことが許可されていない。 そして、それを許可するようにする方法も書かれている。 ausearchで問題が起きているcgiファイルを探して、パイプで audit2allowに渡してmoduleを作成し、 semoduleでそれをinsallする、ということのようだ。
# ausearch -c 'post.cgi' --raw | audit2allow -M my-postcgi
******************** 重要 ***********************
このポリシーパッケージを有効にするには、以下を実行して下さい:

semodule -i my-postcgi.pp

言われたとおりに

# semodule -i my-postcgi.pp

messagesには

semodule -X 300 -i my-postcgi.pp

と書いてあるが、-Xというのはpriorityを指定するオプションのようだ。

が、-Xなしで実行し、同様のcgiがもう一個あったのでそれも同様にすると、掲示板に投稿できるようになった。

そもそもなんでこのcgiがSELinuxで止められたかであるが、それにはちょっと心当たりがあって、 このcgiを作った時にファイルに書き込みができないということが起きて、権限の問題だろうということで、 よくわからないのでとにかくなんでもありの権限や所有者設定にしたのを覚えている。 おそらくそういう適当な権限設定のファイルを扱ったのでSELinuxが止めたのだと思う。

多分、cgi実行ユーザとファイル所有者が違う、とかいうことじゃないかと思うが、今回はめんどくさいのでこのまま許可してしまう。