From d98697009f2a75f0e9d92f13c5916c8916dbb587 Mon Sep 17 00:00:00 2001 From: Woongsuk Cho Date: Wed, 9 Jun 2021 15:24:29 +0900 Subject: [PATCH] change fprintf to _SERR and _SOUT --- NativeLauncher/launcher/exec/corerun.cc | 35 ++++++------ NativeLauncher/tool/dotnettool.cc | 57 +++++++++---------- NativeLauncher/tool/multi_target_resolver.cc | 4 +- NativeLauncher/tool/ni_common.cc | 82 ++++++++++++++-------------- NativeLauncher/tool/nitool.cc | 14 ++--- NativeLauncher/tool/tac_common.cc | 72 ++++++++++++------------ NativeLauncher/tool/tpatool.cc | 5 +- NativeLauncher/util/utils.cc | 8 +-- 8 files changed, 140 insertions(+), 137 deletions(-) diff --git a/NativeLauncher/launcher/exec/corerun.cc b/NativeLauncher/launcher/exec/corerun.cc index 0e8293d..802b9a0 100644 --- a/NativeLauncher/launcher/exec/corerun.cc +++ b/NativeLauncher/launcher/exec/corerun.cc @@ -17,13 +17,14 @@ #include #include #include "coreclr_host.h" +#include "log.h" #include "utils.h" static const char* CLR_PATH = "/usr/share/dotnet.tizen/netcoreapp"; static const char* TOOL_PATH = "/home/owner/share/.dotnet/tools"; void DisplayUsage() { - fprintf(stdout, + _SOUT( "Execute a .NET application or command.\n\n" "Usage: dotnet [options] [path-to-executable] [arguments]\n" "Usage: dotnet [command] [arguments]\n\n" @@ -38,7 +39,7 @@ void DisplayUsage() { "dump capture or analyze a coredump\n" "gcdump capture a heapdump\n" "trace collect or convert a diagnostic event trace\n" - "stack reports the managed stacks\n\n"); + "stack reports the managed stacks\n"); } int main(int argc, const char* argv[]) { @@ -97,12 +98,12 @@ int main(int argc, const char* argv[]) { argc--; argv++; } else if (arg.at(0) == '-') { - fprintf(stderr, "Unknown option %s.\n", argv[0]); + _SERR("Unknown option %s.", argv[0]); DisplayUsage(); return -1; } else if (isManagedAssembly(arg) || isNativeImage(arg)) { if (!isFile(arg)) { - fprintf(stderr, "The specified file does not exist.\n"); + _SERR("The specified file does not exist."); return -1; } managedAssemblyPath = arg; @@ -112,15 +113,15 @@ int main(int argc, const char* argv[]) { } else if (arg == "exec") { // 'dotnet' and 'dotnet exec' can be alternatively used. } else if (arg == "tool") { - fprintf(stderr, "This command is not currently supported.\n"); + _SERR("This command is not currently supported."); return -1; } else { managedAssemblyPath = toolDllsPath + "/dotnet-" + arg + ".dll"; if (!isFile(managedAssemblyPath)) { - fprintf(stderr, + _SERR( "Could not execute because dotnet-%s does not exist.\n" - "Go to https://developer.samsung.com/tizen to learn how to install tools.\n\n", argv[0]); + "Go to https://developer.samsung.com/tizen to learn how to install tools.\n", argv[0]); return -1; } @@ -141,19 +142,19 @@ int main(int argc, const char* argv[]) { std::string currentExeAbsolutePath = getAbsolutePath("/proc/self/exe"); if (currentExeAbsolutePath.empty()) { - fprintf(stderr, "Failed to get the current executable's absolute path.\n"); + _SERR("Failed to get the current executable's absolute path."); return -1; } std::string clrFilesAbsolutePath = getAbsolutePath(clrFilesPath); if (clrFilesAbsolutePath.empty()) { - fprintf(stderr, "Failed to resolve the full path to the CLR files.\n"); + _SERR("Failed to resolve the full path to the CLR files."); return -1; } std::string managedAssemblyAbsolutePath = getAbsolutePath(managedAssemblyPath); if (managedAssemblyAbsolutePath.empty()) { - fprintf(stderr, "Failed to get the managed assembly's absolute path.\n"); + _SERR("Failed to get the managed assembly's absolute path."); return -1; } @@ -171,7 +172,7 @@ int main(int argc, const char* argv[]) { void* coreclrLib = dlopen(coreclrLibPath.c_str(), RTLD_NOW | RTLD_LOCAL); if (coreclrLib == nullptr) { const char* error = dlerror(); - fprintf(stderr, "dlopen failed to open the libcoreclr.so with error %s\n", error); + _SERR("dlopen failed to open the libcoreclr.so with error %s", error); return -1; } @@ -180,13 +181,13 @@ int main(int argc, const char* argv[]) { coreclr_shutdown_ptr shutdownCoreCLR = (coreclr_shutdown_ptr)dlsym(coreclrLib, "coreclr_shutdown"); if (initializeCoreCLR == nullptr) { - fprintf(stderr, "Function coreclr_initialize not found in the libcoreclr.so\n"); + _SERR("Function coreclr_initialize not found in the libcoreclr.so"); return -1; } else if (executeAssembly == nullptr) { - fprintf(stderr, "Function coreclr_execute_assembly not found in the libcoreclr.so\n"); + _SERR("Function coreclr_execute_assembly not found in the libcoreclr.so"); return -1; } else if (shutdownCoreCLR == nullptr) { - fprintf(stderr, "Function coreclr_shutdown not found in the libcoreclr.so\n"); + _SERR("Function coreclr_shutdown not found in the libcoreclr.so"); return -1; } @@ -218,7 +219,7 @@ int main(int argc, const char* argv[]) { &domainId); if (st < 0) { - fprintf(stderr, "coreclr_initialize failed - status: 0x%08x\n", st); + _SERR("coreclr_initialize failed - status: 0x%08x", st); return -1; } @@ -237,13 +238,13 @@ int main(int argc, const char* argv[]) { (unsigned int*)&exitCode); if (st < 0) { - fprintf(stderr, "coreclr_execute_assembly failed - status: 0x%08x\n", st); + _SERR("coreclr_execute_assembly failed - status: 0x%08x", st); exitCode = -1; } st = shutdownCoreCLR(hostHandle, domainId); if (st < 0) { - fprintf(stderr, "coreclr_shutdown failed - status: 0x%08x\n", st); + _SERR("coreclr_shutdown failed - status: 0x%08x", st); return -1; } diff --git a/NativeLauncher/tool/dotnettool.cc b/NativeLauncher/tool/dotnettool.cc index 2314a8f..7fcb6ee 100644 --- a/NativeLauncher/tool/dotnettool.cc +++ b/NativeLauncher/tool/dotnettool.cc @@ -18,6 +18,7 @@ #include "ni_common.h" #include "tac_common.h" #include "multi_target_resolver.h" +#include "log.h" #include #include @@ -26,7 +27,7 @@ #include void DisplayUsage() { - fprintf(stdout, + _SOUT( "\n" "Dotnet Tool Version: 1.0\n" "\n" @@ -116,7 +117,7 @@ int main(int argc, char* argv[]) std::string ibcFilePath = std::string(*it); if (!isDirectory(ibcFilePath)) { - fprintf(stderr, "IBC path is missing or not exist\n"); + _SERR("IBC path is missing or not exist"); return -1; } @@ -140,19 +141,19 @@ int main(int argc, char* argv[]) if (cmd == "--ni-system") { int ret = createNIPlatform(flags); if (ret != NI_ERROR_NONE) { - fprintf(stderr, "Failed to generate system NI\n"); + _SERR("Failed to generate system NI"); } } //sh-3.2# dotnettool --ni-dll [assemblyPath] [assemblyPath] ... else if (cmd == "--ni-dll") { if (args.size() < 1) { - fprintf(stderr, "DLL path is missing\n"); + _SERR("DLL path is missing"); } while (it != args.end()) { std::string dll = std::string(*it); int ret = createNIDll(dll, flags); if (ret != NI_ERROR_NONE) { - fprintf(stderr, "Failed to generate NI file [%s]\n", dll.c_str()); + _SERR("Failed to generate NI file [%s]", dll.c_str()); break; } it = args.erase(it); @@ -161,17 +162,17 @@ int main(int argc, char* argv[]) //sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ... else if (cmd == "--ni-pkg") { if (args.size() < 1) { - fprintf(stderr, "Package name is missing\n"); + _SERR("Package name is missing"); } while (it != args.end()) { std::string pkg = std::string(*it); if (isReadOnlyApp(pkg)) { - fprintf(stderr, "Skip to generate app NI. Try to create NI for read-only package [%s]\n# dotnettool --ni-ro-pkg %s\n", pkg.c_str(), pkg.c_str()); + _SERR("Skip to generate app NI. Try to create NI for read-only package [%s]\n# dotnettool --ni-ro-pkg %s", pkg.c_str(), pkg.c_str()); } else { // if there is AOTed dlls under package root, that is skiped. int ret = createNIUnderPkgRoot(pkg, flags); if (ret != NI_ERROR_NONE) { - fprintf(stderr, "Failed to generate app NI [%s]\n", pkg.c_str()); + _SERR("Failed to generate app NI [%s]", pkg.c_str()); break; } } @@ -181,7 +182,7 @@ int main(int argc, char* argv[]) //sh-3.2# dotnettool --ni-ro-pkg [pkgId] [pkgId] ... else if (cmd == "--ni-ro-pkg") { if (args.size() < 1) { - fprintf(stderr, "Package name is missing\n"); + _SERR("Package name is missing"); } flags |= NI_FLAGS_READONLY_APP; while (it != args.end()) { @@ -190,11 +191,11 @@ int main(int argc, char* argv[]) // if there is AOTed dlls under package root, that is skiped. int ret = createNIUnderPkgRoot(pkg, flags); if (ret != NI_ERROR_NONE) { - fprintf(stderr, "Failed to generate read-only app NI [%s]\n", pkg.c_str()); + _SERR("Failed to generate read-only app NI [%s]", pkg.c_str()); break; } } else { - fprintf(stderr, "Skip to generate app NI. Try to create NI for package [%s]\n# dotnettool --ni-pkg %s\n", pkg.c_str(), pkg.c_str()); + _SERR("Skip to generate app NI. Try to create NI for package [%s]\n# dotnettool --ni-pkg %s", pkg.c_str(), pkg.c_str()); } it = args.erase(it); } @@ -202,13 +203,13 @@ int main(int argc, char* argv[]) //sh-3.2# dotnettool --ni-dir [AssemblyDirectory] [AssemblyDirectory] ... else if (cmd == "--ni-dir") { if (args.size() < 1) { - fprintf(stderr, "Directory path is missing\n"); + _SERR("Directory path is missing"); } while (it != args.end()) { const std::string dir = std::string(*it); int ret = createNIUnderDirs(dir, flags); if (ret != NI_ERROR_NONE) { - fprintf(stderr, "Failed to generate NI directory\n"); + _SERR("Failed to generate NI directory"); break; } it = args.erase(it); @@ -221,13 +222,13 @@ int main(int argc, char* argv[]) //sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ... else if (cmd == "--ni-reset-pkg") { if (args.size() < 1) { - fprintf(stderr, "Package name is missing\n"); + _SERR("Package name is missing"); } while (it != args.end()) { std::string pkg = std::string(*it); int ret = removeNIUnderPkgRoot(pkg); if (ret != NI_ERROR_NONE) { - fprintf(stderr, "Failed to remove dlls for given package [%s]\n", pkg.c_str()); + _SERR("Failed to remove dlls for given package [%s]", pkg.c_str()); break; } it = args.erase(it); @@ -236,7 +237,7 @@ int main(int argc, char* argv[]) //sh-3.2# dotnettool --ni-reset-dir [AssemblyDirectory] [AssemblyDirectory] ... else if (cmd == "--ni-reset-dir") { if (args.size() < 1) { - fprintf(stderr, "Directory path is missing\n"); + _SERR("Directory path is missing"); } while (it != args.end()) { const std::string dir = std::string(*it); @@ -248,7 +249,7 @@ int main(int argc, char* argv[]) else if (cmd == "--ni-regen-all-app") { int ret = regenerateAppNI(flags); if (ret != NI_ERROR_NONE) { - fprintf(stderr, "Failed to regenerate all app NI\n"); + _SERR("Failed to regenerate all app NI"); } } //sh-3.2# dotnettool --ni-regen-readonly-app @@ -256,37 +257,37 @@ int main(int argc, char* argv[]) flags |= NI_FLAGS_READONLY_APP; int ret = regenerateAppNI(flags); if (ret != NI_ERROR_NONE) { - fprintf(stderr, "Failed to regenerate read-only app NI\n"); + _SERR("Failed to regenerate read-only app NI"); } } //sh-3.2# dotnettool --tac-regen-all else if (cmd == "--tac-regen-all") { int ret = regenerateTACNI(flags); if (ret != NI_ERROR_NONE) { - fprintf(stderr, "Failed to regenerate all TAC\n"); + _SERR("Failed to regenerate all TAC"); } } //sh-3.2# dotnettool --tac-restore-db else if (cmd == "--tac-restore-db") { int ret = tac_restoreDB(); if (ret != TAC_ERROR_NONE) { - fprintf(stderr, "Failed to restore TAC db\n"); + _SERR("Failed to restore TAC db"); } ret = tlc_restoreDB(); if (ret != TAC_ERROR_NONE) { - fprintf(stderr, "Failed to restore TLC db\n"); + _SERR("Failed to restore TLC db"); } } //sh-3.2# dotnettool --tac-enable-pkg [pkgId] [pkgId] ... else if (cmd == "--tac-enable-pkg") { if (args.size() < 1) { - fprintf(stderr, "Package name is missing\n"); + _SERR("Package name is missing"); } while (it != args.end()) { std::string pkg = std::string(*it); int ret = enableTACPackage(pkg); if (ret != TAC_ERROR_NONE) { - fprintf(stderr, "Failed to enable tac [%s]\n", pkg.c_str()); + _SERR("Failed to enable tac [%s]", pkg.c_str()); break; } it = args.erase(it); @@ -295,13 +296,13 @@ int main(int argc, char* argv[]) //sh-3.2# dotnettool --tac-disable-pkg [pkgId] [pkgId] ... else if (cmd == "--tac-disable-pkg") { if (args.size() < 1) { - fprintf(stderr, "Package name is missing\n"); + _SERR("Package name is missing"); } while (it != args.end()) { std::string pkg = std::string(*it); int ret = disableTACPackage(pkg); if (ret != TAC_ERROR_NONE) { - fprintf(stderr, "Failed to disable tac [%s]\n", pkg.c_str()); + _SERR("Failed to disable tac [%s]", pkg.c_str()); break; } it = args.erase(it); @@ -311,11 +312,11 @@ int main(int argc, char* argv[]) else if (cmd == "--resolve-all-app") { int ret = resolveAllApps(); if (ret != 0) { - fprintf(stderr, "Failed to remove unused multi-targeting files\n"); + _SERR("Failed to remove unused multi-targeting files"); } } else { - fprintf(stderr, "Unknown option [%s]\n", cmd.c_str()); + _SERR("Unknown option [%s]", cmd.c_str()); DisplayUsage(); } @@ -323,7 +324,7 @@ int main(int argc, char* argv[]) gettimeofday(&tv, NULL); endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l; - fprintf(stdout, "\nSpend time for dotnettool is [%d]ms\n", (int)(endtime - starttime)); + _SOUT("\nSpend time for dotnettool is [%d]ms", (int)(endtime - starttime)); return 0; } diff --git a/NativeLauncher/tool/multi_target_resolver.cc b/NativeLauncher/tool/multi_target_resolver.cc index 317aae4..fe66551 100644 --- a/NativeLauncher/tool/multi_target_resolver.cc +++ b/NativeLauncher/tool/multi_target_resolver.cc @@ -152,12 +152,12 @@ static int appResolveCb(pkgmgrinfo_appinfo_h handle, void *user_data) ret = pkgmgrinfo_appinfo_get_root_path(handle, &rootPath); if (ret != PMINFO_R_OK) { - fprintf(stderr, "Failed to get root path"); + _SERR("Failed to get root path"); return -1; } if (resolvePlatformSpecificFiles(rootPath) != 0) { - fprintf(stderr, "Failed to resolve platform specific resources (%s)\n", rootPath); + _SERR("Failed to resolve platform specific resources (%s)", rootPath); return -1; } diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index 8302c77..f710ee8 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -77,7 +77,7 @@ static void waitInterval() { // by the recommand, ignore small value for performance. if (__interval > 10000) { - fprintf(stdout, "sleep %d usec\n", __interval); + _SOUT("sleep %d usec", __interval); usleep(__interval); } } @@ -86,7 +86,7 @@ static std::string getNIFilePath(const std::string& dllPath) { size_t index = dllPath.find_last_of("."); if (index == std::string::npos) { - fprintf(stderr, "File doesnot contain extension. fail to get NI file name\n"); + _SERR("File doesnot contain extension. fail to get NI file name"); return ""; } std::string fName = dllPath.substr(0, index); @@ -118,7 +118,7 @@ static bool createDirsAndCopyOwnerShip(std::string& target_path, const std::stri if (!newPath.empty()) { if (stat(newPath.c_str(), &st) != 0) { if (mkdir(newPath.c_str(), mode) != 0 && errno != EEXIST) { - fprintf(stderr, "Fail to create app ni directory (%s)\n", newPath.c_str()); + _SERR("Fail to create app ni directory (%s)", newPath.c_str()); return false; } if (!source.empty()) { @@ -126,7 +126,7 @@ static bool createDirsAndCopyOwnerShip(std::string& target_path, const std::stri } } else { if (!S_ISDIR(st.st_mode)) { - fprintf(stderr, "Fail. path is not a dir (%s)\n", newPath.c_str()); + _SERR("Fail. path is not a dir (%s)", newPath.c_str()); return false; } } @@ -155,7 +155,7 @@ static std::string getAppNIFilePath(const std::string& absDllPath, DWORD flags) if (!isDirectory(niDirPath)) { if (!createDirsAndCopyOwnerShip(niDirPath, prevPath)) { niDirPath = prevPath; - fprintf(stderr, "fail to create dir (%s)\n", niDirPath.c_str()); + _SERR("fail to create dir (%s)", niDirPath.c_str()); } } @@ -203,7 +203,7 @@ static uintptr_t getNextBaseAddrFromFile() { FILE *pFile = fopen(__SYSTEM_BASE_FILE, "r"); if (pFile == NULL) { - fprintf(stderr, "Failed to open %s\n", __SYSTEM_BASE_FILE); + _SERR("Failed to open %s", __SYSTEM_BASE_FILE); return 0; } @@ -242,14 +242,14 @@ static void updateBaseAddrFile(const std::string& absNIPath, uintptr_t baseAddr) { uintptr_t niSize = getFileSize(absNIPath); if (niSize == 0) { - fprintf(stderr, "File %s doesn't exist\n", absNIPath.c_str()); + _SERR("File %s doesn't exist", absNIPath.c_str()); return; } // Write new entry to the file FILE *pFile = fopen(__SYSTEM_BASE_FILE, "a"); if (pFile == NULL) { - fprintf(stderr, "Failed to open %s\n", __SYSTEM_BASE_FILE); + _SERR("Failed to open %s", __SYSTEM_BASE_FILE); return; } @@ -277,17 +277,17 @@ static bool isTPADll(const std::string& dllPath) static ni_error_e crossgen(const std::string& dllPath, const std::string& appPath, DWORD flags) { if (!isFile(dllPath)) { - fprintf(stderr, "dll file is not exist : %s\n", dllPath.c_str()); + _SERR("dll file is not exist : %s", dllPath.c_str()); return NI_ERROR_NO_SUCH_FILE; } if (!isManagedAssembly(dllPath)) { - //fprintf(stderr, "Input file is not a dll file : %s\n", dllPath.c_str()); + //_SERR("Input file is not a dll file : %s", dllPath.c_str()); return NI_ERROR_INVALID_PARAMETER; } if (checkNIExistence(dllPath)) { - //fprintf(stderr, "Already ni file is exist for %s\n", dllPath.c_str()); + //_SERR("Already ni file is exist for %s", dllPath.c_str()); return NI_ERROR_ALREADY_EXIST; } @@ -302,7 +302,7 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat } if (absNIPath.empty()) { - fprintf(stderr, "Fail to get ni file name\n"); + _SERR("Fail to get ni file name"); return NI_ERROR_UNKNOWN; } @@ -330,7 +330,7 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat std::string pdbFilePath = replaceAll(absNIPath, ".ni.dll", ".pdb"); if (isFile(absPdbPath) && (absPdbPath != pdbFilePath)) { if (!copyFile(absPdbPath, pdbFilePath)) { - fprintf(stderr, "Failed to copy a .pdb file\n"); + _SERR("Failed to copy a .pdb file"); } else { copySmackAndOwnership(absPdbPath, pdbFilePath); } @@ -342,7 +342,7 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat #endif return NI_ERROR_NONE; } else { - fprintf(stderr, "Fail to create native image for %s\n", dllPath.c_str()); + _SERR("Fail to create native image for %s", dllPath.c_str()); return NI_ERROR_NO_SUCH_FILE; } } @@ -405,7 +405,7 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat argv.push_back(absDllPath.c_str()); argv.push_back(nullptr); - fprintf(stdout, "+ %s (%s)\n", absDllPath.c_str(), enableR2R ? "R2R" : "FNV"); + _SOUT("+ %s (%s)", absDllPath.c_str(), enableR2R ? "R2R" : "FNV"); execv(__CROSSGEN_PATH, const_cast(argv.data())); exit(0); @@ -423,7 +423,7 @@ static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData) ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId); if (ret != PMINFO_R_OK) { - fprintf(stderr, "Failed to get pkgid\n"); + _SERR("Failed to get pkgid"); return -1; } @@ -431,26 +431,26 @@ static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData) // read-only and readonly flag set if (readOnlyApp && (*pFlags & NI_FLAGS_READONLY_APP)) { - fprintf(stderr, "try to regenerate read-only pkg [%s]\n", pkgId); + _SERR("try to regenerate read-only pkg [%s]", pkgId); } // not read-only and readonly flag does not set else if (!readOnlyApp && !(*pFlags & NI_FLAGS_READONLY_APP)) { if (removeNIUnderPkgRoot(pkgId) != NI_ERROR_NONE) { - fprintf(stderr, "Failed to remove previous dlls from [%s]\n", pkgId); + _SERR("Failed to remove previous dlls from [%s]", pkgId); return -1; } } // skip regeneration else { - fprintf(stderr, "skip regeneration. pkg-type(read-only) doesnot match the configuration [%s]\n", pkgId); + _SERR("skip regeneration. pkg-type(read-only) doesnot match the configuration [%s]", pkgId); return 0; } if (createNIUnderPkgRoot(pkgId, *pFlags) != NI_ERROR_NONE) { - fprintf(stderr, "Failed to generate NI file [%s]\n", pkgId); + _SERR("Failed to generate NI file [%s]", pkgId); return -1; } else { - fprintf(stdout, "Complete make application to native image\n"); + _SOUT("Complete make application to native image"); } return 0; @@ -466,9 +466,9 @@ static bool isCoreLibPrepared(DWORD flags) if (isFile(coreLibBackup)) { return true; } else { - fprintf(stderr, "The native image of System.Private.CoreLib does not exist\n" + _SERR("The native image of System.Private.CoreLib does not exist\n" "Run the command to create the native image\n" - "# dotnettool --ni-dll /usr/share/dotnet.tizen/netcoreapp/System.Private.CoreLib.dll\n\n"); + "# dotnettool --ni-dll /usr/share/dotnet.tizen/netcoreapp/System.Private.CoreLib.dll\n"); return false; } } @@ -501,15 +501,15 @@ static ni_error_e createCoreLibNI(DWORD flags) if (!isFile(coreLibBackup) && !hasCoreLibNI()) { if (!crossgen(coreLib, std::string(), flags)) { if (rename(coreLib.c_str(), coreLibBackup.c_str())) { - fprintf(stderr, "Failed to rename System.Private.CoreLib.dll\n"); + _SERR("Failed to rename System.Private.CoreLib.dll"); return NI_ERROR_CORE_NI_FILE; } if (rename(niCoreLib.c_str(), coreLib.c_str())) { - fprintf(stderr, "Failed to rename System.Private.CoreLib.ni.dll\n"); + _SERR("Failed to rename System.Private.CoreLib.ni.dll"); return NI_ERROR_CORE_NI_FILE; } } else { - fprintf(stderr, "Failed to create native image for %s\n", coreLib.c_str()); + _SERR("Failed to create native image for %s", coreLib.c_str()); return NI_ERROR_CORE_NI_FILE; } } @@ -523,19 +523,19 @@ ni_error_e initNICommon() const static std::string intervalFile = concatPath(__NATIVE_LIB_DIR, "crossgen_interval.txt"); std::ifstream inFile(intervalFile); if (inFile) { - fprintf(stdout, "crossgen_interval.txt is found\n"); + _SOUT("crossgen_interval.txt is found"); inFile >> __interval; } if (initializePluginManager("normal")) { - fprintf(stderr, "Fail to initialize PluginManager\n"); + _SERR("Fail to initialize PluginManager"); return NI_ERROR_UNKNOWN; } try { __pm = new PathManager(); } catch (const std::exception& e) { - fprintf(stderr, "Failed to create PathManager"); + _SERR("Failed to create PathManager"); return NI_ERROR_UNKNOWN; } @@ -546,7 +546,7 @@ ni_error_e initNICommon() return NI_ERROR_NONE; #else - fprintf(stderr, "crossgen supports arm/arm64 architecture only. skip ni file generation\n"); + _SERR("crossgen supports arm/arm64 architecture only. skip ni file generation"); return NI_ERROR_NOT_SUPPORTED; #endif } @@ -631,12 +631,12 @@ ni_error_e createNIUnderDirs(const std::string& rootPaths, DWORD flags) if (!isFile(symNIPath)) { bf::create_symlink(originNIPath, symNIPath); copySmackAndOwnership(symPath.c_str(), symNIPath.c_str(), true); - fprintf(stdout, "%s symbolic link file generated successfully.\n", symNIPath.c_str()); + _SOUT("%s symbolic link file generated successfully.", symNIPath.c_str()); _INFO("%s symbolic link file generated successfully.", symNIPath.c_str()); } } } catch (const bf::filesystem_error& error) { - fprintf(stderr, "Failed to recursive directory: %s\n", error.what()); + _SERR("Failed to recursive directory: %s", error.what()); return NI_ERROR_UNKNOWN; } } else { @@ -651,7 +651,7 @@ ni_error_e createNIUnderPkgRoot(const std::string& pkgId, DWORD flags) { std::string rootPath = getRootPath(pkgId); if (rootPath.empty()) { - fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str()); + _SERR("Failed to get root path from [%s]", pkgId.c_str()); return NI_ERROR_INVALID_PACKAGE; } @@ -675,17 +675,17 @@ void removeNIPlatform() } if (remove(coreLib.c_str())) { - fprintf(stderr, "Failed to remove System.Private.CoreLib native image file\n"); + _SERR("Failed to remove System.Private.CoreLib native image file"); } if (rename(coreLibBackup.c_str(), coreLib.c_str())) { - fprintf(stderr, "Failed to rename System.Private.CoreLib.Backup to origin\n"); + _SERR("Failed to rename System.Private.CoreLib.Backup to origin"); } } #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT if (isFile(__SYSTEM_BASE_FILE)) { if (remove(__SYSTEM_BASE_FILE)) { - fprintf(stderr, "Failed to remove %s\n", __SYSTEM_BASE_FILE); + _SERR("Failed to remove %s", __SYSTEM_BASE_FILE); } } #endif @@ -698,7 +698,7 @@ void removeNIUnderDirs(const std::string& rootPaths) auto convert = [](const std::string& path, const std::string& filename) { if (isNativeImage(path)) { if (remove(path.c_str())) { - fprintf(stderr, "Failed to remove %s\n", path.c_str()); + _SERR("Failed to remove %s", path.c_str()); } } }; @@ -714,7 +714,7 @@ ni_error_e removeNIUnderPkgRoot(const std::string& pkgId) { std::string rootPath = getRootPath(pkgId); if (rootPath.empty()) { - fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str()); + _SERR("Failed to get root path from [%s]", pkgId.c_str()); return NI_ERROR_INVALID_PACKAGE; } @@ -731,7 +731,7 @@ ni_error_e removeNIUnderPkgRoot(const std::string& pkgId) } else { if (isDirectory(path)) { if (!removeAll(path.c_str())) { - fprintf(stderr, "Failed to remove app ni dir [%s]\n", path.c_str()); + _SERR("Failed to remove app ni dir [%s]", path.c_str()); } } } @@ -777,13 +777,13 @@ static int regenTacCb(pkgmgrinfo_appinfo_h handle, void *userData) int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId); if (ret != PMINFO_R_OK || pkgId == NULL) { - fprintf(stderr, "Failed to get pkgid\n"); + _SERR("Failed to get pkgid"); return -1; } sqlite3 *tac_db = openDB(TAC_APP_LIST_DB); if (!tac_db) { - fprintf(stderr, "Sqlite open error\n"); + _SERR("Sqlite open error"); return -1; } sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL); diff --git a/NativeLauncher/tool/nitool.cc b/NativeLauncher/tool/nitool.cc index 1b99e3f..bbed3f2 100644 --- a/NativeLauncher/tool/nitool.cc +++ b/NativeLauncher/tool/nitool.cc @@ -100,9 +100,9 @@ int main(int argc, char* argv[]) if (args.size() < 1) { if (pkgMode) - fprintf(stderr, "Package name is missing.\n"); + _SERR("Package name is missing."); else if (dllMode) - fprintf(stderr, "DLL path is missing.\n"); + _SERR("DLL path is missing."); help(argv[0]); return -1; } @@ -112,10 +112,10 @@ int main(int argc, char* argv[]) // if there is AOTed dlls under package root, that is skiped. int ret = createNIUnderPkgRoot(pkg, flags); if (ret == NI_ERROR_INVALID_PACKAGE) { - fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str()); + _SERR("Failed to get root path from [%s]", pkg.c_str()); return -1; } else if (ret != NI_ERROR_NONE) { - fprintf(stderr, "Failed to generate NI file [%s]\n", pkg.c_str()); + _SERR("Failed to generate NI file [%s]", pkg.c_str()); return -1; } } @@ -123,10 +123,10 @@ int main(int argc, char* argv[]) for (const std::string pkg : args) { int ret = removeNIUnderPkgRoot(pkg); if (ret == NI_ERROR_INVALID_PACKAGE) { - fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str()); + _SERR("Failed to get root path from [%s]", pkg.c_str()); return -1; } else if (ret != NI_ERROR_NONE) { - fprintf(stderr, "Failed to remove dlls for given package [%s]\n", pkg.c_str()); + _SERR("Failed to remove dlls for given package [%s]", pkg.c_str()); return -1; } } @@ -138,7 +138,7 @@ int main(int argc, char* argv[]) if (ret == NI_ERROR_ALREADY_EXIST) { // skip for already exist case } else if (ret != NI_ERROR_NONE) { - fprintf(stderr, "Failed to generate NI file [%s]\n", dll.c_str()); + _SERR("Failed to generate NI file [%s]", dll.c_str()); } } } diff --git a/NativeLauncher/tool/tac_common.cc b/NativeLauncher/tool/tac_common.cc index ca666f0..1d69acf 100644 --- a/NativeLauncher/tool/tac_common.cc +++ b/NativeLauncher/tool/tac_common.cc @@ -67,12 +67,12 @@ static void cleanupDirectory() for (auto& rm : removeNuget) { if (!removeAll(rm)) { - fprintf(stderr, "Failed to remove of %s\n", rm.c_str()); + _SERR("Failed to remove of %s", rm.c_str()); } } removeNuget.clear(); } catch (const bf::filesystem_error& error) { - fprintf(stderr, "Failed to recursive directory: %s\n", error.what()); + _SERR("Failed to recursive directory: %s", error.what()); return; } } @@ -88,7 +88,7 @@ static int tac_restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData) int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId); if (ret != PMINFO_R_OK) { - fprintf(stderr, "Failed to get pkgid\n"); + _SERR("Failed to get pkgid"); return -1; } @@ -96,14 +96,14 @@ static int tac_restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData) ret = pkgmgrinfo_appinfo_get_root_path(handle, &root); if (ret != PMINFO_R_OK) { - fprintf(stderr, "Failed to get root path\n"); + _SERR("Failed to get root path"); return -1; } rootPath = std::string(root); ret = pkgmgrinfo_appinfo_get_exec(handle, &exec); if (ret != PMINFO_R_OK) { - fprintf(stderr, "Failed to get exec name\n"); + _SERR("Failed to get exec name"); return -1; } execName = std::string(exec).substr(std::string(exec).rfind('/') + 1); @@ -140,19 +140,19 @@ static int tac_restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData) tac_error_e tac_restoreDB() { if (!removeFile(TAC_APP_LIST_RESTORE_DB)) { - fprintf(stderr, "Failed to remove of %s\n", TAC_APP_LIST_RESTORE_DB); + _SERR("Failed to remove of %s", TAC_APP_LIST_RESTORE_DB); return TAC_ERROR_UNKNOWN; } std::string dbRestoreJournal = TAC_APP_LIST_RESTORE_DB + std::string("-journal"); if (!removeFile(dbRestoreJournal)) { - fprintf(stderr, "Failed to remove of %s\n", dbRestoreJournal.c_str()); + _SERR("Failed to remove of %s", dbRestoreJournal.c_str()); return TAC_ERROR_UNKNOWN; } tac_db = createDB(TAC_APP_LIST_RESTORE_DB, CREATE_TAC_DB_TABLE); if (!tac_db) { - fprintf(stderr, "Sqlite create error\n"); + _SERR("Sqlite create error"); return TAC_ERROR_UNKNOWN; } sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL); @@ -183,21 +183,21 @@ tac_error_e tac_restoreDB() } if (!copyFile(TAC_APP_LIST_RESTORE_DB, TAC_APP_LIST_DB)) { - fprintf(stderr, "Failed to copy of %s\n", TAC_APP_LIST_DB); + _SERR("Failed to copy of %s", TAC_APP_LIST_DB); return TAC_ERROR_UNKNOWN; } if (!removeFile(TAC_APP_LIST_RESTORE_DB)) { - fprintf(stderr, "Failed to remove of %s\n", TAC_APP_LIST_RESTORE_DB); + _SERR("Failed to remove of %s", TAC_APP_LIST_RESTORE_DB); return TAC_ERROR_UNKNOWN; } std::string dbJournal = TAC_APP_LIST_DB + std::string("-journal"); if (!copyFile(dbRestoreJournal, dbJournal)) { - fprintf(stderr, "Failed to copy of %s\n", dbJournal.c_str()); + _SERR("Failed to copy of %s", dbJournal.c_str()); return TAC_ERROR_UNKNOWN; } if (!removeFile(dbRestoreJournal)) { - fprintf(stderr, "Failed to remove of %s\n", dbRestoreJournal.c_str()); + _SERR("Failed to remove of %s", dbRestoreJournal.c_str()); return TAC_ERROR_UNKNOWN; } @@ -210,7 +210,7 @@ tac_error_e disableTACPackage(const std::string& pkgId) { std::string rootPath = getRootPath(pkgId); if (rootPath.empty()) { - fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str()); + _SERR("Failed to get root path from [%s]", pkgId.c_str()); return TAC_ERROR_INVALID_PACKAGE; } @@ -227,14 +227,14 @@ tac_error_e disableTACPackage(const std::string& pkgId) if (!isNativeImage(symPath)) { std::string dllPath = concatPath(binDir, fileName); if (!copyFile(originPath, dllPath)) { - fprintf(stderr, "Failed to copy of %s\n", dllPath.c_str()); + _SERR("Failed to copy of %s", dllPath.c_str()); return TAC_ERROR_UNKNOWN; } copySmackAndOwnership(binDir.c_str(), concatPath(binDir, fileName).c_str()); } else { std::string niPath = concatPath(binNIDir, fileName); if (!copyFile(originPath, niPath)) { - fprintf(stderr, "Failed to copy of %s\n", niPath.c_str()); + _SERR("Failed to copy of %s", niPath.c_str()); return TAC_ERROR_UNKNOWN; } copySmackAndOwnership(binDir.c_str(), niPath.c_str()); @@ -242,11 +242,11 @@ tac_error_e disableTACPackage(const std::string& pkgId) } } if (!removeAll(tacDir)) { - fprintf(stderr, "Failed to remove of %s\n", tacDir.c_str()); + _SERR("Failed to remove of %s", tacDir.c_str()); return TAC_ERROR_UNKNOWN; } } catch (const bf::filesystem_error& error) { - fprintf(stderr, "Failed to recursive directory: %s\n", error.what()); + _SERR("Failed to recursive directory: %s", error.what()); return TAC_ERROR_UNKNOWN; } } @@ -257,19 +257,19 @@ tac_error_e enableTACPackage(const std::string& pkgId) { std::string rootPath = getRootPath(pkgId); if (rootPath.empty()) { - fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str()); + _SERR("Failed to get root path from [%s]", pkgId.c_str()); return TAC_ERROR_INVALID_PACKAGE; } std::string execName = getExecName(pkgId); if (execName.empty()) { - fprintf(stderr, "Failed to get exec name from [%s]\n", pkgId.c_str()); + _SERR("Failed to get exec name from [%s]", pkgId.c_str()); return TAC_ERROR_INVALID_PACKAGE; } std::string metaValue = getMetadataValue(pkgId, TAC_METADATA_KEY); if (metaValue.empty()) { - fprintf(stderr, "Failed to get metadata from [%s]\n", pkgId.c_str()); + _SERR("Failed to get metadata from [%s]", pkgId.c_str()); return TAC_ERROR_INVALID_PACKAGE; } @@ -279,7 +279,7 @@ tac_error_e enableTACPackage(const std::string& pkgId) std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR); if (!exist(tacDir)) { if (!createDir(tacDir)) { - fprintf(stderr, "Cannot create directory: %s\n", tacDir.c_str()); + _SERR("Cannot create directory: %s", tacDir.c_str()); return TAC_ERROR_UNKNOWN; } copySmackAndOwnership(binDir.c_str(), tacDir.c_str()); @@ -305,34 +305,34 @@ tac_error_e enableTACPackage(const std::string& pkgId) std::string originNIPath = changeExtension(originPath, "dll", "ni.dll"); if (exist(originNIPath)) { bf::create_symlink(originNIPath, concatPath(tacDir, NIFileName)); - fprintf(stdout, "%s symbolic link file generated successfully.\n", concatPath(tacDir, NIFileName).c_str()); + _SOUT("%s symbolic link file generated successfully.", concatPath(tacDir, NIFileName).c_str()); copySmackAndOwnership(tacDir.c_str(), concatPath(tacDir, NIFileName).c_str(), true); if (!removeFile(concatPath(binNIDir, NIFileName))) { - fprintf(stderr, "Failed to remove of %s\n", concatPath(binNIDir, NIFileName).c_str()); + _SERR("Failed to remove of %s", concatPath(binNIDir, NIFileName).c_str()); return TAC_ERROR_UNKNOWN; } } } bf::create_symlink(originPath, concatPath(tacDir, fileName)); - fprintf(stdout, "%s symbolic link file generated successfully.\n", concatPath(tacDir, fileName).c_str()); + _SOUT("%s symbolic link file generated successfully.", concatPath(tacDir, fileName).c_str()); copySmackAndOwnership(tacDir.c_str(), concatPath(tacDir, fileName).c_str(), true); if (!removeFile(concatPath(binDir, fileName))) { - fprintf(stderr, "Failed to remove of %s\n", concatPath(binDir, fileName).c_str()); + _SERR("Failed to remove of %s", concatPath(binDir, fileName).c_str()); return TAC_ERROR_UNKNOWN; } } } if (enableNuget.empty()) { if (!removeAll(tacDir)) { - fprintf(stderr, "Failed to remove of %s\n", tacDir.c_str()); + _SERR("Failed to remove of %s", tacDir.c_str()); } } enableNuget.clear(); } } else { - fprintf(stderr, "The metadata key is missing or the metadata value is false of [%s]\n", pkgId.c_str()); + _SERR("The metadata key is missing or the metadata value is false of [%s]", pkgId.c_str()); } return TAC_ERROR_NONE; } @@ -445,13 +445,13 @@ static int tlc_restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData) int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId); if (ret != PMINFO_R_OK) { - fprintf(stderr, "Failed to get pkgid\n"); + _SERR("Failed to get pkgid"); return -1; } ret = pkgmgrinfo_appinfo_get_root_path(handle, &root); if (ret != PMINFO_R_OK) { - fprintf(stderr, "Failed to get root path\n"); + _SERR("Failed to get root path"); return -1; } rootPath = std::string(root); @@ -472,19 +472,19 @@ static int tlc_restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData) tac_error_e tlc_restoreDB() { if (!removeFile(TLC_APP_LIST_RESTORE_DB)) { - fprintf(stderr, "Failed to remove of %s\n", TLC_APP_LIST_RESTORE_DB); + _SERR("Failed to remove of %s", TLC_APP_LIST_RESTORE_DB); return TAC_ERROR_UNKNOWN; } std::string dbRestoreJournal = TLC_APP_LIST_RESTORE_DB + std::string("-journal"); if (!removeFile(dbRestoreJournal)) { - fprintf(stderr, "Failed to remove of %s\n", dbRestoreJournal.c_str()); + _SERR("Failed to remove of %s", dbRestoreJournal.c_str()); return TAC_ERROR_UNKNOWN; } tlc_db = createDB(TLC_APP_LIST_RESTORE_DB, CREATE_TLC_DB_TABLE); if (!tlc_db) { - fprintf(stderr, "Sqlite create error\n"); + _SERR("Sqlite create error"); return TAC_ERROR_UNKNOWN; } sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL); @@ -515,21 +515,21 @@ tac_error_e tlc_restoreDB() } if (!copyFile(TLC_APP_LIST_RESTORE_DB, TLC_APP_LIST_DB)) { - fprintf(stderr, "Failed to copy of %s\n", TLC_APP_LIST_DB); + _SERR("Failed to copy of %s", TLC_APP_LIST_DB); return TAC_ERROR_UNKNOWN; } if (!removeFile(TLC_APP_LIST_RESTORE_DB)) { - fprintf(stderr, "Failed to remove of %s\n", TLC_APP_LIST_RESTORE_DB); + _SERR("Failed to remove of %s", TLC_APP_LIST_RESTORE_DB); return TAC_ERROR_UNKNOWN; } std::string dbJournal = TLC_APP_LIST_DB + std::string("-journal"); if (!copyFile(dbRestoreJournal, dbJournal)) { - fprintf(stderr, "Failed to copy of %s\n", dbJournal.c_str()); + _SERR("Failed to copy of %s", dbJournal.c_str()); return TAC_ERROR_UNKNOWN; } if (!removeFile(dbRestoreJournal)) { - fprintf(stderr, "Failed to remove of %s\n", dbRestoreJournal.c_str()); + _SERR("Failed to remove of %s", dbRestoreJournal.c_str()); return TAC_ERROR_UNKNOWN; } diff --git a/NativeLauncher/tool/tpatool.cc b/NativeLauncher/tool/tpatool.cc index ef00bf5..ffc971b 100644 --- a/NativeLauncher/tool/tpatool.cc +++ b/NativeLauncher/tool/tpatool.cc @@ -20,6 +20,7 @@ #include "utils.h" #include "path_manager.h" +#include "log.h" int main(int argc, char* argv[]) { @@ -27,7 +28,7 @@ int main(int argc, char* argv[]) try { __pm = new PathManager(); } catch (const std::exception& e) { - fprintf(stderr, "Failed to create PathManager"); + _SERR("Failed to create PathManager"); return -1; } @@ -39,7 +40,7 @@ int main(int argc, char* argv[]) out << tpaList; out.close(); } else { - fprintf(stderr, "Failed to create platform_tpa_cache. Symbolic link is detected\n"); + _SERR("Failed to create platform_tpa_cache. Symbolic link is detected"); return -1; } diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index 6611f6e..178741b 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -417,7 +417,7 @@ void copySmackAndOwnership(const std::string& fromPath, const std::string& toPat // change smack label for symbolic link. if (smack_lgetlabel(fromPath.c_str(), &label, SMACK_LABEL_ACCESS) == 0) { if (smack_lsetlabel(toPath.c_str(), label, SMACK_LABEL_ACCESS) < 0) { - fprintf(stderr, "Fail to set smack label\n"); + _SERR("Fail to set smack label"); } free(label); } @@ -425,13 +425,13 @@ void copySmackAndOwnership(const std::string& fromPath, const std::string& toPat // change owner and groups for symbolic link. if (!lstat(fromPath.c_str(), &info)) { if (lchown(toPath.c_str(), info.st_uid, info.st_gid) == -1) - fprintf(stderr, "Failed to change owner and group name\n"); + _SERR("Failed to change owner and group name"); } } else { // change smack label if (smack_getlabel(fromPath.c_str(), &label, SMACK_LABEL_ACCESS) == 0) { if (smack_setlabel(toPath.c_str(), label, SMACK_LABEL_ACCESS) < 0) { - fprintf(stderr, "Fail to set smack label\n"); + _SERR("Fail to set smack label"); } free(label); } @@ -439,7 +439,7 @@ void copySmackAndOwnership(const std::string& fromPath, const std::string& toPat // change owner and groups for generated ni file. if (!stat(fromPath.c_str(), &info)) { if (chown(toPath.c_str(), info.st_uid, info.st_gid) == -1) - fprintf(stderr, "Failed to change owner and group name\n"); + _SERR("Failed to change owner and group name"); } } } -- 2.7.4