]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/safe_io: pass mode to safe_io; use 0600, not 0644 31031/head
authorSage Weil <sage@redhat.com>
Tue, 1 Oct 2019 22:48:11 +0000 (17:48 -0500)
committerNathan Cutler <ncutler@suse.com>
Mon, 21 Oct 2019 21:09:28 +0000 (23:09 +0200)
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit f6e00b96c8802f2205c89cf54fb689bc07436415)

src/common/safe_io.c
src/common/safe_io.h
src/crimson/os/cyan_store.cc
src/mon/MonitorDBStore.h
src/os/ObjectStore.cc
src/os/filestore/FileStore.cc

index 633e3b3e8f06f08ab408fb57622ef8f5fafe7421..22369af38fb7cbdb0bc0ad94f85de93ef67be2aa 100644 (file)
@@ -153,7 +153,8 @@ ssize_t safe_splice_exact(int fd_in, off_t *off_in, int fd_out,
 #endif
 
 int safe_write_file(const char *base, const char *file,
-                   const char *val, size_t vallen)
+                   const char *val, size_t vallen,
+                   unsigned mode)
 {
   int ret;
   char fn[PATH_MAX];
@@ -168,7 +169,7 @@ int safe_write_file(const char *base, const char *file,
 
   snprintf(fn, sizeof(fn), "%s/%s", base, file);
   snprintf(tmp, sizeof(tmp), "%s/%s.tmp", base, file);
-  fd = open(tmp, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+  fd = open(tmp, O_WRONLY|O_CREAT|O_TRUNC, mode);
   if (fd < 0) {
     ret = errno;
     return -ret;
index af8ca700d418113ea1c3c589c23b97fd3ded6e31..7ccbf37b6042e4f819f08c34ee67ecfcf9008dcb 100644 (file)
@@ -62,9 +62,10 @@ extern "C" {
    * Safe functions to read and write an entire file.
    */
   int safe_write_file(const char *base, const char *file,
-                       const char *val, size_t vallen);
+                     const char *val, size_t vallen,
+                     unsigned mode);
   int safe_read_file(const char *base, const char *file,
-                      char *val, size_t vallen);
+                    char *val, size_t vallen);
 
 #ifdef __cplusplus
 }
index adebd41e74bd56befe936fbdf31e45ec7eeed0c1..68ccae88bea655aa4a56a553423a992602718691 100644 (file)
@@ -252,7 +252,7 @@ void CyanStore::write_meta(const std::string& key,
   std::string v = value;
   v += "\n";
   if (int r = safe_write_file(path.c_str(), key.c_str(),
-                              v.c_str(), v.length());
+                              v.c_str(), v.length(), 0600);
       r < 0) {
     throw std::runtime_error{fmt::format("unable to write_meta({})", key)};
   }
index 0561dadf8c8d2748c001211ea8f5b12de685a7a7..c37e4399081777c9a98bd12a420106af3bbcb3ac 100644 (file)
@@ -727,7 +727,8 @@ class MonitorDBStore
     string v = value;
     v += "\n";
     int r = safe_write_file(path.c_str(), key.c_str(),
-                           v.c_str(), v.length());
+                           v.c_str(), v.length(),
+                           0600);
     if (r < 0)
       return r;
     return 0;
index d9b9cf6d1ab65fed44fdccb171a1afe9edace3ac..f9c6073dab60a4035959ae3ddda15caaf136953d 100644 (file)
@@ -129,7 +129,7 @@ int ObjectStore::write_meta(const std::string& key,
   string v = value;
   v += "\n";
   int r = safe_write_file(path.c_str(), key.c_str(),
-                         v.c_str(), v.length());
+                         v.c_str(), v.length(), 0600);
   if (r < 0)
     return r;
   return 0;
index e72f0cc3095e4733918847c4936440ddc6581467..d387947e5d080874697d336cd54c1769c7db3c96 100644 (file)
@@ -1377,7 +1377,7 @@ int FileStore::write_superblock()
   bufferlist bl;
   encode(superblock, bl);
   return safe_write_file(basedir.c_str(), "superblock",
-      bl.c_str(), bl.length());
+                        bl.c_str(), bl.length(), 0600);
 }
 
 int FileStore::read_superblock()
@@ -1462,7 +1462,7 @@ int FileStore::write_version_stamp()
   encode(target_version, bl);
 
   return safe_write_file(basedir.c_str(), "store_version",
-      bl.c_str(), bl.length());
+                        bl.c_str(), bl.length(), 0600);
 }
 
 int FileStore::upgrade()