~ubuntu-branches/ubuntu/utopic/thermald/utopic

« back to all changes in this revision

Viewing changes to debian/patches/0002-android-build-cleanup.patch

  • Committer: Package Import Robot
  • Author(s): Colin King
  • Date: 2014-05-19 12:41:22 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140519124122-zan11arvjxtbqcq5
Tags: 1.2-1
* Adjust for coretemp path change
* Deny non root users to send system bus dbus messages
* Remove compile warning
* Remove rpmlint warning for manual page
* Remove old patches that are now included into version 1.2
* Sync up with version 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
5
 
 
6
 
Changes:
7
 
- android_main:
8
 
Fixed daemon name and removed unused variables. Also updated
9
 
version number.
10
 
- removed android_main_dbus.c
11
 
- Removed dependency on config.h
12
 
---
13
 
 android_main_dbus.cpp | 394 --------------------------------------------------
14
 
 src/android_main.cpp  |  32 ++--
15
 
 src/thermald.h        |   7 +-
16
 
 3 files changed, 19 insertions(+), 414 deletions(-)
17
 
 delete mode 100644 android_main_dbus.cpp
18
 
 
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
23
 
+++ /dev/null
24
 
@@ -1,394 +0,0 @@
25
 
-/*
26
 
- * android_main.cpp: Thermal Daemon entry point tuned for Android
27
 
- *
28
 
- * Copyright (C) 2013 Intel Corporation. All rights reserved.
29
 
- *
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.
33
 
- *
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.
38
 
- *
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
42
 
- * 02110-1301, USA.
43
 
- *
44
 
- *
45
 
- * Author Name <Srinivas.Pandruvada@linux.intel.com>
46
 
- *
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
49
 
- * functions.
50
 
- */
51
 
-
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"
58
 
-
59
 
-#define THERMALD_DAEMON_NAME   "thermald"
60
 
-
61
 
-// poll mode
62
 
-int thd_poll_interval = 4; //in seconds
63
 
-static int pid_file_handle;
64
 
-
65
 
-// Thermal engine
66
 
-cthd_engine *thd_engine;
67
 
-static DBusConnection *dbus_conn;
68
 
-
69
 
-// Start dbus server
70
 
-static int thermald_dbus_server_start() {
71
 
-       DBusError err;
72
 
-       int ret;
73
 
-       char* param;
74
 
-
75
 
-       dbus_error_init(&err);
76
 
-
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);
81
 
-       }
82
 
-       if (NULL == dbus_conn) {
83
 
-               thd_log_fatal("Connection Null\n");
84
 
-               exit(1);
85
 
-       }
86
 
-
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);
92
 
-       }
93
 
-       if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
94
 
-               thd_log_fatal("Not Primary Owner (%d)\n", ret);
95
 
-               exit(1);
96
 
-       }
97
 
-       thd_log_info("thermald dbus server started \n");
98
 
-
99
 
-       return 0;
100
 
-}
101
 
-
102
 
-// Stop dbus server
103
 
-static void thermald_dbus_server_stop() {
104
 
-       if (dbus_conn)
105
 
-               dbus_connection_close(dbus_conn);
106
 
-}
107
 
-
108
 
-// Stop daemon
109
 
-static void daemonShutdown() {
110
 
-       if (dbus_conn)
111
 
-               thermald_dbus_server_stop();
112
 
-       if (pid_file_handle)
113
 
-               close(pid_file_handle);
114
 
-       thd_engine->thd_engine_terminate();
115
 
-       sleep(1);
116
 
-       delete thd_engine;
117
 
-}
118
 
-
119
 
-// Stop daemon
120
 
