tools/thermal/thermometer/thermometer.c
Source file repositories/reference/linux-study-clean/tools/thermal/thermometer/thermometer.c
File Facts
- System
- Linux kernel
- Corpus path
tools/thermal/thermometer/thermometer.c- Extension
.c- Size
- 12647 bytes
- Lines
- 574
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
dirent.hfcntl.hgetopt.hregex.hsignal.hstdio.hstdlib.hstring.hsys/stat.hsys/signalfd.hsys/timerfd.hsys/types.hsys/wait.htime.hunistd.hlinux/thermal.hlibconfig.hthermal-tools.h
Detected Declarations
struct optionsstruct tz_regexstruct configurationstruct tzstruct thermometerfunction configuration_default_initfunction configuration_initfunction usagefunction options_initfunction thermometer_add_tzfunction thermometer_initfunction timer_temperature_callbackfunction thermometer_startfunction thermometer_executefunction kill_processfunction exit_mainloopfunction thermometer_waitfunction thermometer_stopfunction main
Annotated Snippet
struct options {
int loglvl;
int logopt;
int overwrite;
int duration;
const char *config;
char postfix[PATH_MAX];
char output[PATH_MAX];
};
struct tz_regex {
regex_t regex;
int polling;
};
struct configuration {
struct tz_regex *tz_regex;
int nr_tz_regex;
};
struct tz {
FILE *file_out;
int fd_temp;
int fd_timer;
int polling;
const char *name;
};
struct thermometer {
struct tz *tz;
int nr_tz;
};
static struct tz_regex *configuration_tz_match(const char *expr,
struct configuration *config)
{
int i;
for (i = 0; i < config->nr_tz_regex; i++) {
if (!regexec(&config->tz_regex[i].regex, expr, 0, NULL, 0))
return &config->tz_regex[i];
}
return NULL;
}
static int configuration_default_init(struct configuration *config)
{
config->tz_regex = realloc(config->tz_regex, sizeof(*config->tz_regex) *
(config->nr_tz_regex + 1));
if (regcomp(&config->tz_regex[config->nr_tz_regex].regex, ".*",
REG_NOSUB | REG_EXTENDED)) {
ERROR("Invalid regular expression\n");
return -1;
}
config->tz_regex[config->nr_tz_regex].polling = 250;
config->nr_tz_regex = 1;
return 0;
}
static int configuration_init(const char *path, struct configuration *config)
{
config_t cfg;
config_setting_t *tz;
int i, length;
if (path && access(path, F_OK)) {
ERROR("'%s' is not accessible\n", path);
return -1;
}
if (!path && !config->nr_tz_regex) {
INFO("No thermal zones configured, using wildcard for all of them\n");
return configuration_default_init(config);
}
config_init(&cfg);
if (!config_read_file(&cfg, path)) {
ERROR("Failed to parse %s:%d - %s\n", config_error_file(&cfg),
config_error_line(&cfg), config_error_text(&cfg));
return -1;
}
Annotation
- Immediate include surface: `dirent.h`, `fcntl.h`, `getopt.h`, `regex.h`, `signal.h`, `stdio.h`, `stdlib.h`, `string.h`.
- Detected declarations: `struct options`, `struct tz_regex`, `struct configuration`, `struct tz`, `struct thermometer`, `function configuration_default_init`, `function configuration_init`, `function usage`, `function options_init`, `function thermometer_add_tz`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.