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 over 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

Also available in: Atom PDF