#include <dlfcn.h>
#include <string>
#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"
"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[]) {
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;
} 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;
}
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;
}
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;
}
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;
}
&domainId);
if (st < 0) {
- fprintf(stderr, "coreclr_initialize failed - status: 0x%08x\n", st);
+ _SERR("coreclr_initialize failed - status: 0x%08x", st);
return -1;
}
(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;
}
#include "ni_common.h"
#include "tac_common.h"
#include "multi_target_resolver.h"
+#include "log.h"
#include <vector>
#include <cstring>
#include <sys/time.h>
void DisplayUsage() {
- fprintf(stdout,
+ _SOUT(
"\n"
"Dotnet Tool Version: 1.0\n"
"\n"
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;
}
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);
//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;
}
}
//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()) {
// 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);
}
//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);
//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);
//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);
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
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);
//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);
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();
}
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;
}
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;
}
{
// 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);
}
}
{
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);
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()) {
}
} 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;
}
}
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());
}
}
{
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;
}
{
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;
}
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;
}
}
if (absNIPath.empty()) {
- fprintf(stderr, "Fail to get ni file name\n");
+ _SERR("Fail to get ni file name");
return NI_ERROR_UNKNOWN;
}
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);
}
#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;
}
}
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<char* const*>(argv.data()));
exit(0);
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;
}
// 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;
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;
}
}
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;
}
}
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;
}
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
}
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 {
{
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;
}
}
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
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());
}
}
};
{
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;
}
} 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());
}
}
}
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);
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;
}
// 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;
}
}
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;
}
}
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());
}
}
}
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;
}
}
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);
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);
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);
}
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;
}
{
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;
}
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());
}
}
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;
}
}
{
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;
}
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());
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;
}
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);
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);
}
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;
}
#include "utils.h"
#include "path_manager.h"
+#include "log.h"
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;
}
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;
}
// 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);
}
// 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);
}
// 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");
}
}
}