aboutsummaryrefslogtreecommitdiffstats
path: root/argparse.c
diff options
context:
space:
mode:
authorPA4WDH2023-05-24 08:33:53 +0200
committerPA4WDH2023-05-24 08:33:53 +0200
commitfa20f603834ef9febe396c058c9d775038f4a28b (patch)
treedbe5ad3e978f562c4709b66653a5efd9bbdcc2f3 /argparse.c
parentAdd keep feature for governor (diff)
downloadcputemp2maxfreq-fa20f603834ef9febe396c058c9d775038f4a28b.tar.gz
cputemp2maxfreq-fa20f603834ef9febe396c058c9d775038f4a28b.tar.bz2
cputemp2maxfreq-fa20f603834ef9febe396c058c9d775038f4a28b.zip
Add logging functions
Diffstat (limited to 'argparse.c')
-rw-r--r--argparse.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/argparse.c b/argparse.c
index 01b6c57..7246d31 100644
--- a/argparse.c
+++ b/argparse.c
@@ -4,6 +4,7 @@
#include <string.h>
#include "cputemp2maxfreq.h"
#include "debug.h"
+#include "logger.h"
extern struct s_config config;
@@ -20,14 +21,16 @@ void printhelp()
"-h Display this help text\n"
"-i <file> Input for temperature readout, usually somewhere in sysfs\n"
" Default: %s\n"
+ "-l <logger> Logger to use, valid values: none, kmsg, stdout, syslog\n"
+ " Default: %s\n"
"-p <time> Poll interval in seconds\n"
" Default: %d\n"
"-s <step> Step size in Khz when increasing/decreasing CPU speed\n"
" Default: %ld\n"
"-t <number> Temperature limit\n"
" Default: %ld\n",
- config.fallback_freq,config.governor,config.temp_input,config.interval,
- config.freq_step,config.max_temp/1000
+ config.fallback_freq,config.governor,config.temp_input,config.logger_name,
+ config.interval,config.freq_step,config.max_temp/1000
);
}
@@ -42,7 +45,7 @@ void argparse(int argc, char **argv)
memcpy(&userconfig,&config,sizeof(struct s_config));
// Parse options
- while((opt=getopt(argc,argv,"f:g:hi:p:s:t:"))!=-1)
+ while((opt=getopt(argc,argv,"f:g:hi:l:p:s:t:"))!=-1)
{
DEBUG1_ARGPARSE("Argument: %c Value: %s\n",opt,optarg);
switch(opt)
@@ -59,6 +62,9 @@ void argparse(int argc, char **argv)
case 'i':
strncpy(userconfig.temp_input,optarg,sizeof(userconfig.temp_input));
break;
+ case 'l':
+ strncpy(userconfig.logger_name,optarg,sizeof(userconfig.logger_name));
+ break;
case 'p':
userconfig.interval=strtoll(optarg,NULL,10);
break;
@@ -74,6 +80,16 @@ void argparse(int argc, char **argv)
}
}
+// Change the logger function pointer
+ if (strcmp(userconfig.logger_name,"none")==0) userconfig.logger=&logger_none;
+ else if (strcmp(userconfig.logger_name,"stdout")==0) userconfig.logger=&logger_stdout;
+ else if (strcmp(userconfig.logger_name,"syslog")==0) userconfig.logger=&logger_syslog;
+ else if (strcmp(userconfig.logger_name,"kmsg")==0) userconfig.logger=&logger_kmsg;
+ else {
+ printf("Invalid value for logger, exiting.\n");
+ exit(1);
+ }
+
// Copy modified config to global config
memcpy(&config,&userconfig,sizeof(struct s_config));
}