-static void thermald_dbus_listen() {
121
 
-       DBusMessage *msg;
122
 
-       DBusMessage *reply;
123
 
-       DBusMessageIter args;
124
 
-       const char *method;
125
 
-
126
 
-       while (true) {
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");
131
 
-
132
 
-               while (read_msg) {
133
 
-                       msg = dbus_connection_pop_message(dbus_conn);
134
 
-
135
 
-                       // loop again if we haven't got a message
136
 
-                       if (NULL == msg) {
137
 
-                               read_msg = false;
138
 
-                               break;
139
 
-                       }
140
 
-                       method = dbus_message_get_member(msg);
141
 
-                       if (!method) {
142
 
-                               dbus_message_unref(msg);
143
 
-                               read_msg = false;
144
 
-                               break;
145
 
-                       }
146
 
-                       thd_log_info("Received dbus msg %s\n", method);
147
 
-
148
 
-                       if (!strcasecmp(method, "SetUserMaxTemperature")) {
149
 
-                               bool status;
150
 
-                               char *zone_name;
151
 
-                               char *set_point;
152
 
-                               DBusError error;
153
 
-
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);
163
 
-                               } else {
164
 
-                                       thd_log_error("dbus_message_get_args failed %s\n",
165
 
-                                                       error.message);
166
 
-                               }
167
 
-                               dbus_error_free(&error);
168
 
-                       } else if (!strcasecmp(method, "SetCurrentPreference")) {
169
 
-                               bool status;
170
 
-                               char *pref_str;
171
 
-                               DBusError error;
172
 
-
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);
180
 
-                               } else {
181
 
-                                       thd_log_error("dbus_message_get_args failed %s\n",
182
 
-                                                       error.message);
183
 
-                               }
184
 
-                               dbus_error_free(&error);
185
 
-                       } else if (!strcasecmp(method, "CalibrateStart")) {
186
 
-                               // TBD
187
 
-                       } else if (!strcasecmp(method, "CalibrateEnd")) {
188
 
-                               // TBD
189
 
-                       } else if (!strcasecmp(method, "Terminate")) {
190
 
-                               daemonShutdown();
191
 
-                               exit(EXIT_SUCCESS);
192
 
-                       } else {
193
 
-                               thd_log_error("dbus_message_get_args Invalid Message\n");
194
 
-                       }
195
 
-
196
 
-                       // free the message
197
 
-                       dbus_message_unref(msg);
198
 
-               }
199
 
-       }
200
 
-}
201
 
-
202
 
-// signal handler
203
 
-static void signal_handler(int sig) {
204
 
-       switch (sig) {
205
 
-       case SIGHUP:
206
 
-               thd_log_warn("Received SIGHUP signal. \n");
207
 
-               break;
208
 
-       case SIGINT:
209
 
-       case SIGTERM:
210
 
-               thd_log_info("Daemon exiting \n");
211
 
-               daemonShutdown();
212
 
-               exit(EXIT_SUCCESS);
213
 
-               break;
214
 
-       default:
215
 
-               thd_log_warn("Unhandled signal %s", strsignal(sig));
216
 
-               break;
217
 
-       }
218
 
-}
219
 
-
220
 
-static void daemonize(char *rundir, char *pidfile) {
221
 
-       int pid, sid, i;
222
 
-       char str[10];
223
 
-       struct sigaction sig_actions;
224
 
-       sigset_t sig_set;
225
 
-
226
 
-       if (getppid() == 1) {
227
 
-               return;
228
 
-       }
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);
235
 
-
236
 
-       sig_actions.sa_handler = signal_handler;
237
 
-       sigemptyset(&sig_actions.sa_mask);
238
 
-       sig_actions.sa_flags = 0;
239
 
-
240
 
-       sigaction(SIGHUP, &sig_actions, NULL);
241
 
-       sigaction(SIGTERM, &sig_actions, NULL);
242
 
-       sigaction(SIGINT, &sig_actions, NULL);
243
 
-
244
 
-       pid = fork();
245
 
-       if (pid < 0) {
246
 
-               /* Could not fork */
247
 
-               exit(EXIT_FAILURE);
248
 
-       }
249
 
-       if (pid > 0) {
250
 
-               thd_log_info("Child process created: %d\n", pid);
251
 
-               exit(EXIT_SUCCESS);
252
 
-       }
253
 
