Set the native library path with the RIDs value set in TizenFX
[platform/core/dotnet/launcher.git] / NativeLauncher / launcher / main.cc
index 9de8788..f09705b 100644 (file)
 #include <sys/types.h>
 #include <unistd.h>
 
-// By the specification, application id must be shorter than 50 character.
-// To add margin, set CMD_LINE_SIZE to 64. (padding size is included)
-#define APPID_MAX_LENGTH       52
+// By the specification, application id must be shorter than 50 characters.
+// Current length of argv[0] is 25 with a space. ("/usr/bin/dotnet-launcher ")
+// To be able to change argv[0] when standalone mode padding for executable path is added.
+#define APPID_MAX_LENGTH       (25 + 105)
 
 static std::string StandaloneOption("--standalone");
-static std::string PaddingOption("--PADDING_TO_CHANGE_CMDLINE");
+static std::string PaddingOption("--PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE");
 
 extern "C" int realMain(int argc, char *argv[], const char* mode)
 {
@@ -83,11 +84,6 @@ extern "C" int realMain(int argc, char *argv[], const char* mode)
                snprintf(appId, 16, "%s", "dotnet-launcher");
                appRoot = baseName(argv[1]);
 
-               if (runtime->preinitialize(true) != 0) {
-                       _ERR("Failed to preinitialized");
-                       return 1;
-               }
-
                if (runtime->initialize(true) != 0) {
                        _ERR("Failed to initialize");
                        return 1;
@@ -115,11 +111,6 @@ extern "C" int realMain(int argc, char *argv[], const char* mode)
                }
                _INFO("AUL_APPID : %s", appId);
 
-               if (runtime->preinitialize(true) != 0) {
-                       _ERR("Failed to preinitialized");
-                       return 1;
-               }
-
                if (runtime->initialize(true) != 0) {
                        _ERR("Failed to initialize");
                        return 1;
@@ -128,7 +119,7 @@ extern "C" int realMain(int argc, char *argv[], const char* mode)
                // change cmdline from dotnet-launcher to executable path
                int cmdlineSize = paddingExist ? APPID_MAX_LENGTH : APPID_MAX_LENGTH - PaddingOption.length();
                memset(argv[0], '\0', cmdlineSize);
-               snprintf(argv[0], cmdlineSize, "%s", appId);
+               snprintf(argv[0], cmdlineSize, "%s", standalonePath);
 
                int argsLen = vargs.size();
                char** args = &vargs[0];
@@ -137,18 +128,18 @@ extern "C" int realMain(int argc, char *argv[], const char* mode)
                        return 1;
                }
        } else {
-               Launchpad.onPreCreate = [&runtime]() {
-                       if (runtime->preinitialize(false) != 0)
-                               _ERR("Failed to preinitialized");
-                       else
-                               _INFO("Success to preinitialized");
-               };
+               // change cmdline from dotnet-hydra-launcher to dotnet-launcher
+               if (strcmp(argv[0], "/usr/bin/dotnet-hydra-launcher") == 0) {
+                       memset(argv[0], '\0', strlen("/usr/bin/dotnet-hydra-launcher"));
+                       snprintf(argv[0], strlen("/usr/bin/dotnet-launcher") + 1, "/usr/bin/dotnet-launcher");
+               }
 
                Launchpad.onCreate = [&runtime]() {
-                       if (runtime->initialize(false) != 0)
+                       if (runtime->initialize(false) != 0) {
                                _ERR("Failed to initialized");
-                       else
+                       } else {
                                _INFO("Success to initialized");
+                       }
                };
 
                Launchpad.onTerminate = [&runtime](const AppInfo& appInfo, int argc, char** argv) {