Bug 114435
Summary: | svclib_filesystem shell-script include file - problems with | ||||||||
---|---|---|---|---|---|---|---|---|---|
Product: | Red Hat Enterprise Linux 2.1 | Reporter: | Peter Giorgilli <pgiorgilli> | ||||||
Component: | clumanager | Assignee: | Lon Hohberger <lhh> | ||||||
Status: | CLOSED ERRATA | QA Contact: | |||||||
Severity: | medium | Docs Contact: | |||||||
Priority: | medium | ||||||||
Version: | 2.1 | ||||||||
Target Milestone: | --- | ||||||||
Target Release: | --- | ||||||||
Hardware: | i386 | ||||||||
OS: | Linux | ||||||||
Whiteboard: | |||||||||
Fixed In Version: | Doc Type: | Bug Fix | |||||||
Doc Text: | Story Points: | --- | |||||||
Clone Of: | Environment: | ||||||||
Last Closed: | 2004-03-19 15:46:24 UTC | Type: | --- | ||||||
Regression: | --- | Mount Type: | --- | ||||||
Documentation: | --- | CRM: | |||||||
Verified Versions: | Category: | --- | |||||||
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||||
Cloudforms Team: | --- | Target Upstream Version: | |||||||
Embargoed: | |||||||||
Attachments: |
|
Description
Peter Giorgilli
2004-01-28 02:58:33 UTC
Created attachment 97298 [details]
Patch against 1.0.25 to fix problem
Here's a patch against 1.0.25 which fixes the problem. It also appears in
svclib_device.
Thanks for the patch! However, I don't believe the patch addresses the second point in my original bug report. I think you'll find that the code snippet below does not set the value of the "ret_val" variable in the calling shell for the reason already explained. typeset TMPFILE=$(mktemp $TMPFILE_STR; ret_val=$?) Try it yourself. In fact, I don't think it's possible to do what you're trying to do. IMHO, it's better to code this in a more straightforward way a la following: typeset TMPFILE if { ! mktemp $TMPFILE_STR; } then etc... fi Then again, given "mktemp" only returns 0 or 1, you might as well just test whether the string is empty and just leave out the "ret_val" bit all together. The code as it is is misleading. Right, sorry. You're right, the following is not possible: typeset TMPFILE=$(mktemp $TEMPFILE_STR; ret_val=$?) I'm not sure how the author came up with that line. In general, you're more likely to run out of inodes on your file system, in which case, 'mktemp' failing is the least of your worries. ;) I can change the code to fix it so that it will correctly do the assignments. It's not elegant (e.g. still misleading), but it will ensure that the log message actually gets out in the unlikely case that mktemp fails, and has minimal impact on the existing code. Created attachment 97336 [details]
Patch to fix both mktemp / backslash weirdness
Patch against 1.0.25 which fixes both of the potential problems.
Sorry to be a pedant...but it still doesn't work. Here's why: [peterg@aolinux tmp]$ ( cat /etc/redhat-release; echo $SHELL; typeset -i ret_val; typeset SOMEVAR=$(/bin/false); ret_val=$?; echo $ret_val; ) Red Hat Linux release 8.0 (Psyche) /bin/bash 0 [peterg@aolinux tmp]$ ( cat /etc/redhat-release; echo $SHELL; typeset -i ret_val; typeset SOMEVAR=$(/bin/true); ret_val=$?; echo $ret_val; ) Red Hat Linux release 8.0 (Psyche) /bin/bash 0 [peterg@aolinux tmp]$ ( cat /etc/redhat-release; echo $SHELL; typeset -i ret_val; typeset SOMEVAR=$(/bin/anyolthing); ret_val=$?; echo $ret_val; ) Red Hat Linux release 8.0 (Psyche) /bin/bash bash: /bin/anyolthing: No such file or directory 0 [peterg@aolinux tmp]$ ( cat /etc/redhat-release; echo $SHELL; typeset -i ret_val; typeset -abc SOMEVAR=$(/bin/anyolthing); ret_val=$?; echo $ret_val; ) Red Hat Linux release 8.0 (Psyche) /bin/bash bash: /bin/anyolthing: No such file or directory bash: typeset: -b: invalid option typeset: usage: typeset [-afFirtx] [-p] name[=value] ... 2 In other words, it's the exit value of the "typeset" command (which will always be true!) that is being assigned to "ret_val" -- not the "mktemp". IMHO, it's better to omit the "ret_val" all together as it doesn't tell you anything. Ultimately, it's whether the value is non-empty that counts. If you really want to be paranoid you might also test whether the file exists and is a regular file. That is: if ! [[ -n "$tmpfile" && -f "$tmpfile" ]]; then logAndPrint ... fi The typeset lines and assignments are on different lines with the patch applied. The patch makes the code behave in the following manner, to use the above examples: typeset -i ret_val typeset SOMEVAR SOMEVAR=$(/bin/false); ret_val=$? The above causes the correct behavior. Consequently, what the examples above should have done is: ( cat /etc/redhat-release; echo $SHELL; typeset -i ret_val; typeset SOMEVAR; SOMEVAR=$(/bin/false); ret_val=$?; echo $ret_val; ) This works properly: [lhh@eagle lhh]$ ( cat /etc/redhat-release; echo $SHELL; typeset -i ret_val; typeset SOMEVAR; SOMEVAR=$(/bin/false); ret_val=$?; echo $ret_val; ) Red Hat Enterprise Linux WS release 3 (Taroon) /bin/bash 1 [lhh@eagle lhh]$ I should've looked more carefully at the patch! Thanks for the explanation. Case closed! Waiting for erratum / update to close; leaving as 'MODIFIED' for now. Note: This also affects RHEL3 Unable to test this, but the opener seemed to be fine with it. Closing as errata. |