From: Sage Weil Date: Tue, 1 Oct 2019 22:48:11 +0000 (-0500) Subject: common/safe_io: pass mode to safe_io; use 0600, not 0644 X-Git-Tag: v14.2.5~155^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cecb5328bcce269947385295b95fe467118f62a7;p=ceph.git common/safe_io: pass mode to safe_io; use 0600, not 0644 Signed-off-by: Sage Weil (cherry picked from commit f6e00b96c8802f2205c89cf54fb689bc07436415) --- diff --git a/src/common/safe_io.c b/src/common/safe_io.c index 633e3b3e8f0..22369af38fb 100644 --- a/src/common/safe_io.c +++ b/src/common/safe_io.c @@ -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; diff --git a/src/common/safe_io.h b/src/common/safe_io.h index af8ca700d41..7ccbf37b604 100644 --- a/src/common/safe_io.h +++ b/src/common/safe_io.h @@ -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 } diff --git a/src/crimson/os/cyan_store.cc b/src/crimson/os/cyan_store.cc index adebd41e74b..68ccae88bea 100644 --- a/src/crimson/os/cyan_store.cc +++ b/src/crimson/os/cyan_store.cc @@ -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)}; } diff --git a/src/mon/MonitorDBStore.h b/src/mon/MonitorDBStore.h index 0561dadf8c8..c37e4399081 100644 --- a/src/mon/MonitorDBStore.h +++ b/src/mon/MonitorDBStore.h @@ -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; diff --git a/src/os/ObjectStore.cc b/src/os/ObjectStore.cc index d9b9cf6d1ab..f9c6073dab6 100644 --- a/src/os/ObjectStore.cc +++ b/src/os/ObjectStore.cc @@ -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; diff --git a/src/os/filestore/FileStore.cc b/src/os/filestore/FileStore.cc index e72f0cc3095..d387947e5d0 100644 --- a/src/os/filestore/FileStore.cc +++ b/src/os/filestore/FileStore.cc @@ -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()