ClusterLabs / crmsh

Command-line interface for High-Availability cluster management on GNU/Linux systems.
GNU General Public License v2.0
131 stars 94 forks source link

Possible race condition in mv_user_files() #936

Closed ip1981 closed 1 year ago

ip1981 commented 2 years ago

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

liangxin1300 commented 2 years ago

Hi @ip1981 Which version of crmsh you were using?

ip1981 commented 2 years ago

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.