/* * Copyright (c) 2020 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #ifdef OHOS_DEBUG #include #endif // OHOS_DEBUG #include #include "init_adapter.h" #include "init_log.h" #include "init_read_cfg.h" #include "init_signal_handler.h" #ifdef OHOS_LITE #include "parameter.h" #endif #ifndef OHOS_LITE #include "device.h" #include "init_param.h" #endif #include "init_utils.h" static const pid_t INIT_PROCESS_PID = 1; static void PrintSysInfo() { #ifdef OHOS_LITE const char* sysInfo = GetVersionId(); if (sysInfo != NULL) { INIT_LOGE("%s", sysInfo); return; } INIT_LOGE("main, GetVersionId failed!"); #endif } #ifdef OHOS_DEBUG static long TimeDiffMs(const struct timespec* tmBefore, const struct timespec* tmAfter) { if (tmBefore != NULL && tmAfter != NULL) { long timeUsed = (tmAfter->tv_sec - tmBefore->tv_sec) * 1000 + // 1 s = 1000 ms (tmAfter->tv_nsec - tmBefore->tv_nsec) / 1000000L; // 1 ms = 1000000 ns return timeUsed; } return -1; } #endif // OHOS_DEBUG int main(int argc, char **argv) { #ifndef OHOS_LITE if (setenv("UV_THREADPOOL_SIZE", "1", 1) != 0) { INIT_LOGE("set UV_THREADPOOL_SIZE error : %d.", errno); } CloseStdio(); OpenLogDevice(); #endif #ifdef OHOS_DEBUG struct timespec tmEnter; if (clock_gettime(CLOCK_REALTIME, &tmEnter) != 0) { INIT_LOGE("main, enter, get time failed! err %d.\n", errno); } #endif // OHOS_DEBUG if (getpid() != INIT_PROCESS_PID) { INIT_LOGE("main, current process id is %d not %d, failed!", getpid(), INIT_PROCESS_PID); return 0; } PrintSysInfo(); #ifndef OHOS_LITE MountBasicFs(); CreateDeviceNode(); EnableDevKmsg(); MakeDirRecursive("/dev/unix/socket", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); #endif SignalInitModule(); #ifdef OHOS_DEBUG struct timespec tmSysInfo; if (clock_gettime(CLOCK_REALTIME, &tmSysInfo) != 0) { INIT_LOGE("main, after sysinfo, get time failed! err %d.", errno); } #endif // OHOS_DEBUG ExecuteRcs(); #ifdef OHOS_DEBUG struct timespec tmRcs; if (clock_gettime(CLOCK_REALTIME, &tmRcs) != 0) { INIT_LOGE("main, after rcs, get time failed! err %d.", errno); } #endif // OHOS_DEBUG InitReadCfg(); #ifdef OHOS_DEBUG struct timespec tmCfg; if (clock_gettime(CLOCK_REALTIME, &tmCfg) != 0) { INIT_LOGE("main, get time failed! err %d.", errno); } #endif // OHOS_DEBUG #ifdef OHOS_DEBUG INIT_LOGI("main, time used: sigInfo %ld ms, rcs %ld ms, cfg %ld ms.", \ TimeDiffMs(&tmEnter, &tmSysInfo), TimeDiffMs(&tmSysInfo, &tmRcs), TimeDiffMs(&tmRcs, &tmCfg)); #endif INIT_LOGI("main, entering wait."); #ifndef OHOS_LITE StartParamService(); #endif while (1) { (void)pause(); } return 0; }