Bug 434781

Summary: The module should use mktemp() or tempfile module to generate temporary file
Product: Red Hat Enterprise Linux 4 Reporter: Jan Pazdziora <jpazdziora>
Component: rhnlibAssignee: Pradeep Kilambi <pkilambi>
Status: CLOSED ERRATA QA Contact: Jan Hutaƙ <jhutar>
Severity: low Docs Contact:
Priority: low    
Version: 4.6CC: bperkins, jhutar, pthomas, sstover
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
* the SmartIO.py module would attempt to open a file in /tmp. If it did not succeed, it would enter a loop and make multiple attempts to open the same file. If these all failed, the module would exit with an error. The module provided in this updated package instead uses mkstemp to create a file with a unique filename. This has a greater chance of success and uses system resources more efficiently.
Story Points: ---
Clone Of:
: 499858 (view as bug list) Environment:
Last Closed: 2009-05-18 20:14:51 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:
Bug Depends On:    
Bug Blocks: 499858    

Description Jan Pazdziora 2008-02-25 13:43:17 UTC
Description of problem:

In the function _tempfile, there is a loop which tries to open the same file in
/tmp a number of times:

# Creates a temporary file and passes back its file descriptor
def _tempfile(tmpdir='/tmp'):
    # Try to create the file a couple of times
    filename = "%s/_rhn_transports-%d" % (tmpdir, os.getpid())
    for i in range(5):
        try:
            fd = os.open(filename, os.O_CREAT | os.O_RDWR | os.O_EXCL)
        except OSError, e:
            if e.errno == 17:
                # File exists
                filename = "%s-%.5f" % (filename, time.time() % 10)
                continue
            # Another error, raise it
            raise
        else:
            break
    else:
        # Failed to get the temp file
        raise IOError, "Could not create temporary file"

    # To make sure it's a temp file, unlink it
    os.unlink(filename)

    # Convert the file descriptor into a stream
    f = os.fdopen(fd, "wb+")
    return f

We should really use mktemp(), mkstemp() or something similar.

Version-Release number of selected component (if applicable):

# rpm -qf /usr/lib/python2.3/site-packages/rhn/SmartIO.py
rhnlib-2.1.1-9.el4_6

How reproducible:

I looked at the code.

Steps to Reproduce:
1. Look into SmartIO.py.
  
Actual results:

See loop.

Expected results:

Do not see loop.

Additional info:

Comment 1 RHEL Program Management 2008-02-25 13:48:04 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release.  Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products.  This request is not yet committed for inclusion in an Update
release.

Comment 5 Ruediger Landmann 2009-01-12 06:08:21 UTC
Release note added. If any revisions are required, please set the 
"requires_release_notes" flag to "?" and edit the "Release Notes" field accordingly.
All revisions will be proofread by the Engineering Content Services team.

New Contents:
* the SmartIO.py module would attempt to open a file in /tmp. If it did not succeed, it would enter a loop and make multiple attempts to open the same file. If these all failed, the module would exit with an error. The module provided in this updated package instead uses mkstemp to create a file with a unique filename. This has a greater chance of success and uses system resources more efficiently.

Comment 9 errata-xmlrpc 2009-05-18 20:14:51 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2009-0974.html