From: Michael Vrable Date: Wed, 30 May 2007 15:51:50 +0000 (-0700) Subject: Check for errors when files are opened for dumping. X-Git-Url: http://git.vrable.net/?p=cumulus.git;a=commitdiff_plain;h=6b00faf9826faa0013e8cccc55086724f37c44e5 Check for errors when files are opened for dumping. Before, we could fail to open a file when O_NOATIME was specified but the file was owned by another user, and we didn't notice this. Now we do, and we also retry the open without O_NOATIME. --- diff --git a/scandir.cc b/scandir.cc index 9a590ba..26b83ed 100644 --- a/scandir.cc +++ b/scandir.cc @@ -283,8 +283,16 @@ void scanfile(const string& path) * - O_NONBLOCK: prevents open() from blocking if the file was * replaced by a fifo * We also add in O_NOATIME, since this may reduce disk writes (for - * inode updates). */ + * inode updates). However, O_NOATIME may result in EPERM, so if the + * initial open fails, try again without O_NOATIME. */ fd = open(path.c_str(), O_RDONLY|O_NOATIME|O_NOFOLLOW|O_NONBLOCK); + if (fd < 0) { + fd = open(path.c_str(), O_RDONLY|O_NOFOLLOW|O_NONBLOCK); + } + if (fd < 0) { + fprintf(stderr, "Unable to open file %s: %m\n", path.c_str()); + return; + } /* Drop the use of the O_NONBLOCK flag; we only wanted that for file * open. */