-       umask(027);
254
 
-
255
 
-       sid = setsid();
256
 
-       if (sid < 0) {
257
 
-               exit(EXIT_FAILURE);
258
 
-       }
259
 
-       /* close all descriptors */
260
 
-       for (i = getdtablesize(); i >= 0; --i) {
261
 
-               close(i);
262
 
-       }
263
 
-
264
 
-       i = open("/dev/null", O_RDWR);
265
 
-       dup(i);
266
 
-       dup(i);
267
 
-       chdir(rundir);
268
 
-
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);
273
 
-               exit(1);
274
 
-       }
275
 
-       /* Try to lock file */
276
 
-#ifdef LOCKF_SUPPORT
277
 
-       if (lockf(pid_file_handle, F_TLOCK, 0) == -1) {
278
 
-#else
279
 
-               if (flock(pid_file_handle,LOCK_EX|LOCK_NB) < 0) {
280
 
-#endif
281
 
-               /* Couldn't get lock on lock file */
282
 
-               thd_log_info("Couldn't get lock file %d\n", getpid());
283
 
-               exit(1);
284
 
-       }
285
 
-       thd_log_info("Thermal PID %d\n", getpid());
286
 
-       sprintf(str, "%d\n", getpid());
287
 
-       write(pid_file_handle, str, strlen(str));
288
 
-}
289
 
-
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");
298
 
-
299
 
-       exit(exit_code);
300
 
-}
301
 
-
302
 
-int main(int argc, char *argv[]) {
303
 
-       int c;
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;
309
 
-
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 } };
317
 
-
318
 
-       if (argc > 1) {
319
 
-               while ((c = getopt_long(argc, argv, short_options, long_options,
320
 
-                               &option_index)) != -1) {
321
 
-                       int this_option_optind = optind ? optind : 1;
322
 
-                       switch (c) {
323
 
-                       case 'h':
324
 
-                               print_usage(stdout, 0);
325
 
-                               break;
326
 
-                       case 'v':
327
 
-                               fprintf(stdout, "1.03-01\n");
328
 
-                               exit(0);
329
 
-                               break;
330
 
-                       case 'n':
331
 
-                               no_daemon = true;
332
 
-                               break;
333
 
-                       case 'd':
334
 
-                               dbus_enable = true;
335
 
-                               break;
336
 
-                       case 'p':
337
 
-                               thd_poll_interval = atoi(optarg);
338
 
-                               break;
339
 
-                       case 'e':
340
 
-                               exclusive_control = true;
341
 
-                               break;
342
 
-                       case 't':
343
 
-                               test_mode = true;
344
 
-                               break;
345
 
-                       case -1:
346
 
-                       case 0:
347
 
-                               break;
348
 
-                       default:
349
 
-                               break;
350
 
-                       }
351
 
-               }
352
 
-       }
353
 
-       if (getuid() != 0 && !test_mode) {
354
 
-               fprintf(stderr, "You must be root to run thermal daemon!\n");
355
 
-               exit(1);
356
 
-       }
357
 
-
358
 
-       if ((c = mkdir(TDRUNDIR, 0755)) != 0) {
359
 
-               if (errno != EEXIST) {
360
 
-                       fprintf(stderr, "Cannot create '%s': %s\n", TDRUNDIR,
361
 
-                                       strerror(errno));
362
 
-                       exit(1);
363
 
-               }
364
 
-       }
365
 
-       mkdir(TDCONFDIR, 0755); // Don't care return value as directory
366
 
-       if (!no_daemon) {
367
 
-               daemonize((char *) "/tmp/", (char *) "/tmp/thermald.pid");
368
 
-       } else
369
 
-               signal(SIGINT, signal_handler);
370
 
-
371
 
-       thd_log_info(
372
 
-                       "Linux Thermal Daemon is starting mode %d : poll_interval %d :ex_control %d\n",
373
 
-                       no_daemon, thd_poll_interval, exclusive_control);
374
 
