From bdf93248a30d5deccd493b8e38a3056eb4e87eff Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Sat, 8 Feb 2020 16:44:08 -0800 Subject: [PATCH] snapshotctl logs readable by dumpstate Set persistent logs for snapshotctl to 0644 so that they are readable by dumpstate. Not using mode field in open() because it is masked by umask. Directly use fchmod instead. Test: reboot and take bugreport Bug: 148818798 Change-Id: I515f8fd1345fcfb82aa2a1ec0c95da4b6921c039 --- fs_mgr/libsnapshot/snapshotctl.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fs_mgr/libsnapshot/snapshotctl.cpp b/fs_mgr/libsnapshot/snapshotctl.cpp index d724be390..e35ad4b2d 100644 --- a/fs_mgr/libsnapshot/snapshotctl.cpp +++ b/fs_mgr/libsnapshot/snapshotctl.cpp @@ -61,7 +61,16 @@ class FileLogger { ss << kLogFilePath << "snapshotctl." << Now() << ".log"; fd_.reset(TEMP_FAILURE_RETRY( open(ss.str().c_str(), - O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW | O_SYNC, 0660))); + O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW | O_SYNC, 0644))); + if (fd_ == -1) { + PLOG(ERROR) << "Cannot open persistent log " << ss.str(); + return; + } + // Explicitly chmod again because mode in open() may be masked by umask. + if (fchmod(fd_.get(), 0644) == -1) { + PLOG(ERROR) << "Cannot chmod 0644 persistent log " << ss.str(); + return; + } } // Copy-contuctor needed to be converted to std::function. FileLogger(const FileLogger& other) { fd_.reset(dup(other.fd_)); } @@ -108,7 +117,8 @@ bool MergeCmdHandler(int argc, char** argv) { // 'snapshotctl merge' is stripped away from arguments to // Logger. - android::base::InitLogging(argv, MergeCmdLogger(argc - 2, argv + 2)); + android::base::InitLogging(argv); + android::base::SetLogger(MergeCmdLogger(argc - 2, argv + 2)); auto state = SnapshotManager::New()->InitiateMergeAndWait();