c - Is rename required by standard to be atomic? -
an interesting question arose while trying answer this:
is rename() function required atomic standard?
the 'rationale' section of posix standard rename states:
this
rename()function equivalent regular files defined iso c standard. inclusion here expands definition include actions on directories , specifies behavior when new parameter names file exists. that specification requires action of function atomic.
but, latest publicly-available iso c standard section on rename, in entirety, states:
7.21.4.2
renamefunctionsynopsis
#include <stdio.h> int rename(const char *old, const char *new);description
the
renamefunction causes file name string pointedoldhenceforth known name given string pointednew. file namedoldno longer accessible name. if file named string pointednewexists prior callrenamefunction, behavior implementation-defined.returns
the
renamefunction returns 0 if operation succeeds, nonzero if fails, in case if file existed still known original name.
there's no explicit requirement of kind type of atomicity in rename() section of iso c standard.
having written many programs relied upon apparently implementation-specific atomicity of rename(), had assumed atomicity requirement , surprised lack in c standard.
but posix standard says iso c standard requires rename() atomic.
explanation(s)?
your quote posix standard rename() comes (non-normative) 'rationale' section. main entry — actual normative material — begins:
for rename(): [cx]
functionality described on reference page aligned iso c standard. conflict between requirements described here , iso c standard unintentional. volume of posix.1-2008 defers iso c standard.
the
rename()function shall change name of file.oldargument points pathname of file renamed.newargument points new pathname of file. [cx]if
newargument not resolve existing directory entry file of type directory ,newargument contains @ least 1 non-<slash>character , ends 1 or more trailing<slash>characters after symbolic links have been processed,rename()shall fail.…
all rest of entry within [cx] (c extension) tag , discusses other special behaviours.
the rationale quote says:
this
rename()function equivalent regular files defined iso c standard. inclusion here expands definition include actions on directories , specifies behavior when new parameter names file exists. specification requires action of function atomic.
the 'that specification' referred in last sentence expanded definition includes specification of actions on directories , 'when new parameter names file exists', not specification in c standard which, observe, not atomicity (very reasonably; there systems can support c , rename() without being able support posix's more stringent atomicity requirement).
functionality described on reference page aligned iso c standard. conflict between requirements described here , iso c standard unintentional. volume of posix.1-2008 defers iso c standard. ![[option end]](https://i.stack.imgur.com/fwk9w.gif)
Comments
Post a Comment