From f6e00b96c8802f2205c89cf54fb689bc07436415 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 1 Oct 2019 17:48:11 -0500 Subject: [PATCH] common/safe_io: pass mode to safe_io; use 0600, not 0644 Signed-off-by: Sage Weil --- src/common/safe_io.c | 5 +++-- src/common/safe_io.h | 5 +++-- src/crimson/os/cyan_store.cc | 2 +- src/mon/MonitorDBStore.h | 3 ++- src/os/ObjectStore.cc | 2 +- src/os/filestore/FileStore.cc | 4 ++-- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/common/safe_io.c b/src/common/safe_io.c index 633e3b3e8f06..22369af38fb7 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 af8ca700d418..7ccbf37b6042 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 f0749cb921f9..44d6bff32d4e 100644 --- a/src/crimson/os/cyan_store.cc +++ b/src/crimson/os/cyan_store.cc @@ -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)}; } diff --git a/src/mon/MonitorDBStore.h b/src/mon/MonitorDBStore.h index d7782de9890e..9a47f58282ff 100644 --- a/src/mon/MonitorDBStore.h +++ b/src/mon/MonitorDBStore.h @@ -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; diff --git a/src/os/ObjectStore.cc b/src/os/ObjectStore.cc index 5c555ec77c53..05637f2a208d 100644 --- a/src/os/ObjectStore.cc +++ b/src/os/ObjectStore.cc @@ -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; diff --git a/src/os/filestore/FileStore.cc b/src/os/filestore/FileStore.cc index 42d4b3130693..db949dfe086d 100644 --- a/src/os/filestore/FileStore.cc +++ b/src/os/filestore/FileStore.cc @@ -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() -- 2.47.3