• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstring>
17 
18 #include "appspawn_server.h"
19 #include "hilog/log.h"
20 #include "securec.h"
21 
22 #ifdef NWEB_SPAWN
23 #define APPSPAWN_SERVER_NAME "nwebspawn"
24 #else
25 #define APPSPAWN_SERVER_NAME "appspawn"
26 #endif
27 
28 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AppspawnMain"};
29 
main(int argc,char * const argv[])30 int main(int argc, char *const argv[])
31 {
32     if (argc > 0) {
33         // calculate child process long name size
34         uintptr_t start = reinterpret_cast<uintptr_t>(argv[0]);
35         uintptr_t end = reinterpret_cast<uintptr_t>(strchr(argv[argc - 1], 0));
36         uintptr_t argvSize = end - start;
37 
38         int isRet = memset_s(argv[0], argvSize, 0, (size_t)argvSize);
39         if (isRet != 0) {
40             OHOS::HiviewDFX::HiLog::Error(LABEL, "Failed to memset argv[0]");
41             return -EINVAL;
42         }
43         isRet = strncpy_s(argv[0], argvSize, APPSPAWN_SERVER_NAME, strlen(APPSPAWN_SERVER_NAME));
44         if (isRet != 0) {
45             OHOS::HiviewDFX::HiLog::Error(LABEL, "strncpy_s appspawn server name error: %d", errno);
46             return -EINVAL;
47         }
48 
49 #ifdef NWEB_SPAWN
50         OHOS::AppSpawn::AppSpawnServer appspawnServer("/dev/unix/socket/NWebSpawn");
51 #else
52         OHOS::AppSpawn::AppSpawnServer appspawnServer("AppSpawn");
53 #endif
54         appspawnServer.ServerMain(argv[0], argvSize);
55     }
56 
57     return 0;
58 }
59