[Solved] Syntax error: bad fd number on shutdown
-
I rebooted my pfSense 2.0.2-RELEASE box tonight and noticed this message as it was shutting down:
pfSense is rebooting now.
Stopping package pfBlocker…done.
Stopping rc.backup_dhcpleases.sh...done.
Stopping rc.backup_rrd.sh...done.
Stopping rc.update_bogons.sh...done.
Syntax error: bad fd numberI'm not sure what "fd number" means.
I ran pfctl -s rules, the firewall is up and running and I didn't see any errors in the rules I've made. I deleted all my customs lists in pfBlocker to see if that was it and still got the same message when I tried rebooting again to check. pfBlocker is the only package I have installed and it's up and blocking traffic like it should as well.
Can anyone shed some light on what it's indicating?
-
That is a "feature" on 2.0.n systems. For some reason the pclose() at the end of /etc/rc.stop_packages emits this message - I never managed to work out why there is a problem. It doesn't matter - the real work is already done and the code is exiting and stopping.
It is "fixed" in 2.1. The body of the code has been moved to a PHP routine stop_packages() and somehow that (or a newer version of PHP, or?) has stopped the message. -
Thanks a lot. I couldn't see anything wrong on my end and it didn't seem to be effecting operation but didn't want to ignore it.
I've seen syntax errors in rules for the pf firewall on my FreeBSD boxes prevent the firewall from loading rules and didn't want to take the chance I was missing something important.
-
It's fixed on 2.0.3, has been for a month or two
It was missing a variable that was causing it to run shutdown scripts from the wrong direcetory (/etc/ rather than /usr/local/etc/rc.d/)
-
I have found what I believe to be a bug in the function stop_packages that is in the file pkg-utils.inc. This is the behavior:
If there is more than one script file in /usr/local/etc/rc.d the call to fwrite throws an error. It doesn't matter if the files are totally empty. I believe there may be a flaw in the logic so I re-wrote some of the function. Not sure exactly how I would submit this find, but the faulty behavior still exists all the up to 2.1RC1. Here is the code I think has a problem:$shell = @popen("/bin/sh", "w");
if ($shell) {
foreach ($rcfiles as $rcfile => $number) {
echo " Stopping {$rcfile}…";
fwrite($shell, "{$rcfile} stop >>/tmp/bootup_messages 2>&1");
echo "done.\n";
}pclose($shell);
}
It looks like the file handle may be going away after the first iteration in the foreach loop. Here is how I changed it:foreach ($rcfiles as $rcfile => $number) {
$shell = @popen("/bin/sh", "w");
if ($shell) {
echo " Stopping {$rcfile}...";
fwrite($shell, "{$rcfile} stop >>/tmp/bootup_messages 2>&1");
echo "done.\n";
pclose($shell);
}
}
This way you are certain to have a good file number, or something because it makes the error go away. To test this behavior I ask anyone with more than one file in the usr/local/etc/rc.d to see if they don't get the same error when shutting down. Syntax error: bad fd number. I tried my fix on version 2.0.3, 2.1RC0 and 2.1RC1. Although the pkg-utils.inc files are not the same, they have the same stop-packages function.
Please feed back here and let me know if I have lost my mind or maybe I found something here. -
It is not fixed in 2.1-release. i got same error. is ceama solution right?
-
I finally found a box that still showed this error on shutdown and was able to confirm that changing the loop in a similar way to ceama's example fixed the problem there. I just committed a fix.