Project

General

Profile

Actions

Bug #3139

closed

pkg-utils function stop_packages causes Syntax error bad fd number with more than one script file.

Added by Charlie Singleton almost 11 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
08/10/2013
Due date:
% Done:

0%

Estimated time:
Plus Target Version:
Release Notes:
Affected Version:
All
Affected Architecture:
All

Description

Call to function fwrite throws error if more than 1 file exists in /usr/local/etc/rc.d. Testing this, even empty files named .sh will produce the error. This is the same error, Syntax error bad fd number, that was caused by another problem but seems unrelated to this problem I can reproduce all the up to version 2.1RC1. I believe there may be an error in logic in the following loop in pkg-utils function stop_packages.

$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);
}

The first time fwrite is called all is well but the 2nd and subsequent iterations cause the error. I re-wrote just this one small portion of the code and made the error go away.

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 gives the fwrite function a fresh shell handle on each file? This may not be the best way to fix it, but it illustrates the problem and a possible cure. I know this is a small detail but I wanted to submit it.
Actions #1

Updated by Ermal Luçi almost 11 years ago

I still do not see the issue here!
Does the fwrite terminate execution of the script or something else i am missing?

Actions #2

Updated by Charlie Singleton almost 11 years ago

Sorry I left out the condition you see the error. Put 2 .sh scripts in the /usr/etc/rc.d directory. Then go to a serial terminal or VGA terminal and select 5 or 6 to shut down or restart. Here is my output from a NanoBSD serial console:
--------------------------------------------------------------------------
Enter an option: 6

pfSense will shutdown and halt system. This may take one minute.

Do you want to proceed [y|n]? y

pfSense will shutdown and halt system now.
Stopping /usr/local/etc/rc.d/WGXepc.sh...done.
Stopping /usr/local/etc/rc.d/lcdd.sh...done.
Syntax error: Bad fd number
  • Welcome to pfSense 2.0.3-RELEASE-nanobsd (i386) on pfSense ***
WAN (wan)                 > re0        -> 192.168.0.11 (DHCP)
LAN (lan) -> re1 -> 192.168.5.100
OPT1 (opt1) -> re2 -> NONE
OPT2 (opt2) -> re3 -> NONE
OPT3 (opt3) -> re4 -> NONE
OPT4 (opt4) -> re5 -> NONE
---------------------------------------------------------------------

It doesn't matter what is in the .sh file, it can even be empty and the error, "Syntax error: Bad fd number" generates on the second file at shutdown.
Actions #3

Updated by Renato Botelho over 10 years ago

  • Status changed from New to Feedback

Did the committed change fix the issue?

Actions #4

Updated by Charlie Singleton over 10 years ago

What was changed? Excuse my ignorance. I am new to reporting issues. The code I submitted does fix the issue. Are you talking about another change?

Actions #5

Updated by Renato Botelho over 10 years ago

Charlie Singleton wrote:

What was changed? Excuse my ignorance. I am new to reporting issues. The code I submitted does fix the issue. Are you talking about another change?

A different patch was committed, it's listed on "Associated Revisions", here at the ticket page. Here is a link to patch:

http://redmine.pfsense.org/projects/pfsense/repository/revisions/61ef13853f8bd1c02e323b36973b581348ffb805

Actions #6

Updated by Charlie Singleton over 10 years ago

I replaced just the stop_packages function in 2.0.3 Release with the committed function and it does not fix the issue. Did something else change or was it just the changes to the stop_packages function?

Actions #7

Updated by Charlie Singleton over 10 years ago

Just to clarify, I did make the changes and they do not fix the issue. I see now in the "diff" it is clear exactly what was changed in the stop_packages function. This does not fix the issue. The error still is displayed when more than one .sh file is in the /usr/local/etc/rc.d directory at shutdown.

Actions #8

Updated by Charlie Singleton over 10 years ago

I downloaded the snapshot created yesterday and the problem is still there. I checked "etc/inc/pkg-utils.inc" and the changes are there but did not fix the problem.

Actions #10

Updated by Jim Pingle about 7 years ago

  • Status changed from Feedback to Closed
Actions

Also available in: Atom PDF