tools/thermal/tmon/tmon.c
Source file repositories/reference/linux-study-clean/tools/thermal/tmon/tmon.c
File Facts
- System
- Linux kernel
- Corpus path
tools/thermal/tmon/tmon.c- Extension
.c- Size
- 8625 bytes
- Lines
- 369
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
getopt.hunistd.hstdio.hstdlib.hstring.hsys/types.hsys/stat.hncurses.hctype.htime.hsignal.hlimits.hsys/time.hpthread.hmath.hstdarg.hsyslog.htmon.h
Detected Declarations
function usagefunction versionfunction tmon_cleanupfunction tmon_sig_handlerfunction start_syslogfunction prepare_loggingfunction mainfunction start_daemon_mode
Annotated Snippet
switch (c) {
case 'c':
no_control = 0;
strncpy(ctrl_cdev, optarg, CDEV_NAME_SIZE);
break;
case 'd':
start_daemon_mode();
printf("Run TMON in daemon mode\n");
break;
case 't':
ticktime = strtod(optarg, NULL);
if (ticktime < 1)
ticktime = 1;
break;
case 'T':
temp = strtod(optarg, NULL);
if (temp < 0) {
fprintf(stderr, "error: temperature must be positive\n");
return 1;
}
target_temp_user = temp;
break;
case 'l':
printf("Logging data to /var/tmp/tmon.log\n");
logging = 1;
break;
case 'h':
usage();
break;
case 'v':
version();
break;
case 'g':
debug_on = 1;
break;
case 'z':
target_thermal_zone = strtod(optarg, NULL);
break;
default:
break;
}
}
if (pthread_mutex_init(&input_lock, NULL) != 0) {
fprintf(stderr, "\n mutex init failed, exit\n");
return 1;
}
start_syslog();
if (signal(SIGINT, tmon_sig_handler) == SIG_ERR)
syslog(LOG_DEBUG, "Cannot handle SIGINT\n");
if (signal(SIGTERM, tmon_sig_handler) == SIG_ERR)
syslog(LOG_DEBUG, "Cannot handle SIGTERM\n");
if (probe_thermal_sysfs()) {
pthread_mutex_destroy(&input_lock);
closelog();
return -1;
}
initialize_curses();
setup_windows();
signal(SIGWINCH, resize_handler);
show_title_bar();
show_sensors_w();
show_cooling_device();
update_thermal_data();
show_data_w();
prepare_logging();
init_thermal_controller();
nodelay(stdscr, TRUE);
err = pthread_create(&event_tid, NULL, &handle_tui_events, NULL);
if (err != 0) {
printf("\ncan't create thread :[%s]", strerror(err));
tmon_cleanup();
exit(EXIT_FAILURE);
}
/* validate range of user selected target zone, default to the first
* instance if out of range
*/
target_tz_index = zone_instance_to_index(target_thermal_zone);
if (target_tz_index < 0) {
target_thermal_zone = ptdata.tzi[0].instance;
syslog(LOG_ERR, "target zone is not found, default to %d\n",
target_thermal_zone);
}
while (1) {
sleep(ticktime);
show_title_bar();
show_sensors_w();
update_thermal_data();
Annotation
- Immediate include surface: `getopt.h`, `unistd.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/types.h`, `sys/stat.h`, `ncurses.h`.
- Detected declarations: `function usage`, `function version`, `function tmon_cleanup`, `function tmon_sig_handler`, `function start_syslog`, `function prepare_logging`, `function main`, `function start_daemon_mode`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.