diff --git a/twisted/scripts/tap2rpm.py b/twisted/scripts/tap2rpm.py
index a3888a7..3f55840 100755
--- a/twisted/scripts/tap2rpm.py
+++ b/twisted/scripts/tap2rpm.py
@@ -167,8 +167,10 @@ type_dict = {
 
 ##########################
 def makeBuildDir(baseDir):
-    '''Set up the temporary directory for building RPMs.
-    Returns: Tuple: ( buildDir, rpmrcFile )
+    '''
+    Set up the temporary directory for building RPMs.
+
+    Returns: buildDir, a randomly-named subdirectory of baseDir.
     '''
     import random, string
 
@@ -189,21 +191,7 @@ def makeBuildDir(baseDir):
     os.makedirs(os.path.join(tmpDir, 'SOURCES'))
     os.makedirs(os.path.join(tmpDir, 'SRPMS'))
 
-    #  set up rpmmacros file
-    macroFile = os.path.join(tmpDir, 'rpmmacros')
-    rcFile = os.path.join(tmpDir, 'rpmrc')
-    rpmrcData = open('/usr/lib/rpm/rpmrc', 'r').read()
-    rpmrcData = string.replace(rpmrcData, '~/.rpmmacros', macroFile)
-    fp = open(macroFile, 'w')
-    fp.write('%%_topdir %s\n' % tmpDir)
-    fp.close()
-
-    #  set up the rpmrc file
-    fp = open(rcFile, 'w')
-    fp.write(rpmrcData)
-    fp.close()
-
-    return(( tmpDir, rcFile ))
+    return tmpDir
 
 
 ##########
@@ -236,7 +224,7 @@ def run(options=None):
         maintainer = 'tap2rpm'
 
     #  create source archive directory
-    tmp_dir, rpmrc_file = makeBuildDir('/var/tmp')
+    tmp_dir = makeBuildDir('/var/tmp')
     source_dir = os.path.join(tmp_dir, directory)
     os.makedirs(source_dir)
 
@@ -257,7 +245,7 @@ def run(options=None):
     print 'Starting build...'
     print '=' * 70
     sys.stdout.flush()
-    os.system('rpmbuild -ta --rcfile "%s" %s' % ( rpmrc_file, tarfile_name ))
+    os.system('rpmbuild --define "_topdir %s" -ta %s' % ( tmp_dir, tarfile_name ))
     print 'Done with build...'
     print '=' * 70
     
diff --git a/twisted/scripts/test/test_tap2rpm.py b/twisted/scripts/test/test_tap2rpm.py
index 0f8863d..d4ac41a 100644
--- a/twisted/scripts/test/test_tap2rpm.py
+++ b/twisted/scripts/test/test_tap2rpm.py
@@ -7,6 +7,7 @@ Tests for L{twisted.scripts.tap2rpm}.
 from os.path import exists
 from twisted.trial.unittest import TestCase, SkipTest
 from twisted.python import log, procutils
+from twisted.python.failure import Failure
 from twisted.internet import utils
 from twisted.scripts import tap2rpm
 
@@ -80,9 +81,39 @@ def _queryRPMTags(rpmfile, taglist):
 
         return res
 
+    def checkErrorResult(failure):
+        # The current rpm packages on Debian and Ubuntu don't properly set up
+        # the RPM database, which causes rpm to print a harmless warning to
+        # stderr. Unfortunately, .getProcessOutput() assumes all warnings are
+        # catastrophic and panics whenever it sees one.
+        #
+        # See also:
+        #   http://twistedmatrix.com/trac/ticket/3292#comment:42
+        #   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=551669
+        #   http://rpm.org/ticket/106
+
+        failure.trap(IOError)
+
+        # Depending on kernel scheduling, we might read the whole error
+        # message, or only the first few bytes.
+        if str(failure.value).startswith("got stderr: 'error: "):
+            newFailure = Failure(SkipTest("rpm is missing its package "
+                    "database. Run 'sudo rpm -qa > /dev/null' to create one."))
+        else:
+            # Not the exception we were looking for; we should report the
+            # original failure.
+            newFailure = failure
+
+        # We don't want to raise the exception right away; we want to wait for
+        # the process to exit, otherwise we'll get extra useless errors
+        # reported.
+        d = failure.value.processEnded
+        d.addBoth(lambda _: newFailure)
+        return d
+
     d = utils.getProcessOutput("rpm",
             ("-q", "--queryformat", queryFormat, "-p", rpmfile))
-    d.addCallback(parseTagValues)
+    d.addCallbacks(parseTagValues, checkErrorResult)
     return d
 
 
