Browse files

mogstored: fix kqueue usage with daemonization

Calling Mogstored::HTTPServer::Perlbal->start() creates a kqueue
descriptor.  kqueue descriptors are invalidated across fork,
so we must avoid kqueue creation until after daemonization.

We continue starting non-Perlbal HTTP servers before
daemonization, as error reporting can be easier if stderr/stdout
are not redirected to /dev/null.

  • Loading branch information...
Eric Wong
Eric Wong committed Jan 18, 2013
1 parent c23cc6b commit d8de2baa06cca3fd4059ad580b39541acea3e4d8
Showing with 10 additions and 1 deletion.
  1. +10 −1 mogstored
@@ -97,7 +97,13 @@ my $httpsrv = $httpsrv_class->new(
maxconns => $max_conns,
bin => $serverbin,
+# Configure Perlbal HTTP listener after daemonization since it can create a
+# kqueue on *BSD. kqueue descriptors are automatically invalidated on fork(),
+# making them unusable after daemonize. For non-Perlbal, starting the
+# server before daemonization improves error reporting as daemonization
+# redirects stdout/stderr to /dev/null.
+$httpsrv->start if $server ne "perlbal";
if ($opt_daemonize) {
@@ -106,6 +112,9 @@ if ($opt_daemonize) {
print "Running.\n";
+# It is now safe for Perlbal to create a kqueue
+$httpsrv->start if $server eq "perlbal";
# kill our children processes on exit:

0 comments on commit d8de2ba

Please sign in to comment.