RDK Documentation (Open Sourced RDK Components)
acm_main.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 #include <unistd.h>
20 #include "audio_capture_manager.h"
21 #include "music_id.h"
22 #include "acm_session_mgr.h"
23 #if defined(DROP_ROOT_PRIV)
24 #include "cap.h"
25 #endif
26 
27 #if defined(DROP_ROOT_PRIV)
28 static bool drop_root()
29 {
30  bool ret = false,retval = false;
31  cap_user appcaps = {{0, 0, 0, '\0', 0, 0, 0, '\0'}};
32  ret = isBlocklisted();
33  if(ret)
34  {
35  INFO("NonRoot feature is disabled\n");
36  }
37  else
38  {
39  INFO("NonRoot feature is enabled\n");
40  appcaps.caps = NULL;
41  appcaps.user_name = NULL;
42  if(init_capability() != NULL) {
43  if(drop_root_caps(&appcaps) != -1) {
44  if(update_process_caps(&appcaps) != -1) {
45  read_capability(&appcaps);
46  retval = true;
47  }
48  }
49  }
50  }
51  return retval;
52 }
53 #endif
54 
55 void launcher()
56 {
57  acm_session_mgr *mgr = acm_session_mgr::get_instance();
58  mgr->activate();
59  /* Hold here until application is terminated.*/
60  pause();
61  mgr->deactivate();
62 }
63 
64 
65 int main(int argc, char *argv[])
66 {
67  setlinebuf(stdout); //otherwise logs may take forever to get flushed to journald
68 #if defined(DROP_ROOT_PRIV)
69  if(!drop_root())
70  {
71  ERROR("drop_root function failed!\n");
72  }
73 #endif
74  launcher();
75  return 0;
76 }
acm_session_mgr::activate
int activate()
This API initializes the message bus, registers event, RPC methods to be used by other applications.
Definition: acm_session_mgr.cpp:152
acm_session_mgr
Definition: acm_session_mgr.h:40
acm_session_mgr::deactivate
int deactivate()
This API disconnects application from the message bus, releases memory.
Definition: acm_session_mgr.cpp:179