• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
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 #include "llkd.h"
18 
19 #include <sched.h>
20 #include <sys/prctl.h>
21 #include <unistd.h>
22 
23 #include <chrono>
24 
25 #include <android-base/logging.h>
26 
27 using namespace std::chrono;
28 
main(int,char **)29 int main(int, char**) {
30     prctl(PR_SET_DUMPABLE, 0);
31 
32     LOG(INFO) << "started";
33 
34     bool enabled = llkInit();
35 
36     // Would like this policy to be automatic as part of libllkd,
37     // but that would be presumptuous and bad side-effect.
38     struct sched_param param;
39     memset(&param, 0, sizeof(param));
40     sched_setscheduler(0, SCHED_BATCH, &param);
41 
42     while (true) {
43         if (enabled) {
44             ::usleep(duration_cast<microseconds>(llkCheck()).count());
45         } else {
46             ::pause();
47         }
48     }
49     // NOTREACHED
50 
51     LOG(INFO) << "exiting";
52     return 0;
53 }
54