-
375
 
-       thd_engine = new cthd_engine_default();
376
 
-       if (exclusive_control)
377
 
-               thd_engine->set_control_mode(EXCLUSIVE);
378
 
-
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: ");
382
 
-               exit(1);
383
 
-       }
384
 
-
385
 
-       // Initialize thermald objects
386
 
-       if (thd_engine->thd_engine_start(false) != THD_SUCCESS) {
387
 
-               thd_log_error("thermald engine start failed: ");
388
 
-               exit(1);
389
 
-       }
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.
394
 
-       sleep(10);
395
 
-       if (dbus_conn)
396
 
-       thermald_dbus_server_stop();
397
 
-       if (pid_file_handle)
398
 
-       close(pid_file_handle);
399
 
-       thd_engine->thd_engine_terminate();
400
 
-       sleep(1);
401
 
-       delete thd_engine;
402
 
-#else
403
 
-       if (dbus_enable) {
404
 
-               if (thermald_dbus_server_start()) {
405
 
-                       fprintf(stderr, "Dbus start error\n");
406
 
-                       exit(1);
407
 
-               }
408
 
-               thermald_dbus_listen(); // Will block here
409
 
-               thermald_dbus_server_stop();
410
 
-       } else {
411
 
-               for (;;)
412
 
-                       sleep(0xffff);
413
 
-       }
414
 
-
415
 
-       thd_log_info("Linux Thermal Daemon is exiting \n");
416
 
-#endif
417
 
-       return 0;
418
 
-}
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
423
 
@@ -21,8 +21,8 @@
424
 
  * Author Name <Srinivas.Pandruvada@linux.intel.com>
425
 
  *
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
428
 
- * functions.
429
 
+ * which parses command line arguments, setup logs and starts thermal
430
 
+ * engine.
431
 
  */
432
 
 
433
 
 #include "thermald.h"
434
 
@@ -31,8 +31,6 @@
435
 
 #include "thd_engine_default.h"
436
 
 #include "thd_parse.h"
437
 
 
438
 
-#define THERMALD_DAEMON_NAME   "thermald"
439
 
-
440
 
 // poll mode
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) {
444
 
 }
445
 
 
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");
456
 
 
457
 
        exit(exit_code);
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;
464
 
 
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 } };
480
 
 
481
 
        if (argc > 1) {
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);
485
 
                                break;
486
 
                        case 'v':
487
 
-                               fprintf(stdout, "1.03-01\n");
488
 
+                               fprintf(stdout, "1.1\n");
489
 
                                exit(0);
490
 
                                break;
491
 
                        case 'n':
492
 
                                no_daemon = true;
493
 
                                break;
494
 
-                       case 'd':
495
 
-                               dbus_enable = true;
496
 
-                               break;
497
 
                        case 'p':
498
 
                                thd_poll_interval = atoi(optarg);
499
 
                                break;
500
 
diff --git a/src/thermald.h b/src/thermald.h
501
 
index ce64382..ddc406a 100644
502
 
--- a/src/thermald.h
503
 
+++ b/src/thermald.h
504
 
@@ -38,9 +38,8 @@
505
 
 #include <string.h>
506
 
 #include <signal.h>
507
 
 
508
 
-#include "config.h"
509
 
-
510
 
 #ifdef ANDROID
511
 
+
512
 
 #define LOG_NDEBUG 1
513
 
 #undef LOG_TAG
514
 
 #define LOG_TAG "THERMALD"
515
 
@@ -53,7 +52,11 @@
516
 
 #define thd_log_warn   ALOGW
517
 
 #define thd_log_info   ALOGD
518
 
 #define thd_log_debug  ALOGV
519
 
+
520
 
 #else
521
 
+
522
 
+#include "config.h"
523
 
+
524
 
 #define LOCKF_SUPPORT
525
 
 #ifdef GLIBC_SUPPORT
526
 
 #include <glib.h>
527
 
1.8.5.3
528