aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorltoetsch <ltoetsch@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2001-03-08 15:25:38 +0000
committerltoetsch <ltoetsch@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2001-03-08 15:25:38 +0000
commit824e3605cf8644295dc837a17f329c2e2bd619a3 (patch)
tree02aff59dab901063436b9f22074566765564ec84
parentaf1aa94e53eea7a721806610ffdad0affe8d2d0f (diff)
downloadlcd4linux-824e3605cf8644295dc837a17f329c2e2bd619a3.tar.gz
[lcd4linux @ 2001-03-08 15:25:38 by ltoetsch]
improved exec git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@103 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r--README105
-rw-r--r--TODO20
-rw-r--r--cfg.c9
-rw-r--r--exec.c89
-rw-r--r--exec.h17
-rw-r--r--lcd4linux.c9
-rw-r--r--lcd4linux.conf.sample12
-rw-r--r--parser.c7
-rw-r--r--processor.c39
9 files changed, 214 insertions, 93 deletions
diff --git a/README b/README
index 82dce69..4d014ce 100644
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
#
-# $Id: README,v 1.13 2001/03/07 18:10:21 ltoetsch Exp $
+# $Id: README,v 1.14 2001/03/08 15:25:38 ltoetsch Exp $
#
This is the README file for lcd4linux
@@ -17,22 +17,23 @@ vertical bars, logarithmic bars, split bars (two independent bars in one row).
USAGE
lcd4linux -h
-print version number and a small help text, then exit
+ print version number and a small help text, then exit
lcd4linux -l
-list available drivers
+ list available drivers
lcd4linux -d
-calibrate delay loop (necessary for some drivers)
+ calibrate delay loop (necessary for some drivers)
lcd4linux [-c key=val] [-F] [-f config-file] [-o output] [-q] [-v]
-run lcd4linux
-overwrite entries from the config-file with '-c'
-do not fork and detach with '-F'
-use configuration from 'config-file' instead of /etc/lcd4linux.conf
-write picture to 'output' (raster driver only)
-suppress startup splash screen with '-q'
-generate debugging messages with '-v'
+ run lcd4linux
+ overwrite entries from the config-file with '-c'
+ do not fork and detach with '-F'
+ use configuration from 'config-file' instead of /etc/lcd4linux.conf
+ write picture to 'output' (raster driver only)
+ suppress startup splash screen with '-q'
+ generate info messages with '-v'
+ generate debugging messages with '-vv'
SUPPORTED DISPLAYS
@@ -65,10 +66,11 @@ SUPPORTED DISPLAYS
* X11
- thanks to Herbert Rosmanith <herp@wildsau.idv.uni-linz.ac.at> a driver for the
- X Window System is available. It supports any size at any resolution. A very
- small XLCD4Linux-Window can even swallow on the KDE Panel!
-
+ thanks to Herbert Rosmanith <herp@wildsau.idv.uni-linz.ac.at> a driver
+ for the X Window System is available. It supports any size at any
+ resolution. A very small XLCD4Linux-Window can even swallow on the KDE
+ Panel!
+
* Raster formats:
a generic raster driver (which is used by the X11-driver, too) is availiable,
@@ -77,53 +79,68 @@ SUPPORTED DISPLAYS
PNG (with libgd)
-* other displays: lcd4linux and especially the display driver code is very modular,
- so it should be quite easy to write a driver for any display. See README.driver
- for details. Contributors are welcome!!!
+* other displays: lcd4linux and especially the display driver code is very
+ modular, so it should be quite easy to write a driver for any display. See
+ README.driver for details. Contributors are welcome!!!
CONFIGURATION
-The configuration file (default: /etc/lcd4linux.conf) has a very simple format:
-Every line consists of a key and a value, seperated by whitespace (blanks or tabs).
-Values can contain whitespace, and can be enclosed in single or double quotes.
-A key must not contain whitespace. Keys are NOT case-sensitive. Order doesn't matter.
-Empty lines and all text on a line after a '#' will be ignored. If you want to
-use '#' in a value (think of X11-colors), you have to quote it with a backslash.
+The configuration file (default: /etc/lcd4linux.conf) has a very simple
+format: Every line consists of a key and a value, seperated by whitespace
+(blanks or tabs). Values can contain whitespace, and can be enclosed in
+single or double quotes. A key must not contain whitespace. Keys are NOT
+case-sensitive. Order doesn't matter. Empty lines and all text on a line
+after a '#' will be ignored. If you want to use '#' in a value (think of
+X11-colors), you have to quote it with a backslash.
NOTE:
Because of security reasons the config file is assured to be:
* - file is a normal file (or /dev/null)
* - file owner is owner of program
- * - file is not writeable by group
- * - file is not writeable by other
+ * - file is not accessible by group
+ * - file is not accessible by other
So if you run lcd4linux as root, /etc/lcd4linux has to be:
chmod 600
chown root.root
-The configuration file contains information for different modules of lcd4linux:
+The configuration file contains information for different modules of
+lcd4linux:
Global options:
tick: time in milliseconds between bar updates
- tack: time in milliseconds between text updates (text can be updated less often than
- bars, so you get a smooth bar display and readable text)
+ tack: time in milliseconds between text updates (text can be updated less
+ often than bars, so you get a smooth bar display and readable text)
tau: time constant (in milliseconds) for damping function (not used by now)
Data-specific options:
- overload: load average threshold and bar scaling. The '%L' token (see below) displays
- a '!' instead of a blank if the current load average exceeds this value.
+ overload: load average threshold and bar scaling. The '%L' token (see below)
+ displays a '!' instead of a blank if the current load average
+ exceeds this value.
load bars are scaled by this value (load=overload gives 100%)
fifo: path to fifo for communication with isdnlog (not yet implemented)
- sensor1: path to the 1st temperature file (e.g. /proc/sys/dev/sensors/w83781d-isa-0290/temp1)
- it is important that you use the isa sensors, because the i2c sensors are very slow!
+ sensor1: path to the 1st temperature file
+ (e.g. /proc/sys/dev/sensors/w83781d-isa-0290/temp1)
+ it is important that you use the isa sensors, because the i2c
+ sensors are very slow!
sensor1_min: temperature where the corresponding bar starts
sensor1_max: temperature where bar ends
sensor[2..9], -_min, -_max: entries for the 2nd to 9th temperature sensor
+
+ exec:
+ x1 ... x9: command to execute, PATH=/usr/local/bin:/usr/bin:/bin
+ $X1 ... $X8 is result of command 1..8 in environment
+ Tick_x1 .. 9 delay in ticks (overrides delay_x)
+ Delay_x1 ..9 delay in seconds (default 1)
+ Scale_x1 ..9 scale for bars (default 100)
+
+ battery: Battwarning 10 (default 10)
+
Driver-specific options:
@@ -131,26 +148,28 @@ Driver-specific options:
every driver has its own configuration options (e.g. 'Port', 'Speed', ...)
see README.<Drivername> for details!
+
Display options:
row1: Text to display in row 1
row[2-max]: Text to display in other rows
- The text to be displayed can contain specific directives, which will be replaced
- by the appropriate values, or will create bars:
+ The text to be displayed can contain specific directives, which will be
+ replaced by the appropriate values, or will create bars:
'\nnn` will write the ASCII-character nnn (octal)
'%<token>' will be replaced by the value of <token>
'%%' will write a '%'
'%$' will write a '$'
- '$<direction><length><token>[+<token>] will create a bar with the specified direction
- and length (in characters) with the value of <token>. If the driver supports dual bars,
- you can specify the second value with '+<token>'.
- <direction> can be 'l' (left), 'r' (right), 'u' (up) or 'd' (down).
- If you specify the direction in upper case, a logarithmic bar will be created.
- note that the space occupied by a bar always grows from left to right or from top to
- bottom, regardless of the direction!
-
+
+ '$<direction><length><token>[+<token>] will create a bar with the
+ specified direction and length (in characters) with the value of <token>.
+ If the driver supports dual bars, you can specify the second value with
+ '+<token>'. <direction> can be 'l' (left), 'r' (right), 'u' (up) or 'd'
+ (down). If you specify the direction in upper case, a logarithmic bar will
+ be created. note that the space occupied by a bar always grows from left
+ to right or from top to bottom, regardless of the direction!
+
Tokens:
'o', operating system name ('Linux')
diff --git a/TODO b/TODO
index bb6c9a0..9b7d638 100644
--- a/TODO
+++ b/TODO
@@ -6,7 +6,7 @@ can be filled (made up of bars) or not (needs raster graphics)
// 2000-04-04 Michael Reinelt <reinelt@eunet.at>
// write a driver for PNG. This should be the first step towards a WWW-driver.
-Done 2001-03-01 -lt.
+// Done 2001-03-01 -lt.
2000-04-15 Thomas Skyt Jessen <thskyt@foni.net>
show partition information (used, free, ...)
@@ -18,14 +18,16 @@ show process information
show other sensors than temperature
we have to use libsensors instead of parsing the proc files directly
-2000-12-03 Ghassan Matar <gmatar@hexapods.com>
-show contents of any text file
-the file should only contain one line, with a fixed format
-there are two possibilities: text and numbers
-numbers can be used for bars, too
+// 2000-12-03 Ghassan Matar <gmatar@hexapods.com>
+// show contents of any text file
+// the file should only contain one line, with a fixed format
+// there are two possibilities: text and numbers
+// numbers can be used for bars, too
+// Done 2000-03-08, look at %x -lt
-2000-12-03 Ghassan Matar <gmatar@hexapods.com>
-accept data from external sources (fifo?)
+// 2000-12-03 Ghassan Matar <gmatar@hexapods.com>
+// accept data from external sources (fifo?)
+// Done 2000-03-08, look at %x -lt
2001-02-11 Carsten Nau <info@cnau.de>
connect a LED to a spare pin of the parallel port and show if ISDN
@@ -34,7 +36,7 @@ is online
// 2001-01-27 Axel Ehnert <axel@ehnert.net>
// - display numer of emails in a mailbox
// - display seti@home values
-done.
+// done.
2001-03-05 Leo Tötsch <lt@toetsch.at>
rename some tokens: %o->%os, %v->%ov, %r->%or, %p->%op,
diff --git a/cfg.c b/cfg.c
index 89061a2..634448f 100644
--- a/cfg.c
+++ b/cfg.c
@@ -1,4 +1,4 @@
-/* $Id: cfg.c,v 1.10 2001/03/07 18:10:21 ltoetsch Exp $
+/* $Id: cfg.c,v 1.11 2001/03/08 15:25:38 ltoetsch Exp $
*
* config file stuff
*
@@ -20,6 +20,9 @@
*
*
* $Log: cfg.c,v $
+ * Revision 1.11 2001/03/08 15:25:38 ltoetsch
+ * improved exec
+ *
* Revision 1.10 2001/03/07 18:10:21 ltoetsch
* added e(x)ec commands
*
@@ -221,8 +224,8 @@ static int check_cfg_file(char *file)
* we will check that:
* - file is a normal file (or /dev/null)
* - file owner is owner of program
- * - file is not writeable by group
- * - file is not writeable by other
+ * - file is not accessible by group
+ * - file is not accessible by other
*/
uid_t uid, gid;
diff --git a/exec.c b/exec.c
index 2617206..3c7c8de 100644
--- a/exec.c
+++ b/exec.c
@@ -1,4 +1,4 @@
-/* $Id: exec.c,v 1.2 2001/03/08 08:39:54 reinelt Exp $
+/* $Id: exec.c,v 1.3 2001/03/08 15:25:38 ltoetsch Exp $
*
* exec ('x*') functions
*
@@ -20,6 +20,9 @@
*
*
* $Log: exec.c,v $
+ * Revision 1.3 2001/03/08 15:25:38 ltoetsch
+ * improved exec
+ *
* Revision 1.2 2001/03/08 08:39:54 reinelt
*
* fixed two typos
@@ -28,43 +31,99 @@
* added e(x)ec commands
*
*
+ * This implements the x1 .. x9 commands
+ * config options:
+ * x1 .. x9 command to execute
+ * Tick_x1 ... 9 delay in ticks
+ * Delay_x1 .. 9 delay in seconds
+ * Scale_x1 .. 9 scale for bars
*/
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <time.h>
+#include <ctype.h>
+#include <errno.h>
+#define IN_EXEC
#include "exec.h"
#include "debug.h"
#include "cfg.h"
-int Exec(int index, char buff[EXEC_TXT_LEN])
+int Exec(int index, char buff[EXEC_TXT_LEN], double *val)
{
- static time_t now = 0;
- char *command;
- char xn[4];
+ static time_t now[EXECS+1];
+ static int errs[EXECS+1];
+ static int ticks[EXECS+1];
+ char *command, *p;
+ char xn[20];
+ char env[EXEC_TXT_LEN];
FILE *pipe;
+ size_t len;
+ int i;
+
+ if (index < 1 || index > EXECS)
+ return -1;
+ if (errs[index])
+ return -1;
- if (time(NULL) <= now+EXEC_WAIT)
- return 0;
- time(&now);
+ /* first time ? */
+ if (now[index] != 0) {
+ /* delay in Ticks ? */
+ sprintf(xn, "Tick_x%d", index);
+ p = cfg_get(xn);
+ if (p && *p) {
+ if (ticks[index]++ % atoi(p) != 0)
+ return 0;
+ }
+ else {
+ sprintf(xn, "Delay_x%d", index);
+ /* delay in Delay_x* sec ? */
+ if (time(NULL) <= now[index] + atoi(cfg_get(xn)?:"1"))
+ return 0;
+ }
+ }
+ time(&now[index]);
+ *val = -1;
sprintf(xn, "x%d", index);
command = cfg_get(xn);
- debug("command%d = %s:%s",index,xn,command);
+ debug("%s:'%s'",xn,command);
- if (!*command) {
+ if (!command || !*command) {
error("Empty command for 'x%d'", index);
+ errs[index]++;
return -1;
}
-
+ for (i = 1; i < index; i++) {
+ sprintf(env, "X%d=%.*s", i, EXEC_TXT_LEN-10, exec[i].s);
+ putenv(env);
+ }
+ putenv("PATH=/usr/local/bin:/usr/bin:/bin");
pipe = popen(command, "r");
if (pipe == NULL) {
- error("Couln't run pipe '%s'", command);
+ error("Couldn't run pipe '%s':\n%s", command, strerror(errno));
+ errs[index]++;
+ return -1;
+ }
+ len = fread(buff, 1, EXEC_TXT_LEN-1, pipe);
+ if (len <= 0) {
+ pclose(pipe);
+ error("Couldn't fread from pipe '%s', len=%d", command, len);
+ errs[index]++;
+ *buff = '\0';
return -1;
}
- fread(buff, EXEC_TXT_LEN, 1, pipe);
- fclose(pipe);
- buff[EXEC_TXT_LEN-1] = '\0';
+ pclose(pipe);
+ buff[len] = '\0';
+ for (p = buff ; *p && isspace(*p); p++)
+ ;
+ if (isdigit(*p)) {
+ *val = atof(p);
+ sprintf(xn, "Scale_x%d", index);
+ *val /= atoi(cfg_get(xn)?:"100")?:100;
+ }
return 0;
}
diff --git a/exec.h b/exec.h
index 0bec266..b8936a0 100644
--- a/exec.h
+++ b/exec.h
@@ -1,4 +1,4 @@
-/* $Id: exec.h,v 1.1 2001/03/07 18:10:21 ltoetsch Exp $
+/* $Id: exec.h,v 1.2 2001/03/08 15:25:38 ltoetsch Exp $
*
* exec ('x*') functions
*
@@ -20,6 +20,9 @@
*
*
* $Log: exec.h,v $
+ * Revision 1.2 2001/03/08 15:25:38 ltoetsch
+ * improved exec
+ *
* Revision 1.1 2001/03/07 18:10:21 ltoetsch
* added e(x)ec commands
*
@@ -30,9 +33,17 @@
#define _EXEC_H_
#define EXECS 9
-#define EXEC_WAIT 2
#define EXEC_TXT_LEN 256
-int Exec (int index, char txt[EXEC_TXT_LEN]);
+#ifdef IN_EXEC
+ #define EXTERN extern
+#else
+ #define EXTERN
+#endif
+
+EXTERN struct { char s[EXEC_TXT_LEN]; double val; } exec[EXECS+1];
+
+int Exec (int index, char txt[EXEC_TXT_LEN], double *val);
+
#endif
diff --git a/lcd4linux.c b/lcd4linux.c
index 3bc0144..c60a04e 100644
--- a/lcd4linux.c
+++ b/lcd4linux.c
@@ -1,4 +1,4 @@
-/* $Id: lcd4linux.c,v 1.29 2001/02/14 07:40:16 reinelt Exp $
+/* $Id: lcd4linux.c,v 1.30 2001/03/08 15:25:38 ltoetsch Exp $
*
* LCD4Linux
*
@@ -20,6 +20,9 @@
*
*
* $Log: lcd4linux.c,v $
+ * Revision 1.30 2001/03/08 15:25:38 ltoetsch
+ * improved exec
+ *
* Revision 1.29 2001/02/14 07:40:16 reinelt
*
* first (incomplete) GPO implementation
@@ -182,7 +185,7 @@ char *release="LCD4Linux " VERSION " (c) 2000 Michael Reinelt <reinelt@eunet.at>
char **my_argv;
char *output=NULL;
int got_signal=0;
-int debugging=1;
+int debugging=0;
int foreground=0;
int tick, tack;
@@ -343,7 +346,7 @@ int main (int argc, char *argv[])
}
if (foreground) {
- debug ("LCD4Linux " VERSION);
+ info ("Version " VERSION " starting");
} else {
info ("Version " VERSION " starting");
if (my_argv[0]==NULL || my_argv[0][0]!='/') {
diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample
index 50de336..db91281 100644
--- a/lcd4linux.conf.sample
+++ b/lcd4linux.conf.sample
@@ -62,6 +62,18 @@ Row2 "%p CPU %r MB RAM"
Row3 "Busy %cb%% $r10cs+cb"
Row4 "Load%l1%L$r10l1"
+# e(x)ecute command in %x*
+# Row5 %x1
+# Row6 %x2
+# x1 tail -1 /var/log/messages
+# x2 echo $X1 | cut -b25-
+# Note: PATH=/usr/local/bin:/usr/bin:/bin
+# Note: $X1 .. $X8 is the text of lines x1 .. x8
+#
+# Tick_x1 10 # every 10 ticks
+# Delay_x1 2 # every 2 seconds
+# Scale_x1 50 # scale for bars (default 100), value SHOULD be numeric ;-)
+
#Row1 "Load%l1%L$r10cs+cb"
#Row2 "Disk%dm $R10dr+dw"
#Row3 "Net %nm $R10nr+nw"
diff --git a/parser.c b/parser.c
index 3c7482a..8efa761 100644
--- a/parser.c
+++ b/parser.c
@@ -1,4 +1,4 @@
-/* $Id: parser.c,v 1.12 2001/03/07 18:10:21 ltoetsch Exp $
+/* $Id: parser.c,v 1.13 2001/03/08 15:25:38 ltoetsch Exp $
*
* row definition parser
*
@@ -20,6 +20,9 @@
*
*
* $Log: parser.c,v $
+ * Revision 1.13 2001/03/08 15:25:38 ltoetsch
+ * improved exec
+ *
* Revision 1.12 2001/03/07 18:10:21 ltoetsch
* added e(x)ec commands
*
@@ -156,7 +159,7 @@ static SYMTAB Symtab[] = {{ "%", T_PERCENT, C_GENERIC, 0 },
{ "bd", T_BATT_DUR, C_BATT, 0 },
{ "e*", T_MAIL, C_MAIL, 0 },
{ "s*", T_SENSOR, C_SENSOR, 1 },
- { "x*", T_EXEC, C_EXEC, 0 },
+ { "x*", T_EXEC, C_EXEC, 1 },
{ "", -1, 0 }};
static int bar_type (char tag)
diff --git a/processor.c b/processor.c
index 0f9913c..173412f 100644
--- a/processor.c
+++ b/processor.c
@@ -1,4 +1,4 @@
-/* $Id: processor.c,v 1.17 2001/03/08 08:39:55 reinelt Exp $
+/* $Id: processor.c,v 1.18 2001/03/08 15:25:38 ltoetsch Exp $
*
* main data processing
*
@@ -20,6 +20,9 @@
*
*
* $Log: processor.c,v $
+ * Revision 1.18 2001/03/08 15:25:38 ltoetsch
+ * improved exec
+ *
* Revision 1.17 2001/03/08 08:39:55 reinelt
*
* fixed two typos
@@ -114,6 +117,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include "debug.h"
#include "cfg.h"
@@ -146,7 +150,6 @@ struct { int perc, stat; double dur; } batt;
struct { double perc, cput; } seti;
struct { int num; } mail[MAILBOXES];
struct { double val, min, max; } sensor[SENSORS];
-struct { char s[EXEC_TXT_LEN]; } exec[EXECS];
static double query (int token)
{
@@ -240,6 +243,9 @@ static double query (int token)
case T_SENSOR:
return sensor[(token>>8)-'0'].val;
+
+ case T_EXEC:
+ return exec[(token>>8)-'0'].val;
}
return 0.0;
}
@@ -250,7 +256,7 @@ static double query_bar (int token)
int i;
double value=query(token);
- switch (token) {
+ switch (token & 255) {
case T_MEM_TOTAL:
case T_MEM_USED:
@@ -312,12 +318,12 @@ static double query_bar (int token)
return value;
}
-static void print_token (int token, char **p)
+static void print_token (int token, char **p, char *start, int maxlen)
{
double val;
int i;
- switch (token) {
+ switch (token & 255) {
case T_PERCENT:
*(*p)++='%';
break;
@@ -439,20 +445,19 @@ static void print_token (int token, char **p)
}
break;
-#if 0
- never comes here -lt ?
case T_MAIL:
val=query(token);
*p+=sprintf (*p, "%3.0f", val);
break;
-#endif
+
+ case T_EXEC:
+ i = (token>>8)-'0';
+ *p+=sprintf (*p, "%.*s",cols-(*p-start), exec[i].s);
+ for (i=*p-start; i<cols && maxlen--; i++) /* clear right of text */
+ *(*p)++=' ';
+ break;
default:
- if ((token & 255) == T_EXEC) {
- i = (token>>8)-'0';
- *p+=sprintf (*p, "%s", exec[i].s);
- }
- else
*p+=sprintf (*p, "%5.0f", query(token));
}
}
@@ -525,7 +530,7 @@ static void collect_data (void)
for (i=1; i<EXECS; i++) {
if (token_usage[T_EXEC]&(1<<i)) {
- Exec (i, exec[i].s);
+ Exec (i, exec[i].s, &exec[i].val);
}
}
}
@@ -536,12 +541,16 @@ static char *process_row (int r)
char *s=row[r];
char *p=buffer;
int token;
+ int len;
+ char *q;
do {
if (*s=='%') {
token = *(unsigned char*)++s;
if (token>T_EXTENDED) token += (*(unsigned char*)++s)<<8;
- print_token (token, &p);
+ for (q = p, len=0; *q && isspace(*q); q++)
+ len++;
+ print_token (token, &p, buffer, len);
} else if (*s=='$') {
double val1, val2;