diff -Nru /tmp/HEOmP5gLeY/longrun-0.9/debian/changelog /tmp/fBLQDxJNp2/longrun-0.9/debian/changelog --- /tmp/HEOmP5gLeY/longrun-0.9/debian/changelog 2005-10-02 16:52:34.718131240 +0800 +++ /tmp/fBLQDxJNp2/longrun-0.9/debian/changelog 2005-10-02 16:52:35.905950664 +0800 @@ -1,3 +1,11 @@ +longrun (0.9-17) unstable; urgency=low + + * Added configuration file reading support (-C) to enable minimal + external configuration. + * Added man page entry for -C flag. + + -- Dean Michael C. Berris (Mikhail Beris) Sat, 1 Oct 2005 18:55:35 +0800 + longrun (0.9-16) unstable; urgency=low * Patch from dean gaudet with following changes for improved efficion diff -Nru /tmp/HEOmP5gLeY/longrun-0.9/longrun.1 /tmp/fBLQDxJNp2/longrun-0.9/longrun.1 --- /tmp/HEOmP5gLeY/longrun-0.9/longrun.1 2005-10-02 16:52:34.553156320 +0800 +++ /tmp/fBLQDxJNp2/longrun-0.9/longrun.1 2005-10-02 16:52:35.839960696 +0800 @@ -41,12 +41,17 @@ .SH NAME Transmeta(TM) Crusoe(TM) LongRun(TM) utility .SH SYNOPSIS -.B longrun [-c device] [-m device] [-hlpv] [-f flag] [-s low high] [-t num] +.B longrun [-C filename] [-c device] [-m device] [-hlpv] [-f flag] [-s low high] [-t num] .SH DESCRIPTION The .I longrun -utility is used to control and query LongRun settings on Transmeta -Crusoe processors. +utility is used to control and query LongRun settings on Transmeta(tm) +Crusoe(tm) processors. +.TP +-C filename +Set the configuration file to read and load. If not used, the default +filename is +.BR /etc/longrun.conf . .TP -c device Set the CPUID device. The default CPUID device is diff -Nru /tmp/HEOmP5gLeY/longrun-0.9/longrun.c /tmp/fBLQDxJNp2/longrun-0.9/longrun.c --- /tmp/HEOmP5gLeY/longrun-0.9/longrun.c 2005-10-02 16:52:34.612147352 +0800 +++ /tmp/fBLQDxJNp2/longrun-0.9/longrun.c 2005-10-02 16:52:35.852958720 +0800 @@ -33,7 +33,11 @@ #include #include #include + +#ifndef __USE_UNIX98 #define __USE_UNIX98 /* for pread/pwrite */ +#endif + #define __USE_FILE_OFFSET64 /* we should use 64 bit offset for pread/pwrite */ #include @@ -88,12 +92,19 @@ int opt_verbose = 0; /* verbosity */ +/* Configuration File Support */ +#define MAXLINE 255 +#define CONFIG_FILENAME "/etc/longrun.conf" +char * conf_cpuid = NULL; +char * conf_msr = NULL; + void usage(int status) { FILE *stream = status ? stderr : stdout; fprintf(stream, _("%s %s (%s)\n" - "usage: %s [-c device] [-m device] [-hlpv] [-f flag] [-s low high] [-t tlx]\n" + "usage: %s [-C filename] [-c device] [-m device] [-hlpv] [-f flag] [-s low high] [-t tlx]\n" + " -C filename set the config file to read\n" " -c device set CPUID device\n" " -m device set MSR device\n" " -h print this help\n" @@ -514,6 +525,63 @@ printf(_("LongRun flags: %s\n"), (lower & 1) ? _("performance") : _("economy")); } +void parse_line(char * line, size_t len) { + char * key = NULL; + char * value = NULL; + if (len && line) { + /* ignore lines that start with # */ + if (line[0] == '#') + return; + + /* special config file option "verbose" */ + if (!strncmp("verbose", line, 6)) { + opt_verbose++; + printf(_("Verbose mode set in configuration file.\n")); + return; + } + + if ((key = strtok(line, "=")) == NULL) { + if (opt_verbose) + printf(_("encountered invalid line '%s'\n"), line); + + return; + } + + value = strtok(NULL, "\n"); + + if (!strncmp("cpuid", key, 5)) { + conf_cpuid = malloc(sizeof(char) * (strlen(value) + 1)); + strcpy(conf_cpuid, value); + cpuid_device = conf_cpuid; + if (opt_verbose) + printf(_("cpuid device set to: %s\n"), conf_cpuid); + return; + } + + if (!strncmp("msr", key, 3)) { + conf_msr = malloc(sizeof(char) * (strlen(value) + 1)); + strcpy(conf_msr, value); + msr_device = conf_msr; + if (opt_verbose) + printf(_("msr device set to: %s\n"), conf_msr); + return; + } + + } +} + +void conf_cleanup() { + if (!conf_cpuid) { + free(conf_cpuid); + conf_cpuid = NULL; + } + + if (!conf_msr) { + free(conf_msr); + conf_cpuid = NULL; + } +} + int main(int argc, char *argv[]) { int low, high; @@ -524,6 +592,10 @@ int opt_print = 0; int opt_set = 0; int opt_atm = 0; + /* for configuration file reading */ + int opt_conf= 0; + char * c_filename = NULL; + FILE * c_file = NULL; if (argc) progname = my_basename(argv[0]); @@ -538,8 +610,12 @@ cpuid_device = CPUID_DEVICE; /* command line options */ - while ((g = getopt(argc, argv, "c:f:m:hlpstv")) != EOF) { + while ((g = getopt(argc, argv, "C:c:f:m:hlpstv")) != EOF) { switch (g) { + case 'C': + c_filename = optarg; + opt_conf++; + break; case 'c': cpuid_device = optarg; break; @@ -585,6 +661,26 @@ fprintf(stderr, _("%s: must be run as root\n"), progname); exit(1); } + + /* load the config file settings by default */ + if (!c_filename) + c_filename = CONFIG_FILENAME; + + if ((c_file = fopen(c_filename, "r")) == NULL) { + fprintf(stderr, _("%s: configuration file named '%s' not found.\n"), progname, c_filename); + exit(1); + } else { + char * read = NULL; + char * line = (char *) malloc((sizeof(char) * MAXLINE) + 1); + + while ((read = fgets(line, MAXLINE, c_file)) != NULL) { + parse_line(line, strlen(line)); + } + + free(line); + + fclose(c_file); + } if ((cpuid_fd = open(cpuid_device, O_RDWR)) < 0) { error_warn(_("error opening %s"), cpuid_device); @@ -606,6 +702,7 @@ if (opt_list) { list_longrun(); + conf_cleanup(); exit(0); } if (opt_set) { @@ -623,6 +720,7 @@ if (opt_print || opt_verbose) { print_longrun(); } - + + conf_cleanup(); exit(0); }