]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/safe_io: pass mode to safe_io; use 0600, not 0644 30679/head
authorSage Weil <sage@redhat.com>
Tue, 1 Oct 2019 22:48:11 +0000 (17:48 -0500)
committerSage Weil <sage@redhat.com>
Tue, 1 Oct 2019 22:55:13 +0000 (17:55 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
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 f0749cb921f909ae26fd26cde691b24b18466c5a..44d6bff32d4e45e91ac246560d6d0dd84fbc6f77 100644 (file)
@@ -615,7 +615,7 @@ seastar::future<> 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 d7782de9890edea837d0e17014374255a050d1fe..9a47f58282ffb38eee18d9218c00344161aadbf7 100644 (file)
@@ -754,7 +754,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 5c555ec77c53b1d03dcd4fe28d1ed68446cc2377..05637f2a208dfaf571282d30cddd9c2b0517ba78 100644 (file)
@@ -94,7 +94,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 42d4b3130693b2445792c74d2e361bd3a6de17db..db949dfe086dc4ba5921d1a3dd348af785f1e730 100644 (file)
@@ -1374,7 +1374,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()
@@ -1459,7 +1459,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()