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;
}
tz = config_lookup(&cfg, "thermal-zones"); if (!tz) {
ERROR("No thermal zone configured to be monitored\n"); return -1;
}
INFO("Thermal zone regular expression '%s' with polling %d\n",
name, polling);
}
return 0;
}
staticvoid usage(constchar *cmd)
{
printf("%s Version: %s\n", cmd, VERSION);
printf("Usage: %s [options]\n", cmd);
printf("\t-h, --help\t\tthis help\n");
printf("\t-o, --output \toutput directory for temperature capture\n");
printf("\t-c, --config \tconfiguration file\n");
printf("\t-d, --duration \tcapture duration\n");
printf("\t-l, --loglevel \tlog level: ");
printf("DEBUG, INFO, NOTICE, WARN, ERROR\n");
printf("\t-p, --postfix \tpostfix to be happened at the end of the files\n");
printf("\t-s, --syslog\t\toutput to syslog\n");
printf("\t-w, --overwrite\t\toverwrite the temperature capture files if they exist\n");
printf("\n"); exit(0);
}
staticint options_init(int argc, char *argv[], struct options *options)
{ int opt;
time_t now = time(NULL);
if (kill(pid, SIGTERM))
ERROR("Failed to send SIGTERM signal to '%d': %p\n", pid); elseif (waitpid(pid, NULL, 0))
ERROR("Failed to wait pid '%d': %p\n", pid);
/* * If there is a duration specified, we will exit the mainloop * and gracefully close all the files which will flush the * file system cache
*/ if (options->duration) { struct itimerspec timer_it = { 0 };
fd = timerfd_create(CLOCK_MONOTONIC, 0); if (fd < 0) {
ERROR("Failed to create duration timer: %m\n"); return -1;
}
if (timerfd_settime(fd, 0, &timer_it, NULL)) {
ERROR("Failed to set timer time: %m\n"); return -1;
}
if (mainloop_add(fd, pid < 0 ? exit_mainloop : kill_process, &pid)) {
ERROR("Failed to set timer exit mainloop callback\n"); return -1;
}
}
/* * We want to catch any keyboard interrupt, as well as child * signals if any in order to exit properly
*/
sigemptyset(&mask);
sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGQUIT);
sigaddset(&mask, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &mask, NULL)) {
ERROR("Failed to set sigprocmask: %m\n"); return -1;
}
fd = signalfd(-1, &mask, 0); if (fd < 0) {
ERROR("Failed to set the signalfd: %m\n"); return -1;
}
if (mainloop_add(fd, exit_mainloop, NULL)) {
ERROR("Failed to set timer exit mainloop callback\n"); return -1;
}
return mainloop(-1);
}
staticint thermometer_stop(struct thermometer *thermometer)
{ int i;
INFO("Closing/flushing output files\n");
for (i = 0; i < thermometer->nr_tz; i++)
fclose(thermometer->tz[i].file_out);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.