Bug 434781 - The module should use mktemp() or tempfile module to generate temporary file
The module should use mktemp() or tempfile module to generate temporary file
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: rhnlib (Show other bugs)
4.6
All Linux
low Severity low
: rc
: ---
Assigned To: Pradeep Kilambi
Jan Hutař
:
Depends On:
Blocks: 499858
  Show dependency treegraph
 
Reported: 2008-02-25 08:43 EST by Jan Pazdziora
Modified: 2009-05-18 16:14 EDT (History)
4 users (show)

See Also:
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 16:14:51 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Jan Pazdziora 2008-02-25 08:43:17 EST
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 Product and Program Management 2008-02-25 08:48:04 EST
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 01:08:21 EST
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 16:14:51 EDT
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

Note You need to log in before you can comment on or make changes to this bug.