Package: longrun Version: 0.9-16 Severity: wishlist Tags: patch *** Please type your report below this line *** Added support for external configuration file defined through -C. Currently, the supported options in the configuration file are "cpuid=", "msr=", and "verbose". The default configuration file is set at /etc/longrun.conf when -C is invoked without an argument.
This allows the defaults for longrun to be defined in the configuration file instead of in the source code in compile time. This added feature can easily be extended as necessary in the future. -- System Information: Debian Release: 3.1 Architecture: i386 (i686) Kernel: Linux 2.6.10-5-386 Locale: LANG=en_PH.UTF-8, LC_CTYPE=en_PH.UTF-8 (charmap=UTF-8) Versions of packages longrun depends on: ii libc6 2.3.2.ds1-20ubuntu14 GNU C Library: Shared libraries an -- no debconf information
diff -Nru /tmp/2Ets9aEuA4/longrun-0.9/debian/changelog /tmp/q9JQF1Hbsz/longrun-0.9/debian/changelog
--- /tmp/2Ets9aEuA4/longrun-0.9/debian/changelog 2005-10-01 19:35:28.002861944 +0800
+++ /tmp/q9JQF1Hbsz/longrun-0.9/debian/changelog 2005-10-01 19:35:28.935720128 +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) <[EMAIL PROTECTED]> 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/2Ets9aEuA4/longrun-0.9/longrun.1 /tmp/q9JQF1Hbsz/longrun-0.9/longrun.1
--- /tmp/2Ets9aEuA4/longrun-0.9/longrun.1 2005-10-01 19:35:27.867882464 +0800
+++ /tmp/q9JQF1Hbsz/longrun-0.9/longrun.1 2005-10-01 19:35:28.909724080 +0800
@@ -41,12 +41,16 @@
.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. The default filename is
+.BR /etc/longrun.conf .
.TP
-c device
Set the CPUID device. The default CPUID device is
@@ -139,10 +143,14 @@
.SH ENVIRONMENT
No environment variables are used.
.SH FILES
+.P
This program requires that the Linux CPUID and MSR devices be compiled
into the kernel (or loaded as kernel modules), that the CPUID character
device be readable, and that the MSR character device be both readable
and writable.
+.P
+In case the -C flag is invoked without an argument, the default configuration
+file is /etc/longrun.conf.
.SH "SEE ALSO"
.BR acpid (8),
.BR apmd (8),
diff -Nru /tmp/2Ets9aEuA4/longrun-0.9/longrun.c /tmp/q9JQF1Hbsz/longrun-0.9/longrun.c
--- /tmp/2Ets9aEuA4/longrun-0.9/longrun.c 2005-10-01 19:35:27.910875928 +0800
+++ /tmp/q9JQF1Hbsz/longrun-0.9/longrun.c 2005-10-01 19:35:28.918722712 +0800
@@ -19,7 +19,8 @@
*/
#define VERSION "0.9"
-#define REVDATE "2001-02-14"
+#define REVDATE "2005-10-1"
+#define _GNU_SOURCE
#include <ctype.h>
#include <errno.h>
@@ -33,7 +34,11 @@
#include <sys/io.h>
#include <sys/sysmacros.h>
#include <locale.h>
+
+#ifndef __USE_UNIX98
#define __USE_UNIX98 /* for pread/pwrite */
+#endif
+
#define __USE_FILE_OFFSET64 /* we should use 64 bit offset for pread/pwrite */
#include <unistd.h>
@@ -88,12 +93,16 @@
int opt_verbose = 0; /* verbosity */
+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 +523,62 @@
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;
+
+ 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;
+ }
+
+ if (!strncmp("verbose", key, 3)) {
+ opt_verbose++;
+ printf(_("Verbose mode set in configuration file.\n"));
+ 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 +589,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 +607,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 +658,32 @@
fprintf(stderr, _("%s: must be run as root\n"), progname);
exit(1);
}
+
+ /* load the config file settings */
+ if (opt_conf && !c_filename)
+ c_filename = "/etc/longrun.conf";
+
+ if ((c_filename != NULL) && ((c_file = fopen(c_filename, "r")) == NULL)) {
+ fprintf(stderr, _("%s: configuration file named '%s' not found.\n"), progname, c_filename);
+ exit(1);
+ } else {
+ /* use GNU getline to read the lines and extract pertinent information
+ from the configuration file. */
+ char * line = NULL;
+ size_t len = 0;
+ ssize_t read = 0;
+ while ((read = getline(&line, &len, c_file)) != -1) {
+ if (opt_verbose)
+ printf( _("Read: %s"), line);
+
+ parse_line(line, len);
+
+ if (!line)
+ free(line);
+ }
+
+ fclose(c_file);
+ }
if ((cpuid_fd = open(cpuid_device, O_RDWR)) < 0) {
error_warn(_("error opening %s"), cpuid_device);
@@ -606,6 +705,7 @@
if (opt_list) {
list_longrun();
+ conf_cleanup();
exit(0);
}
if (opt_set) {
@@ -623,6 +723,7 @@
if (opt_print || opt_verbose) {
print_longrun();
}
-
+
+ conf_cleanup();
exit(0);
}
signature.asc
Description: This is a digitally signed message part

