depmod: prevent module dependency files corruption due to parallel invocation.
authorMichal Suchanek <msuchanek@suse.de>
Mon, 17 Dec 2018 22:46:28 +0000 (23:46 +0100)
committerLucas De Marchi <lucas.demarchi@intel.com>
Mon, 17 Dec 2018 23:10:05 +0000 (15:10 -0800)
commita06bacf500d56b72b5f9b121ebf7f6af9e3df185
tree13b4e7f4a9577ad04960759dd7b96219f5ed05e8
parentc2996b5fa880e81f63c25e80a4157b2239e32c5d
depmod: prevent module dependency files corruption due to parallel invocation.

Depmod does not use unique filename for temporary files. There is no
guarantee the user does not attempt to run mutiple depmod processes in
parallel. If that happens a temporary file might be created by
depmod(1st), truncated by depmod(2nd), and renamed to final name by
depmod(1st) resulting in corrupted file seen by user.

Due to missing mkstempat() this is more complex than it should be.
Adding PID and timestamp to the filename should be reasonably reliable.
Adding O_EXCL as mkstemp does fails creating the file rather than
corrupting existing file.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
tools/depmod.c