rpmbuild not stopping on error

General support questions including new installations
Post Reply
mrspot
Posts: 11
Joined: 2008/11/06 22:00:53
Location: California

rpmbuild not stopping on error

Post by mrspot » 2011/10/26 23:09:21

The %build phase of my spec has a 'while' loop which calls a shell script (named "[i]module_build[/i]") to make drivers. If the [i]module_build[/i] script exits with error, then rpmbuild exits the loop immediately but does not stop. When the [i]module_build[/i] script is NOT in a loop, rpmbuild detects the error correctly and stops. How do I make rpmbuild see the error while looping?

The [i]module_build[/i] script uses this error-exit function:
[code]function error_exit
{
echo "ERROR: ${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
exit 1
}[/code]

The rpmbuild spec runs [i]module_build[/i] like this:
[code]%build
grep System.KernelVersion myfile |sed -e 's/,/\n/g' |sort -u |grep -vE 'System.KernelVersion|none' |
while read branding_kernel_version
do
bin/dne_module_build ${branding_kernel_version}
done[/code]

I've tried adding a test inside the spec file while loop, like this (with echoes added to show control flow)
[code]while read branding_kernel_version
do
echo Building modules for ${branding_kernel_version}
bin/module_build ${branding_kernel_version}
echo after module_build
if [ $? -ne 0 ]
then
echo "ne 0"
exit 2
fi
done
echo after done[/code]

which seems to show that the loop is exited immediately after getting the error:

[code]+ read branding_kernel_version
+ echo Building modules for 2.6.18.128-2_wsxen
Building modules for 2.6.18.128-2_wsxen
+ bin/module_build 2.6.18.128-2_wsxen
<<[i]next three lines come from module_build[/i]>>
+ echo 'ERROR: module_build: kernel version modules must be present in /lib/modules'
ERROR: module_build: kernel version modules must be present in /lib/modules
+ exit 1
+ echo after done
after done[/code]

(Note that "exit 1" comes from the [i]module_build[/i] script, not from the spec file test, and the test in the while loop is not shown at all)

Grasping at straws, I tried putting the test after the loop, but it doesn't see the error exit code:

[code]while read branding_kernel_version
do
echo Building modules for ${branding_kernel_version}
bin/module_build ${branding_kernel_version}
echo after module_build
done
echo after done
if [ $? -ne 0 ]
then
echo "ne 0"
exit 2
fi
echo "FINISHED"[/code]

which gives output

[code]+ read branding_kernel_version
+ echo Building modules for 2.6.18.128-2_wsxen
Building modules for 2.6.18.128-2_wsxen
+ bin/module_build 2.6.18.128-2_wsxen
+ echo 'ERROR: module_build: kernel version modules must be present in /lib/modules'
ERROR: module_build: kernel version modules must be present in /lib/modules
+ exit 1
+ echo after done
after done
+ '[' 0 -ne 0 ']'
+ echo 'FINISHED'[/code]

I'm using rpmbuild (RPM) version 4.3.3 on CentOS 4.1 (cannot move to 5.x for a few months yet)
Any ideas will be much appreciated!
Thanks

User avatar
TrevorH
Forum Moderator
Posts: 29166
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: rpmbuild not stopping on error

Post by TrevorH » 2011/10/27 00:19:40

[quote]
echo after done
if [ $? -ne 0 ]
[/quote]

You're testing the result of the [u]echo[/u] line ...

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

rpmbuild not stopping on error

Post by pschaff » 2011/10/27 14:45:33

Looks like Trevor has the answer to your question; however, I can't resist... :-)

[quote]
mrspot wrote:
...
I'm using rpmbuild (RPM) version 4.3.3 on CentOS 4.1 (cannot move to 5.x for a few months yet)
[/quote]
You could at least update to 4.9 - 4.1 is severely obsolete, buggy, and insecure, and consequently unsupported.

Post Reply

Return to “CentOS 4 - General Support”