Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    [Solved] Syntax error: bad fd number on shutdown

    General pfSense Questions
    5
    7
    4.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mr_bobo
      last edited by

      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 number

      I'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?

      1 Reply Last reply Reply Quote 0
      • P
        phil.davis
        last edited by

        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.

        As the Greek philosopher Isosceles used to say, "There are 3 sides to every triangle."
        If I helped you, then help someone else - buy someone a gift from the INF catalog http://secure.inf.org/gifts/usd/

        1 Reply Last reply Reply Quote 0
        • M
          mr_bobo
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • jimpJ
            jimp Rebel Alliance Developer Netgate
            last edited by

            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/)

            Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

            Need help fast? Netgate Global Support!

            Do not Chat/PM for help!

            1 Reply Last reply Reply Quote 0
            • C
              ceama
              last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • ?
                Guest
                last edited by

                It is not fixed in 2.1-release. i got same error. is ceama solution right?

                1 Reply Last reply Reply Quote 0
                • jimpJ
                  jimp Rebel Alliance Developer Netgate
                  last edited by

                  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.

                  Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

                  Need help fast? Netgate Global Support!

                  Do not Chat/PM for help!

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.