From ea361dffb297b2bc1c6a4f0ab245acad2208bccf Mon Sep 17 00:00:00 2001 From: luethje Date: Fri, 9 May 1997 23:30:37 +0000 Subject: [PATCH] isdnlog: new switch -O isdnrep: new format %S bugfix in handle_runfiles() --- isdnlog/Makefile.in | 9 ++++-- isdnlog/README | 7 +++++ isdnlog/isdnlog/functions.c | 21 +++++++++++-- isdnlog/isdnlog/isdnlog.c | 38 ++++++++++++++++++++--- isdnlog/isdnlog/isdnlog.h | 9 +++++- isdnlog/isdnrep/isdnrep.c | 10 ++++++- isdnlog/tools/tools.h | 60 ++++++++++++++++++++----------------- lib/isdntools.c | 25 ++++++++++++++-- lib/libtools.c | 26 +++++++++++++++- lib/libtools.h | 8 ++++- 10 files changed, 171 insertions(+), 42 deletions(-) diff --git a/isdnlog/Makefile.in b/isdnlog/Makefile.in index 747fb79d..6f35d579 100644 --- a/isdnlog/Makefile.in +++ b/isdnlog/Makefile.in @@ -1,4 +1,4 @@ -## $Id: Makefile.in,v 1.20 1997/05/06 22:13:21 luethje Exp $ +## $Id: Makefile.in,v 1.21 1997/05/09 23:30:37 luethje Exp $ ## ## ISDN accounting for isdn4linux. ## @@ -19,6 +19,11 @@ ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## ## $Log: Makefile.in,v $ +## Revision 1.21 1997/05/09 23:30:37 luethje +## isdnlog: new switch -O +## isdnrep: new format %S +## bugfix in handle_runfiles() +## ## Revision 1.20 1997/05/06 22:13:21 luethje ## bugfixes in HTML-Code of the isdnrep ## @@ -200,7 +205,7 @@ SERVICEFILE = /etc/services # DON'T EDIT BELOW THIS LINE ###################################################################### -VERSION = 2.99.15 +VERSION = 2.99.16 ifeq ($(POSTGRES),1) DEFS += -DPOSTGRES diff --git a/isdnlog/README b/isdnlog/README index 12b3fd05..ae027c0c 100644 --- a/isdnlog/README +++ b/isdnlog/README @@ -2031,6 +2031,12 @@ angegeben werden. ACHTUNG: Andere Bedeutung als in frueheren Versionen! (stdout="value") + -OX Angabe einer Datei, an der der Output von Option -mx (stderr) umgelenkt + werden soll. Nur gueltig mit Option -m zusammen! + Es ist moeglich parallel die Option -C X zu setzen. Dann wird + sowohl auf der Console als auch in der Datei die Ausgabe ausgegeben. + (outfile="value") + -lX Angabe der gewuenschten Meldungen, die in's syslog eingetragen werden sollen (syslog="value") @@ -2546,6 +2552,7 @@ Die Optionen von isdnrep haben im einzelnen folgende Funktion: %O: Gibt den OUTPUT-Datendurchsatz an. %P: Gibt den INPUT-Datendurchsatz pro Sekunde an. %p: Gibt den OUTPUT-Datendurchsatz pro Sekunde an. + %S: Gibt die SI an. Defaultmaessig ist der folgende String fuer den isdnrep (nicht HTML) eingestellt: diff --git a/isdnlog/isdnlog/functions.c b/isdnlog/isdnlog/functions.c index f2d3e2f4..a7fe149b 100644 --- a/isdnlog/isdnlog/functions.c +++ b/isdnlog/isdnlog/functions.c @@ -1,4 +1,4 @@ -/* $Id: functions.c,v 1.6 1997/04/08 00:02:12 luethje Exp $ +/* $Id: functions.c,v 1.7 1997/05/09 23:30:45 luethje Exp $ * * ISDN accounting for isdn4linux. (log-module) * @@ -19,6 +19,11 @@ * along with this program; if not, write to the Free Software * * $Log: functions.c,v $ + * Revision 1.7 1997/05/09 23:30:45 luethje + * isdnlog: new switch -O + * isdnrep: new format %S + * bugfix in handle_runfiles() + * * Revision 1.6 1997/04/08 00:02:12 luethje * Bugfix: isdnlog is running again ;-) * isdnlog creates now a file like /var/lock/LCK..isdnctrl0 @@ -85,6 +90,9 @@ void _Exit(char *File, int Line, int RetCode) /* WARNING: RetCode==-9 does _not_ closelog(); + if (fout) + fclose(fout); + #ifdef POSTGRES dbClose(); #endif @@ -267,15 +275,24 @@ int print_msg(int Level, const char *fmt, ...) } /* if */ if (Level & message) + { if (fcons == NULL) { fputs(width ? s : String, stderr); fflush(stderr); } - else { + else + if (!fout){ fputs(width ? s : String, fcons); fflush(fcons); } /* else */ + if (fout) + { + fputs(width ? s : String, fout); + fflush(fout); + } + } + if (Level & xinfo) print_from_server(String); diff --git a/isdnlog/isdnlog/isdnlog.c b/isdnlog/isdnlog/isdnlog.c index a056caa9..17dde31b 100644 --- a/isdnlog/isdnlog/isdnlog.c +++ b/isdnlog/isdnlog/isdnlog.c @@ -1,4 +1,4 @@ -/* $Id: isdnlog.c,v 1.10 1997/05/06 22:13:26 luethje Exp $ +/* $Id: isdnlog.c,v 1.11 1997/05/09 23:30:47 luethje Exp $ * * ISDN accounting for isdn4linux. (log-module) * @@ -19,6 +19,11 @@ * along with this program; if not, write to the Free Software * * $Log: isdnlog.c,v $ + * Revision 1.11 1997/05/09 23:30:47 luethje + * isdnlog: new switch -O + * isdnrep: new format %S + * bugfix in handle_runfiles() + * * Revision 1.10 1997/05/06 22:13:26 luethje * bugfixes in HTML-Code of the isdnrep * @@ -57,7 +62,7 @@ /*****************************************************************************/ - /* Letzte Exit-Nummer: 43 */ + /* Letzte Exit-Nummer: 45 */ /*****************************************************************************/ @@ -73,9 +78,9 @@ static int read_param_file(char *FileName); static char usage[] = "%s: usage: %s [ -%s ] file\n"; #ifdef Q931 -static char options[] = "av:sp:x:m:l:rt:c:C:w:SVTDPMh:nW:H:f:bL:NqFA:2:"; +static char options[] = "av:sp:x:m:l:rt:c:C:w:SVTDPMh:nW:H:f:bL:NqFA:2:O:"; #else -static char options[] = "av:sp:x:m:l:rt:c:C:w:SVTDPMh:nW:H:f:bL:NFA:2:"; +static char options[] = "av:sp:x:m:l:rt:c:C:w:SVTDPMh:nW:H:f:bL:NFA:2:O:"; #endif static char msg1[] = "%s: Can't open %s (%s)\n"; static char *ptty = NULL; @@ -265,6 +270,7 @@ static void init_variables(int argc, char* argv[]) fcons = NULL; /* /dev/ttyX (or stderr) */ fprot = NULL; /* /tmp/isdnctrl0 */ isdnctrl = NULL; + fout = NULL; first_descr = FIRST_DESCR; message = PRT_NORMAL | PRT_WARN | PRT_ERR | PRT_INFO; @@ -295,6 +301,7 @@ static void init_variables(int argc, char* argv[]) bilingual = 0; mcalls = MAX_CALLS_IN_QUEUE; xlog = MAX_PRINTS_IN_QUEUE; + outfile = NULL; sockets = NULL; known = NULL; @@ -463,6 +470,9 @@ int set_options(int argc, char* argv[]) case '2' : dual = strtol(optarg, NIL, 0); break; + case 'O' : outfile = strdup(optarg); + break; + case '?' : printf(usage, myshortname, myshortname, options); exit(1); } /* switch */ @@ -621,6 +631,9 @@ static int read_param_file(char *FileName) #endif if (!strcmp(Ptr->name,CONF_ENT_WD)) watchdog = (int)strtol(Ptr->value, NIL, 0); + else + if (!strcmp(Ptr->name,CONF_ENT_OUTFILE)) + outfile = Ptr->value; else print_msg(PRT_ERR,"Error: Invalid entry `%s'!\n",Ptr->name); @@ -733,6 +746,23 @@ int main(int argc, char *argv[], char *envp[]) lastarg = set_options(argc,argv); + if (outfile != NULL) + { + if (!message) + { + print_msg(PRT_ERR,"Can not set outfile `%s', when -m is not set!\n",outfile); + Exit(44); + } + else + { + if ((fout = fopen(outfile,"w")) == NULL) + { + print_msg(PRT_ERR,"Can not open file `%s': %s!\n",outfile, strerror(errno)); + Exit(45); + } + } + } + if (lastarg < argc) isdnctrl = argv[lastarg]; diff --git a/isdnlog/isdnlog/isdnlog.h b/isdnlog/isdnlog/isdnlog.h index fef3a9e4..409afa56 100644 --- a/isdnlog/isdnlog/isdnlog.h +++ b/isdnlog/isdnlog/isdnlog.h @@ -1,4 +1,4 @@ -/* $Id: isdnlog.h,v 1.5 1997/04/08 00:02:17 luethje Exp $ +/* $Id: isdnlog.h,v 1.6 1997/05/09 23:30:50 luethje Exp $ * * ISDN accounting for isdn4linux. * @@ -20,6 +20,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: isdnlog.h,v $ + * Revision 1.6 1997/05/09 23:30:50 luethje + * isdnlog: new switch -O + * isdnrep: new format %S + * bugfix in handle_runfiles() + * * Revision 1.5 1997/04/08 00:02:17 luethje * Bugfix: isdnlog is running again ;-) * isdnlog creates now a file like /var/lock/LCK..isdnctrl0 @@ -188,6 +193,7 @@ extern socket_queue *sockets; _EXTERN FILE *flog; /* /var/adm/isdn.log */ _EXTERN FILE *fcons; /* /dev/ttyX (or stderr) */ _EXTERN FILE *fprot; /* /tmp/isdnctrl0 */ +_EXTERN FILE *fout; /* outfile */ _EXTERN int first_descr; _EXTERN int chan; @@ -230,6 +236,7 @@ _EXTERN int width; _EXTERN int watchdog; _EXTERN char *isdnctrl; _EXTERN char isdnctrl2[FNSIZE]; +_EXTERN char *outfile; _EXTERN IFO ifo[ISDN_MAX_CHANNELS]; _EXTERN IO io[ISDN_MAX_CHANNELS]; diff --git a/isdnlog/isdnrep/isdnrep.c b/isdnlog/isdnrep/isdnrep.c index 9ff196b0..7e614192 100644 --- a/isdnlog/isdnrep/isdnrep.c +++ b/isdnlog/isdnrep/isdnrep.c @@ -1,4 +1,4 @@ -/* $Id: isdnrep.c,v 1.17 1997/05/06 22:13:31 luethje Exp $ +/* $Id: isdnrep.c,v 1.18 1997/05/09 23:30:55 luethje Exp $ * * ISDN accounting for isdn4linux. (Report-module) * @@ -20,6 +20,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: isdnrep.c,v $ + * Revision 1.18 1997/05/09 23:30:55 luethje + * isdnlog: new switch -O + * isdnrep: new format %S + * bugfix in handle_runfiles() + * * Revision 1.17 1997/05/06 22:13:31 luethje * bugfixes in HTML-Code of the isdnrep * @@ -989,6 +994,9 @@ static int print_line(int status, one_call *cur_call, int computed, char *overla /* Benoetigt Range! */ case 'p': colsize[i] = append_string(&string,*fmtstring,set_byte_string(GET_OUT|GET_BPS,cur_call->duration?cur_call->obytes/(double)cur_call->duration:0.0)); break; + /* SI: */ + case 'S': colsize[i] = append_string(&string,*fmtstring,int2str(cur_call->si,2)); + break; /* there are dummy entries */ case 'c': case 'd': diff --git a/isdnlog/tools/tools.h b/isdnlog/tools/tools.h index b8f8cce3..6129018a 100644 --- a/isdnlog/tools/tools.h +++ b/isdnlog/tools/tools.h @@ -1,4 +1,4 @@ -/* $Id: tools.h,v 1.12 1997/05/04 20:20:05 luethje Exp $ +/* $Id: tools.h,v 1.13 1997/05/09 23:31:00 luethje Exp $ * * ISDN accounting for isdn4linux. * @@ -20,6 +20,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: tools.h,v $ + * Revision 1.13 1997/05/09 23:31:00 luethje + * isdnlog: new switch -O + * isdnrep: new format %S + * bugfix in handle_runfiles() + * * Revision 1.12 1997/05/04 20:20:05 luethje * README completed * isdnrep finished @@ -343,32 +348,33 @@ /* Keywords for parameter file */ -#define CONF_SEC_OPT "OPTIONS" -#define CONF_ENT_DEV "DEVICE" -#define CONF_ENT_LOG "LOG" -#define CONF_ENT_FLUSH "FLUSH" -#define CONF_ENT_PORT "PORT" -#define CONF_ENT_STDOUT "STDOUT" -#define CONF_ENT_SYSLOG "SYSLOG" -#define CONF_ENT_XISDN "XISDN" -#define CONF_ENT_TIME "TIME" -#define CONF_ENT_CON "CONSOLE" -#define CONF_ENT_START "START" -#define CONF_ENT_THRU "THRUPUT" -#define CONF_ENT_DAEMON "DAEMON" -#define CONF_ENT_PIPE "PIPE" -#define CONF_ENT_BI "BILINGUAL" -#define CONF_ENT_MON "MONITOR" -#define CONF_ENT_HANGUP "HANGUP" -#define CONF_ENT_CALLS "CALLS" -#define CONF_ENT_XLOG "XLOG" -#define CONF_ENT_NL "NEWLINE" -#define CONF_ENT_WIDTH "WIDTH" -#define CONF_ENT_WD "WATCHDOG" -#define CONF_ENT_CW "CITYWEEKEND" -#define CONF_ENT_AMT "AMT" -#define CONF_ENT_DUAL "DUAL" -#define CONF_ENT_Q931 "Q931DUMP" +#define CONF_SEC_OPT "OPTIONS" +#define CONF_ENT_DEV "DEVICE" +#define CONF_ENT_LOG "LOG" +#define CONF_ENT_FLUSH "FLUSH" +#define CONF_ENT_PORT "PORT" +#define CONF_ENT_STDOUT "STDOUT" +#define CONF_ENT_SYSLOG "SYSLOG" +#define CONF_ENT_XISDN "XISDN" +#define CONF_ENT_TIME "TIME" +#define CONF_ENT_CON "CONSOLE" +#define CONF_ENT_START "START" +#define CONF_ENT_THRU "THRUPUT" +#define CONF_ENT_DAEMON "DAEMON" +#define CONF_ENT_PIPE "PIPE" +#define CONF_ENT_BI "BILINGUAL" +#define CONF_ENT_MON "MONITOR" +#define CONF_ENT_HANGUP "HANGUP" +#define CONF_ENT_CALLS "CALLS" +#define CONF_ENT_XLOG "XLOG" +#define CONF_ENT_NL "NEWLINE" +#define CONF_ENT_WIDTH "WIDTH" +#define CONF_ENT_WD "WATCHDOG" +#define CONF_ENT_CW "CITYWEEKEND" +#define CONF_ENT_AMT "AMT" +#define CONF_ENT_DUAL "DUAL" +#define CONF_ENT_Q931 "Q931DUMP" +#define CONF_ENT_OUTFILE "OUTFILE" /****************************************************************************/ diff --git a/lib/isdntools.c b/lib/isdntools.c index dd951427..6138424d 100644 --- a/lib/isdntools.c +++ b/lib/isdntools.c @@ -1,4 +1,4 @@ -/* $Id: isdntools.c,v 1.11 1997/04/15 00:20:17 luethje Exp $ +/* $Id: isdntools.c,v 1.12 1997/05/09 23:31:06 luethje Exp $ * * ISDN accounting for isdn4linux. (Utilities) * @@ -19,6 +19,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: isdntools.c,v $ + * Revision 1.12 1997/05/09 23:31:06 luethje + * isdnlog: new switch -O + * isdnrep: new format %S + * bugfix in handle_runfiles() + * * Revision 1.11 1997/04/15 00:20:17 luethje * replace variables: some bugfixes, README comleted * @@ -348,8 +353,10 @@ int handle_runfiles(const char *_progname, char **_devices, int flag) static char progname[SHORT_STRING_SIZE] = ""; static char **devices = NULL; auto char string[PATH_MAX]; + auto char string2[SHORT_STRING_SIZE]; auto char *Ptr = NULL; auto int RetCode = -1; + auto FILE *fp; if (progname[0] == '\0' || devices == NULL) @@ -406,8 +413,20 @@ int handle_runfiles(const char *_progname, char **_devices, int flag) while (*devices != NULL) { sprintf(string,"%s%c%s%s",LOCKDIR,C_SLASH,LOCKFILE,*devices); - if (unlink(string)) - print_msg("Can not remove file %s (%s)!\n", *devices, strerror(errno)); + + if ((fp = fopen(string, "r")) != NULL) + { + if (fgets(string2,SHORT_STRING_SIZE,fp) != NULL) + { + if (atoi(string2) == (int)getpid()) + { + if (unlink(string)) + print_msg("Can not remove file %s (%s)!\n", string, strerror(errno)); + } + } + + fclose(fp); + } devices++; } diff --git a/lib/libtools.c b/lib/libtools.c index 671881bf..475f8f17 100644 --- a/lib/libtools.c +++ b/lib/libtools.c @@ -1,4 +1,4 @@ -/* $Id: libtools.c,v 1.5 1997/04/15 00:20:18 luethje Exp $ +/* $Id: libtools.c,v 1.6 1997/05/09 23:31:09 luethje Exp $ * ISDN accounting for isdn4linux. * * Copyright 1996 by Stefan Luethje (luethje@sl-gw.lake.de) @@ -18,6 +18,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: libtools.c,v $ + * Revision 1.6 1997/05/09 23:31:09 luethje + * isdnlog: new switch -O + * isdnrep: new format %S + * bugfix in handle_runfiles() + * * Revision 1.5 1997/04/15 00:20:18 luethje * replace variables: some bugfixes, README comleted * @@ -626,3 +631,22 @@ char *Replace_Variable(char *String) /****************************************************************************/ +#define MAX_PREC 9 + +char *int2str(int value, int prec) +{ + static char RetCode[MAX_PREC+1]; + + if (prec < 0 || prec > MAX_PREC) + { + print_msg("Error: precision %d is out of range (0-%d)!\n",prec,MAX_PREC); + *RetCode = '\0'; + } + else + sprintf(RetCode,"%*d",prec,value); + + return RetCode; +} + +/****************************************************************************/ + diff --git a/lib/libtools.h b/lib/libtools.h index 1f0e41e6..5b93ecce 100644 --- a/lib/libtools.h +++ b/lib/libtools.h @@ -1,4 +1,4 @@ -/* $Id: libtools.h,v 1.5 1997/04/15 00:20:19 luethje Exp $ +/* $Id: libtools.h,v 1.6 1997/05/09 23:31:10 luethje Exp $ * * ISDN accounting for isdn4linux. * @@ -19,6 +19,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: libtools.h,v $ + * Revision 1.6 1997/05/09 23:31:10 luethje + * isdnlog: new switch -O + * isdnrep: new format %S + * bugfix in handle_runfiles() + * * Revision 1.5 1997/04/15 00:20:19 luethje * replace variables: some bugfixes, README comleted * @@ -99,6 +104,7 @@ _EXTERN int match(register char *p, register char *s, int flags); _EXTERN int is_double (char *string, double *value); _EXTERN int is_integer (char *string, long int *value); _EXTERN char *Replace_Variable(char *String); +_EXTERN char *int2str(int value, int prec); #undef _EXTERN