2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_SystemManager
19 /// \brief Application entry point.
21 ///////////////////////////////////////////////////////////////////////////////
22 #include <system_service/ss_system_if.h>
23 #include <native_service/frameworkunified_dispatcher.h>
24 #include <native_service/ns_version_if.h>
25 #include <system_service/ss_services.h>
26 #include <system_service/ss_string_maps.h>
27 #include <system_service/ss_version.h>
28 #include <system_service/ss_system_types.h>
32 #include <sys/types.h>
37 #include "ss_sm_systemmanagerlog.h"
38 #include "ss_system_manager.h"
41 CFrameworkunifiedVersion g_FrameworkunifiedVersion(MAJORNO, MINORNO, REVISION);
43 /// \brief: Name of the Queue that will be used to read data from.
44 const CHAR AppName[] = SERVICE_SYSMANAGER;
46 static EFrameworkunifiedStatus ArgumentParser(SI_32 cc, PCHAR str) {
49 CSystemManager::m_bootOpt += str;
54 return eFrameworkunifiedStatusOK;
57 //////////////////////////////////////////
59 //////////////////////////////////////////
60 int main(int argc, char *argv[]) {
61 EFrameworkunifiedStatus l_eStatus;
62 FrameworkunifiedDefaultCallbackHandler cbFuncs;
63 FRAMEWORKUNIFIED_MAKE_DEFAULT_CALLBACK(cbFuncs); // LCOV_EXCL_BR_LINE 15: marco defined in ss-system_if.h // NOLINT(whitespace/line_length)
66 if (geteuid() == 0) { // LCOV_EXCL_BR_LINE 200: process cannot be executed by root
67 // LCOV_EXCL_START 200: process cannot be executed by root
68 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
69 printf("System cannot be started by root user!!\n"
70 "You can start system: \n"
71 " # sm > /dev/null &\n"
78 fd = open("/dev/null", O_RDONLY); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length)
79 if (fd > 0) { // LCOV_EXCL_BR_LINE 5: open file error case.
82 if (ret == -1) perror("dup2"); // LCOV_EXCL_BR_LINE 5: dup2 error case.
83 ret = close(fd); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length)
84 if (ret == -1) perror("close"); // LCOV_EXCL_BR_LINE 5: close error case.
86 // LCOV_EXCL_START 5: open file error case.
87 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
88 perror("open"); // LCOV_EXCL_LINE 5: open file error case.
92 // This allows overriding the already-passed-in System Manager's command
93 // line arguments by having a file exist named
94 // "/agl/rwdata/<this_file's_base_name>.args".
95 // For example, when this file is named 'SS_SystemManager', then
96 // if '/agl/rwdata/SS_SystemManager.args' is present, then the
97 // '/agl/rwdata/SS_SystemManager.args' strings are read as command line
98 // values and are passed to the FrameworkunifiedDispatcher() function.
100 // 0xFFFFFFFF,0xFFFFFFFF, where each bit represents a logging Zone.
102 // [configuration file..]
104 struct sched_param l_schedParam;
106 l_schedParam.sched_priority = PR_SS_SYSMANAGER;
108 if (0 != sched_setscheduler(getpid(), SCHED_FIFO, &l_schedParam)) { // LCOV_EXCL_BR_LINE 5: sched_setscheduler error case. // NOLINT(whitespace/line_length)
109 printf("ASSERT %d:%s\n", errno, strerror(errno)); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length)
112 CustomCommandLineOptions l_tCmdLineOptions = { "b:", NULL, ArgumentParser }; // cShortOptions,rsv,callback
114 l_eStatus = FrameworkunifiedDispatcherWithArguments(AppName, argc, argv, &cbFuncs, &l_tCmdLineOptions); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length)
116 printf("SM: Line %d: FrameworkunifiedDispatcherWithArguments() returned l_eStatus: '%d'/'%s'\n", // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length)
117 __LINE__, l_eStatus, GetStr(l_eStatus).c_str()); // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length)
120 } // LCOV_EXCL_BR_LINE 11:unexpected branch // NOLINT(whitespace/line_length)