[core] Use fd instead of realpath (#1170)

Co-authored-by: LoveSy <shana@zju.edu.cn>
This commit is contained in:
南宫雪珊 2021-09-25 13:57:51 +08:00 committed by GitHub
parent 361e05ea2e
commit 957896fd63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -36,11 +36,16 @@ public class LogcatService implements Runnable {
@SuppressWarnings("unused")
private int refreshFd(boolean isVerboseLog) {
try {
File log = isVerboseLog ? (verboseLog = ConfigFileManager.getNewVerboseLogPath()) :
(modulesLog = ConfigFileManager.getNewModulesLogPath());
File log = isVerboseLog ? ConfigFileManager.getNewVerboseLogPath() : ConfigFileManager.getNewModulesLogPath();
Log.i(TAG, "New " + (isVerboseLog ? "verbose" : "modules") + " log file: " + log);
return ParcelFileDescriptor.open(log, mode).detachFd();
int fd = ParcelFileDescriptor.open(log, mode).detachFd();
var fdFile = new File("/proc/self/fd/" + fd);
if (isVerboseLog) verboseLog = fdFile;
else modulesLog = fdFile;
return fd;
} catch (IOException e) {
if (isVerboseLog) verboseLog = null;
else modulesLog = null;
Log.w(TAG, "someone chattr +i ?", e);
return -1;
}