[LinuxCNC/linuxcnc Issue#54] write the parameter file in a safer way

未分类 bolang 4个月前 (10-15) 23次浏览

Issue #54 | 状态: 已关闭 | 作者: SebKuzminsky | 创建时间: 2016-04-12

标签: enhancement task


Currently (as of 2.7.4 and master commit 69e87f99f2) the interpreter saves the parameter file in an unsafe way:
1. rename the current file with a backup extension
2. create a new replacement parameter file by opening it for writing
3. write out the parameters
4. close the file to save it

This is done in src/emc/rs274ngc/rs274ngcpre.cc’s Interp::saveparameters().

This has the danger that something can go wrong after 1 but before 4 (such as the operator removing power to the machine), resulting in corruption.

A safer alternative would be to copy the existing parameter file to a backup, write the new parameter file to a temporary file, then atomically renaming the temporary file to the real parameter file, replacing it.

Another alternative would be to look into a lightweight key/value store, perhaps in a separate process. This would have the benefit of not blocking Task if disk access is slow, which is currently a major source of userspace/non-realtime latency in linuxcnc.

This fix should be made in master, not in a stable/release branch.

原始Issue: https://github.com/LinuxCNC/linuxcnc/issues/54

喜欢 (0)