1
From 4d9fba1d7b993634a6a4906d2e910842d6e7b21e Mon Sep 17 00:00:00 2001
2
From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
3
Date: Fri, 10 Jan 2014 21:08:44 -0800
4
Subject: [PATCH] android build cleanup
8
Fixed daemon name and removed unused variables. Also updated
10
- removed android_main_dbus.c
11
- Removed dependency on config.h
13
android_main_dbus.cpp | 394 --------------------------------------------------
14
src/android_main.cpp | 32 ++--
16
3 files changed, 19 insertions(+), 414 deletions(-)
17
delete mode 100644 android_main_dbus.cpp
19
diff --git a/android_main_dbus.cpp b/android_main_dbus.cpp
20
deleted file mode 100644
21
index 9c7e347..0000000
22
--- a/android_main_dbus.cpp
26
- * android_main.cpp: Thermal Daemon entry point tuned for Android
28
- * Copyright (C) 2013 Intel Corporation. All rights reserved.
30
- * This program is free software; you can redistribute it and/or
31
- * modify it under the terms of the GNU General Public License version
32
- * 2 or later as published by the Free Software Foundation.
34
- * This program is distributed in the hope that it will be useful,
35
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
36
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37
- * GNU General Public License for more details.
39
- * You should have received a copy of the GNU General Public License
40
- * along with this program; if not, write to the Free Software
41
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
45
- * Author Name <Srinivas.Pandruvada@linux.intel.com>
47
- * This is the main entry point for thermal daemon. This has main function
48
- * which parses command line arguments, set up dbus server and log related
52
-#include <dbus/dbus.h>
53
-#include "thermald.h"
54
-#include "thd_preference.h"
55
-#include "thd_engine.h"
56
-#include "thd_engine_default.h"
57
-#include "thd_parse.h"
59
-#define THERMALD_DAEMON_NAME "thermald"
62
-int thd_poll_interval = 4; //in seconds
63
-static int pid_file_handle;
66
-cthd_engine *thd_engine;
67
-static DBusConnection *dbus_conn;
70
-static int thermald_dbus_server_start() {
75
- dbus_error_init(&err);
77
- dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
78
- if (dbus_error_is_set(&err)) {
79
- thd_log_fatal("Connection Error (%s)\n", err.message);
80
- dbus_error_free(&err);
82
- if (NULL == dbus_conn) {
83
- thd_log_fatal("Connection Null\n");
87
- ret = dbus_bus_request_name(dbus_conn, THD_SERVICE_NAME,
88
- DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
89
- if (dbus_error_is_set(&err)) {
90
- thd_log_fatal("Name Error (%s)\n", err.message);
91
- dbus_error_free(&err);
93
- if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
94
- thd_log_fatal("Not Primary Owner (%d)\n", ret);
97
- thd_log_info("thermald dbus server started \n");
103
-static void thermald_dbus_server_stop() {
105
- dbus_connection_close(dbus_conn);
109
-static void daemonShutdown() {
111
- thermald_dbus_server_stop();
112
- if (pid_file_handle)
113
- close(pid_file_handle);
114
- thd_engine->thd_engine_terminate();
120
-static void thermald_dbus_listen() {
122
- DBusMessage *reply;
123
- DBusMessageIter args;
124
- const char *method;
127
- bool read_msg = true;
128
- // Blocking read of the next available message
129
- dbus_connection_read_write(dbus_conn, -1);
130
- thd_log_debug("Got some dbus message... \n");
133
- msg = dbus_connection_pop_message(dbus_conn);
135
- // loop again if we haven't got a message
140
- method = dbus_message_get_member(msg);
142
- dbus_message_unref(msg);
146
- thd_log_info("Received dbus msg %s\n", method);
148
- if (!strcasecmp(method, "SetUserMaxTemperature")) {
154
- dbus_error_init(&error);
155
- if (dbus_message_get_args(msg, &error, DBUS_TYPE_STRING,
156
- &zone_name, DBUS_TYPE_STRING, &set_point,
157
- DBUS_TYPE_INVALID)) {
158
- thd_log_info("New Set Point %s\n", set_point);
159
- cthd_preference thd_pref;
160
- if (thd_engine->thd_engine_set_user_max_temp(zone_name,
161
- set_point) == THD_SUCCESS)
162
- thd_engine->send_message(PREF_CHANGED, 0, NULL);
164
- thd_log_error("dbus_message_get_args failed %s\n",
167
- dbus_error_free(&error);
168
- } else if (!strcasecmp(method, "SetCurrentPreference")) {
173
- dbus_error_init(&error);
174
- if (dbus_message_get_args(msg, &error, DBUS_TYPE_STRING,
175
- &pref_str, DBUS_TYPE_INVALID)) {
176
- thd_log_info("New Pref %s\n", pref_str);
177
- cthd_preference thd_pref;
178
- thd_pref.set_preference(pref_str);
179
- thd_engine->send_message(PREF_CHANGED, 0, NULL);
181
- thd_log_error("dbus_message_get_args failed %s\n",
184
- dbus_error_free(&error);
185
- } else if (!strcasecmp(method, "CalibrateStart")) {
187
- } else if (!strcasecmp(method, "CalibrateEnd")) {
189
- } else if (!strcasecmp(method, "Terminate")) {
191
- exit(EXIT_SUCCESS);
193
- thd_log_error("dbus_message_get_args Invalid Message\n");
196
- // free the message
197
- dbus_message_unref(msg);
203
-static void signal_handler(int sig) {
206
- thd_log_warn("Received SIGHUP signal. \n");
210
- thd_log_info("Daemon exiting \n");
212
- exit(EXIT_SUCCESS);
215
- thd_log_warn("Unhandled signal %s", strsignal(sig));
220
-static void daemonize(char *rundir, char *pidfile) {
223
- struct sigaction sig_actions;
226
- if (getppid() == 1) {
229
- sigemptyset(&sig_set);
230
- sigaddset(&sig_set, SIGCHLD);
231
- sigaddset(&sig_set, SIGTSTP);
232
- sigaddset(&sig_set, SIGTTOU);
233
- sigaddset(&sig_set, SIGTTIN);
234
- sigprocmask(SIG_BLOCK, &sig_set, NULL);
236
- sig_actions.sa_handler = signal_handler;
237
- sigemptyset(&sig_actions.sa_mask);
238
- sig_actions.sa_flags = 0;
240
- sigaction(SIGHUP, &sig_actions, NULL);
241
- sigaction(SIGTERM, &sig_actions, NULL);
242
- sigaction(SIGINT, &sig_actions, NULL);
246
- /* Could not fork */
247
- exit(EXIT_FAILURE);
250
- thd_log_info("Child process created: %d\n", pid);
251
- exit(EXIT_SUCCESS);
257
- exit(EXIT_FAILURE);
259
- /* close all descriptors */
260
- for (i = getdtablesize(); i >= 0; --i) {
264
- i = open("/dev/null", O_RDWR);
269
- pid_file_handle = open(pidfile, O_RDWR | O_CREAT, 0600);
270
- if (pid_file_handle == -1) {
271
- /* Couldn't open lock file */
272
- thd_log_info("Could not open PID lock file %s, exiting", pidfile);
275
- /* Try to lock file */
276
-#ifdef LOCKF_SUPPORT
277
- if (lockf(pid_file_handle, F_TLOCK, 0) == -1) {
279
- if (flock(pid_file_handle,LOCK_EX|LOCK_NB) < 0) {
281
- /* Couldn't get lock on lock file */
282
- thd_log_info("Couldn't get lock file %d\n", getpid());
285
- thd_log_info("Thermal PID %d\n", getpid());
286
- sprintf(str, "%d\n", getpid());
287
- write(pid_file_handle, str, strlen(str));
290
-static void print_usage(FILE* stream, int exit_code) {
291
- fprintf(stream, "Usage: dptf_if options [ ... ]\n");
292
- fprintf(stream, " --help Display this usage information.\n"
293
- " --version Show version.\n"
294
- " --no-daemon No daemon.\n"
295
- " -poll-interval poll interval 0 to disable.\n"
296
- " --dbus-enable Enable dbus I/F.\n"
297
- " --exclusive_control to act as exclusive thermal controller. \n");
302
-int main(int argc, char *argv[]) {
304
- int option_index = 0;
305
- bool no_daemon = false;
306
- bool exclusive_control = false;
307
- bool dbus_enable = false;
308
- bool test_mode = false;
310
- const char* const short_options = "hvnp:de";
311
- static struct option long_options[] = { { "help", no_argument, 0, 'h' }, {
312
- "version", no_argument, 0, 'v' },
313
- { "no-daemon", no_argument, 0, 'n' }, { "poll-interval",
314
- required_argument, 0, 'p' }, { "dbus-enable", no_argument,
315
- 0, 'd' }, { "exclusive_control", no_argument, 0, 'e' }, {
316
- "test-mode", no_argument, 0, 't' }, { NULL, 0, NULL, 0 } };
319
- while ((c = getopt_long(argc, argv, short_options, long_options,
320
- &option_index)) != -1) {
321
- int this_option_optind = optind ? optind : 1;
324
- print_usage(stdout, 0);
327
- fprintf(stdout, "1.03-01\n");
334
- dbus_enable = true;
337
- thd_poll_interval = atoi(optarg);
340
- exclusive_control = true;
353
- if (getuid() != 0 && !test_mode) {
354
- fprintf(stderr, "You must be root to run thermal daemon!\n");
358
- if ((c = mkdir(TDRUNDIR, 0755)) != 0) {
359
- if (errno != EEXIST) {
360
- fprintf(stderr, "Cannot create '%s': %s\n", TDRUNDIR,
365
- mkdir(TDCONFDIR, 0755); // Don't care return value as directory
367
- daemonize((char *) "/tmp/", (char *) "/tmp/thermald.pid");
369
- signal(SIGINT, signal_handler);
372
- "Linux Thermal Daemon is starting mode %d : poll_interval %d :ex_control %d\n",
373
- no_daemon, thd_poll_interval, exclusive_control);
375
- thd_engine = new cthd_engine_default();
376
- if (exclusive_control)
377
- thd_engine->set_control_mode(EXCLUSIVE);
379
- thd_engine->set_poll_interval(thd_poll_interval);
380
- if (thd_engine->thd_engine_start(false) != THD_SUCCESS) {
381
- thd_log_error("THD engine start failed: ");
385
- // Initialize thermald objects
386
- if (thd_engine->thd_engine_start(false) != THD_SUCCESS) {
387
- thd_log_error("thermald engine start failed: ");
390
-#ifdef VALGRIND_TEST
391
- // lots of STL lib function don't free memory
392
- // when called with exit() fn.
393
- // Here just run for some time and gracefully return.
396
- thermald_dbus_server_stop();
397
- if (pid_file_handle)
398
- close(pid_file_handle);
399
- thd_engine->thd_engine_terminate();
404
- if (thermald_dbus_server_start()) {
405
- fprintf(stderr, "Dbus start error\n");
408
- thermald_dbus_listen(); // Will block here
409
- thermald_dbus_server_stop();
415
- thd_log_info("Linux Thermal Daemon is exiting \n");
419
diff --git a/src/android_main.cpp b/src/android_main.cpp
420
index 2c4078e..ba1251d 100644
421
--- a/src/android_main.cpp
422
+++ b/src/android_main.cpp
424
* Author Name <Srinivas.Pandruvada@linux.intel.com>
426
* This is the main entry point for thermal daemon. This has main function
427
- * which parses command line arguments, set up dbus server and log related
429
+ * which parses command line arguments, setup logs and starts thermal
433
#include "thermald.h"
435
#include "thd_engine_default.h"
436
#include "thd_parse.h"
438
-#define THERMALD_DAEMON_NAME "thermald"
441
int thd_poll_interval = 4; //in seconds
442
static int pid_file_handle;
443
@@ -138,11 +136,11 @@ static void daemonize(char *rundir, char *pidfile) {
446
static void print_usage(FILE* stream, int exit_code) {
447
- fprintf(stream, "Usage: dptf_if options [ ... ]\n");
448
- fprintf(stream, " --help Display this usage information.\n"
449
+ fprintf(stream, "Usage: thermal-daemon options [ ... ]\n");
450
+ fprintf(stream, " --help Display this usage information.\n"
451
" --version Show version.\n"
452
" --no-daemon No daemon.\n"
453
- " -poll-interval poll interval 0 to disable.\n"
454
+ " --poll-interval poll interval 0 to disable.\n"
455
" --exclusive_control to act as exclusive thermal controller. \n");
458
@@ -153,16 +151,17 @@ int main(int argc, char *argv[]) {
459
int option_index = 0;
460
bool no_daemon = false;
461
bool exclusive_control = false;
462
- bool dbus_enable = false;
463
bool test_mode = false;
465
const char* const short_options = "hvnp:de";
466
- static struct option long_options[] = { { "help", no_argument, 0, 'h' }, {
467
- "version", no_argument, 0, 'v' },
468
- { "no-daemon", no_argument, 0, 'n' }, { "poll-interval",
469
- required_argument, 0, 'p' }, { "dbus-enable", no_argument,
470
- 0, 'd' }, { "exclusive_control", no_argument, 0, 'e' }, {
471
- "test-mode", no_argument, 0, 't' }, { NULL, 0, NULL, 0 } };
472
+ static struct option long_options[] = {
473
+ { "help", no_argument, 0, 'h' },
474
+ { "version", no_argument, 0, 'v' },
475
+ { "no-daemon", no_argument, 0, 'n' },
476
+ { "poll-interval", required_argument, 0, 'p' },
477
+ { "exclusive_control", no_argument, 0, 'e' },
478
+ { "test-mode", no_argument, 0, 't' },
479
+ { NULL, 0, NULL, 0 } };
482
while ((c = getopt_long(argc, argv, short_options, long_options,
483
@@ -173,15 +172,12 @@ int main(int argc, char *argv[]) {
484
print_usage(stdout, 0);
487
- fprintf(stdout, "1.03-01\n");
488
+ fprintf(stdout, "1.1\n");
495
- dbus_enable = true;
498
thd_poll_interval = atoi(optarg);
500
diff --git a/src/thermald.h b/src/thermald.h
501
index ce64382..ddc406a 100644
514
#define LOG_TAG "THERMALD"
516
#define thd_log_warn ALOGW
517
#define thd_log_info ALOGD
518
#define thd_log_debug ALOGV
524
#define LOCKF_SUPPORT