crmsh icon indicating copy to clipboard operation
crmsh copied to clipboard

Possible race condition in mv_user_files()

Open ip1981 opened this issue 3 years ago • 2 comments

If two or more crm commands executed in parallel one of them may fail:

Traceback (most recent call last):
  File "/usr/sbin/crm", line 61, in <module>
    rc = main.run()
  File "/usr/lib/python2.7/site-packages/crmsh/main.py", line 352, in run
    userdir.mv_user_files()
  File "/usr/lib/python2.7/site-packages/crmsh/userdir.py", line 60, in mv_user_files
    HISTORY_FILE = _xdg_file(HISTORY_FILE, "history", os.path.isfile, CACHE_HOME)
  File "/usr/lib/python2.7/site-packages/crmsh/userdir.py", line 47, in _xdg_file
    os.makedirs(directory, 0o700)
  File "/usr/lib64/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 17] File exists: '/root/.cache/crm'

Probably it's because of a time gap between isdir and makedirs: https://github.com/ClusterLabs/crmsh/blob/d0150a8874d800caf7abb57c8f17e1a73f9dd0a6/crmsh/userdir.py#L50-L51

ip1981 avatar Feb 03 '22 14:02 ip1981

Hi @ip1981 Which version of crmsh you were using?

liangxin1300 avatar Feb 07 '22 00:02 liangxin1300

Package crmsh-3.0.5-0.wc1.noarch, crm --version prints crm 3.0.1. But it does not matter, because the problem is obvious in the current code.

ip1981 avatar Feb 07 '22 08:02 ip1981