common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / systemservice / system_manager / server / src / systemmanager_main.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_SystemManager
19 /// \brief    Application entry point.
20 ///
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>
29 #include <stdio.h>
30 #include <errno.h>
31 #include <fcntl.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <cstdlib>
35 #include <fstream>
36
37 #include "ss_sm_systemmanagerlog.h"
38 #include "ss_system_manager.h"
39
40
41 CFrameworkunifiedVersion g_FrameworkunifiedVersion(MAJORNO, MINORNO, REVISION);
42
43 /// \brief: Name of the Queue that will be used to read data from.
44 const CHAR AppName[] = SERVICE_SYSMANAGER;
45
46 static EFrameworkunifiedStatus ArgumentParser(SI_32 cc, PCHAR str) {
47   switch (cc) {
48     case 'b':
49         CSystemManager::m_bootOpt += str;
50         break;
51     default:
52         break;
53   }
54   return eFrameworkunifiedStatusOK;
55 }
56
57 //////////////////////////////////////////
58 //  Function : main
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)
64   int fd;
65 /*
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"
72             "    or \n"
73             " # sm &\n");
74     // LCOV_EXCL_STOP 
75     return -1;
76   }
77 */
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.
80     int ret;
81     ret = dup2(fd, 0);
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.
85   } else {
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.
89     // LCOV_EXCL_STOP
90   }
91
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.
99   // -m
100   // 0xFFFFFFFF,0xFFFFFFFF, where each bit represents a logging Zone.
101   // -c
102   // [configuration file..]
103
104   struct sched_param l_schedParam;
105
106   l_schedParam.sched_priority = PR_SS_SYSMANAGER;
107
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)
110   }
111
112   CustomCommandLineOptions l_tCmdLineOptions = { "b:", NULL, ArgumentParser };  // cShortOptions,rsv,callback
113   {
114     l_eStatus = FrameworkunifiedDispatcherWithArguments(AppName, argc, argv, &cbFuncs, &l_tCmdLineOptions);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
115   }
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)
118
119   return l_eStatus;
120 }  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)