Revision 8342c325

b/lib/daemon.py
681 681

  
682 682
    exec_fn(options, args, prep_results)
683 683
  finally:
684
    utils.RemovePidFile(daemon_name)
684
    utils.RemovePidFile(utils.DaemonPidFileName(daemon_name))
b/lib/utils/__init__.py
2025 2025
def WritePidFile(pidfile):
2026 2026
  """Write the current process pidfile.
2027 2027

  
2028
  @type pidfile: sting
2028
  @type pidfile: string
2029 2029
  @param pidfile: the path to the file to be written
2030 2030
  @raise errors.LockError: if the pid file already exists and
2031 2031
      points to a live process
......
2049 2049
  return fd_pidfile
2050 2050

  
2051 2051

  
2052
def RemovePidFile(name):
2052
def RemovePidFile(pidfile):
2053 2053
  """Remove the current process pidfile.
2054 2054

  
2055 2055
  Any errors are ignored.
2056 2056

  
2057
  @type name: str
2058
  @param name: the daemon name used to derive the pidfile name
2057
  @type pidfile: string
2058
  @param pidfile: Path to the file to be removed
2059 2059

  
2060 2060
  """
2061
  pidfilename = DaemonPidFileName(name)
2062 2061
  # TODO: we could check here that the file contains our pid
2063 2062
  try:
2064
    RemoveFile(pidfilename)
2065
  except: # pylint: disable-msg=W0702
2063
    RemoveFile(pidfile)
2064
  except Exception: # pylint: disable-msg=W0703
2066 2065
    pass
2067 2066

  
2068 2067

  
b/test/ganeti.utils_unittest.py
174 174
  def setUp(self):
175 175
    self.dir = tempfile.mkdtemp()
176 176
    self.f_dpn = lambda name: os.path.join(self.dir, "%s.pid" % name)
177
    utils.DaemonPidFileName = self.f_dpn
178 177

  
179 178
  def testPidFileFunctions(self):
180 179
    pid_file = self.f_dpn('test')
......
187 186
    self.failUnlessRaises(errors.LockError, utils.WritePidFile,
188 187
                          self.f_dpn('test'))
189 188
    os.close(fd)
190
    utils.RemovePidFile('test')
189
    utils.RemovePidFile(self.f_dpn("test"))
191 190
    self.failIf(os.path.exists(pid_file),
192 191
                "PID file should not exist anymore")
193 192
    self.failUnlessEqual(utils.ReadPidFile(pid_file), 0,
......
200 199
    # but now, even with the file existing, we should be able to lock it
201 200
    fd = utils.WritePidFile(self.f_dpn('test'))
202 201
    os.close(fd)
203
    utils.RemovePidFile('test')
202
    utils.RemovePidFile(self.f_dpn("test"))
204 203
    self.failIf(os.path.exists(pid_file),
205 204
                "PID file should not exist anymore")
206 205

  
......
222 221
    self.failUnless(utils.IsProcessAlive(new_pid))
223 222
    utils.KillProcess(new_pid, waitpid=True)
224 223
    self.failIf(utils.IsProcessAlive(new_pid))
225
    utils.RemovePidFile('child')
224
    utils.RemovePidFile(self.f_dpn('child'))
226 225
    self.failUnlessRaises(errors.ProgrammerError, utils.KillProcess, 0)
227 226

  
228 227
  def tearDown(self):

Also available in: Unified diff