2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "core_runtime.h"
26 #include <sys/types.h>
29 #include <sys/prctl.h>
31 using tizen::runtime::dotnetcore::CoreRuntime;
33 // By the specification, application id must be shorter than 50 characters.
34 // Current length of argv[0] is 25 with a space. ("/usr/bin/dotnet-launcher ")
35 // To be able to change argv[0] when standalone mode padding for executable path is added.
36 #define APPID_MAX_LENGTH (25 + 105)
37 #define PRC_NAME_LENGTH 16
39 static std::string StandaloneOption("--standalone");
40 static std::string PaddingOption("--PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE");
41 static std::string AppTypeOption("--appType");
42 static std::string ProfileOption("--profile");
43 static std::string GlobalizationInvariantOption("--invariant");
44 static std::string GlobalizationInvariantOption2("ICULoadDisable");
46 int main(int argc, char *argv[])
48 printHWClockLog("[dotnet-launcher] launcher main!");
49 _INFO("##### Run in standalone mode #####");
51 char* standalonePath = nullptr;
52 bool paddingExist = false;
54 const char* appType = "dotnet";
55 const char* appRootPath = NULL;
56 char appId[APPID_MAX_LENGTH] = {0,};
58 std::vector<char*> vargs;
60 // start index 1 to avoid passing executable name "dotnet-launcher" as a parameter
61 for (int i = 1; i < argc; i++) {
63 if (GlobalizationInvariantOption.compare(argv[i]) == 0 || GlobalizationInvariantOption2.compare(argv[i]) == 0) {
64 setenv("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", 1);
66 } else if (StandaloneOption.compare(argv[i]) == 0) {
68 _ERR("Assembly path must be after \"--standalone\" option");
72 standalonePath = argv[i];
73 } else if (PaddingOption.compare(argv[i]) == 0) {
75 } else if (ProfileOption.compare(argv[i]) == 0) {
77 } else if (AppTypeOption.compare(argv[i]) == 0) {
79 _ERR("app type for launchpad must be after \"--appType\" option");
85 vargs.push_back(argv[i]);
89 // get app ID and app root path
90 if (AUL_R_OK == aul_app_get_appid_bypid(getpid(), appId, sizeof(appId))) {
91 _INFO("AUL_APPID : %s", appId);
92 // aul_get_app_root_path returns const char*, so there is no need to free after use.
93 appRootPath = aul_get_app_root_path();
94 if (appRootPath == nullptr) {
95 _ERR("Fail to get application root path");
99 _ERR("Fail to get app_id");
103 // set command name to assembly file
104 setCmdName(getFileName(standalonePath));
106 // change cmdline from dotnet-launcher to executable path
107 int cmdlineSize = paddingExist ? APPID_MAX_LENGTH : APPID_MAX_LENGTH - PaddingOption.length();
108 memset(argv[0], '\0', cmdlineSize);
109 snprintf(argv[0], cmdlineSize - 1, "%s", standalonePath);
111 // initialize CoreRuntime
112 int err = CoreRuntime::initialize(appType, LaunchMode::launcher);
114 _ERR("Failed to initialize");
116 // launch application
117 err = CoreRuntime::launch(appId, appRootPath, standalonePath, vargs.size(), &vargs[0], profile);
119 _ERR("Failed to launch");
123 // finalize CoreRuntime
124 CoreRuntime::finalize();