| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * tmon.c Thermal Monitor (TMON) main function and entry point |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2012 Intel Corporation. All rights reserved. |
|---|
| 5 | 6 | * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or |
|---|
| 7 | | - * modify it under the terms of the GNU General Public License version |
|---|
| 8 | | - * 2 or later as published by the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | 7 | * Author: Jacob Pan <jacob.jun.pan@linux.intel.com> |
|---|
| 16 | | - * |
|---|
| 17 | 8 | */ |
|---|
| 18 | 9 | |
|---|
| 19 | 10 | #include <getopt.h> |
|---|
| .. | .. |
|---|
| 55 | 46 | |
|---|
| 56 | 47 | pthread_t event_tid; |
|---|
| 57 | 48 | pthread_mutex_t input_lock; |
|---|
| 58 | | -void usage() |
|---|
| 49 | +void usage(void) |
|---|
| 59 | 50 | { |
|---|
| 60 | 51 | printf("Usage: tmon [OPTION...]\n"); |
|---|
| 61 | 52 | printf(" -c, --control cooling device in control\n"); |
|---|
| .. | .. |
|---|
| 71 | 62 | exit(0); |
|---|
| 72 | 63 | } |
|---|
| 73 | 64 | |
|---|
| 74 | | -void version() |
|---|
| 65 | +void version(void) |
|---|
| 75 | 66 | { |
|---|
| 76 | 67 | printf("TMON version %s\n", VERSION); |
|---|
| 77 | 68 | exit(EXIT_SUCCESS); |
|---|
| .. | .. |
|---|
| 79 | 70 | |
|---|
| 80 | 71 | static void tmon_cleanup(void) |
|---|
| 81 | 72 | { |
|---|
| 82 | | - |
|---|
| 83 | 73 | syslog(LOG_INFO, "TMON exit cleanup\n"); |
|---|
| 84 | 74 | fflush(stdout); |
|---|
| 85 | 75 | refresh(); |
|---|
| .. | .. |
|---|
| 105 | 95 | exit(1); |
|---|
| 106 | 96 | } |
|---|
| 107 | 97 | |
|---|
| 108 | | - |
|---|
| 109 | 98 | static void tmon_sig_handler(int sig) |
|---|
| 110 | 99 | { |
|---|
| 111 | 100 | syslog(LOG_INFO, "TMON caught signal %d\n", sig); |
|---|
| .. | .. |
|---|
| 128 | 117 | } |
|---|
| 129 | 118 | tmon_exit = true; |
|---|
| 130 | 119 | } |
|---|
| 131 | | - |
|---|
| 132 | 120 | |
|---|
| 133 | 121 | static void start_syslog(void) |
|---|
| 134 | 122 | { |
|---|
| .. | .. |
|---|
| 176 | 164 | return; |
|---|
| 177 | 165 | } |
|---|
| 178 | 166 | |
|---|
| 179 | | - |
|---|
| 180 | 167 | fprintf(tmon_log, "#----------- THERMAL SYSTEM CONFIG -------------\n"); |
|---|
| 181 | 168 | for (i = 0; i < ptdata.nr_tz_sensor; i++) { |
|---|
| 182 | 169 | char binding_str[33]; /* size of long + 1 */ |
|---|
| .. | .. |
|---|
| 184 | 171 | |
|---|
| 185 | 172 | memset(binding_str, 0, sizeof(binding_str)); |
|---|
| 186 | 173 | for (j = 0; j < 32; j++) |
|---|
| 187 | | - binding_str[j] = (ptdata.tzi[i].cdev_binding & 1<<j) ? |
|---|
| 174 | + binding_str[j] = (ptdata.tzi[i].cdev_binding & (1 << j)) ? |
|---|
| 188 | 175 | '1' : '0'; |
|---|
| 189 | 176 | |
|---|
| 190 | 177 | fprintf(tmon_log, "#thermal zone %s%02d cdevs binding: %32s\n", |
|---|
| .. | .. |
|---|
| 196 | 183 | trip_type_name[ptdata.tzi[i].tp[j].type], |
|---|
| 197 | 184 | ptdata.tzi[i].tp[j].temp); |
|---|
| 198 | 185 | } |
|---|
| 199 | | - |
|---|
| 200 | 186 | } |
|---|
| 201 | 187 | |
|---|
| 202 | 188 | for (i = 0; i < ptdata.nr_cooling_dev; i++) |
|---|
| .. | .. |
|---|
| 227 | 213 | { "debug", 0, NULL, 'g' }, |
|---|
| 228 | 214 | { 0, 0, NULL, 0 } |
|---|
| 229 | 215 | }; |
|---|
| 230 | | - |
|---|
| 231 | 216 | |
|---|
| 232 | 217 | int main(int argc, char **argv) |
|---|
| 233 | 218 | { |
|---|
| .. | .. |
|---|
| 292 | 277 | if (signal(SIGINT, tmon_sig_handler) == SIG_ERR) |
|---|
| 293 | 278 | syslog(LOG_DEBUG, "Cannot handle SIGINT\n"); |
|---|
| 294 | 279 | if (signal(SIGTERM, tmon_sig_handler) == SIG_ERR) |
|---|
| 295 | | - syslog(LOG_DEBUG, "Cannot handle SIGINT\n"); |
|---|
| 280 | + syslog(LOG_DEBUG, "Cannot handle SIGTERM\n"); |
|---|
| 296 | 281 | |
|---|
| 297 | 282 | if (probe_thermal_sysfs()) { |
|---|
| 298 | 283 | pthread_mutex_destroy(&input_lock); |
|---|
| .. | .. |
|---|
| 337 | 322 | show_cooling_device(); |
|---|
| 338 | 323 | } |
|---|
| 339 | 324 | time_elapsed += ticktime; |
|---|
| 340 | | - controller_handler(trec[0].temp[target_tz_index] / 1000, |
|---|
| 341 | | - &yk); |
|---|
| 325 | + controller_handler(trec[0].temp[target_tz_index] / 1000, &yk); |
|---|
| 342 | 326 | trec[0].pid_out_pct = yk; |
|---|
| 343 | 327 | if (!dialogue_on) |
|---|
| 344 | 328 | show_control_w(); |
|---|
| .. | .. |
|---|
| 349 | 333 | return 0; |
|---|
| 350 | 334 | } |
|---|
| 351 | 335 | |
|---|
| 352 | | -static void start_daemon_mode() |
|---|
| 336 | +static void start_daemon_mode(void) |
|---|
| 353 | 337 | { |
|---|
| 354 | 338 | daemon_mode = 1; |
|---|
| 355 | 339 | /* fork */ |
|---|
| 356 | 340 | pid_t sid, pid = fork(); |
|---|
| 357 | | - if (pid < 0) { |
|---|
| 341 | + |
|---|
| 342 | + if (pid < 0) |
|---|
| 358 | 343 | exit(EXIT_FAILURE); |
|---|
| 359 | | - } else if (pid > 0) |
|---|
| 344 | + else if (pid > 0) |
|---|
| 360 | 345 | /* kill parent */ |
|---|
| 361 | 346 | exit(EXIT_SUCCESS); |
|---|
| 362 | 347 | |
|---|
| .. | .. |
|---|
| 375 | 360 | if ((chdir("/")) < 0) |
|---|
| 376 | 361 | exit(EXIT_FAILURE); |
|---|
| 377 | 362 | |
|---|
| 378 | | - |
|---|
| 379 | 363 | sleep(10); |
|---|
| 380 | 364 | |
|---|
| 381 | 365 | close(STDIN_FILENO); |
|---|
| 382 | 366 | close(STDOUT_FILENO); |
|---|
| 383 | 367 | close(STDERR_FILENO); |
|---|
| 384 | | - |
|---|
| 385 | 368 | } |
|---|