diff --git a/isdnlog/isdnlog/isdnlog.c b/isdnlog/isdnlog/isdnlog.c index d0772fab..f6516110 100644 --- a/isdnlog/isdnlog/isdnlog.c +++ b/isdnlog/isdnlog/isdnlog.c @@ -1,4 +1,4 @@ -/* $Id: isdnlog.c,v 1.71 2004/01/26 15:20:08 tobiasb Exp $ +/* $Id: isdnlog.c,v 1.72 2004/01/28 14:27:46 tobiasb Exp $ * * ISDN accounting for isdn4linux. (log-module) * @@ -19,6 +19,13 @@ * along with this program; if not, write to the Free Software * * $Log: isdnlog.c,v $ + * Revision 1.72 2004/01/28 14:27:46 tobiasb + * Second step in restricting fds at isdnlog restart and script starting. + * The fd limit is now taken from getrlimit() instead of NR_OPEN. + * Close_Fds(first) which tries to close all possible fds is generally + * built in but the execution must be requested with "closefds=yes" in + * the parameterfile otherwise the isdnlog behaviour remains unchanged. + * * Revision 1.71 2004/01/26 15:20:08 tobiasb * First step to close all unnecessary open file descriptors before * starting a start script as reaction to a call. The same applies to the @@ -582,7 +589,8 @@ static void hup_handler(int isig) { print_msg(PRT_INFO, "restarting %s\n", myname); Exit(-9); - Close_Fds(3); /* avoid duplicate fds after restart */ + if (param_closefds) + Close_Fds(3); /* avoid duplicate fds after restart */ execv(myname, hup_argv); print_msg(PRT_ERR,"Cannot restart %s: %s!\n", myname, strerror(errno)); } /* hup_handler */ @@ -1156,18 +1164,14 @@ static int read_param_file(char *FileName) if (!strcmp(Ptr->name,CONF_ENT_PIPE)) stdoutput = toupper(*(Ptr->value)) == 'Y'?PRT_LOG:0; else - if (!strcmp(Ptr->name,CONF_ENT_MON)) - imon = toupper(*(Ptr->value)) == 'Y'?1:0; - else if (!strcmp(Ptr->name,CONF_ENT_HANGUP)) { hupctrl++; - if ((p = strchr(Ptr->value, ':'))) { - *p = 0; - hup1 = atoi(Ptr->value); - hup2 = atoi(p + 1); - - if ((p = strchr(p + 1, ':'))) - hup3 = atoi(p + 1); + if ((p = strchr(Ptr->value, ':'))) { + *p = 0; + hup1 = atoi(Ptr->value); + hup2 = atoi(p + 1); + if ((p = strchr(p + 1, ':'))) + hup3 = atoi(p + 1); } /* if */ else printf("%s: WARNING: \"-h\" Option requires 2 .. 3 arguments\n", myshortname); @@ -1179,27 +1183,27 @@ static int read_param_file(char *FileName) if (!strcmp(Ptr->name,CONF_ENT_ABCLCR)) abclcr = atoi(Ptr->value); else - if (!strcmp(Ptr->name, CONF_ENT_CIINTERVAL)) { - if ((p = strchr(Ptr->value, ':'))) { - *p = 0; - ciInterval = atoi(Ptr->value); - ehInterval = atoi(p + 1); - } - else - ciInterval = ehInterval = atoi(Ptr->value); - } + if (!strcmp(Ptr->name, CONF_ENT_CIINTERVAL)) { + if ((p = strchr(Ptr->value, ':'))) { + *p = 0; + ciInterval = atoi(Ptr->value); + ehInterval = atoi(p + 1); + } + else + ciInterval = ehInterval = atoi(Ptr->value); + } else - if (!strcmp(Ptr->name, CONF_ENT_TRIM)) { - trim++; - if ((p = strchr(Ptr->value, ':'))) { - *p = 0; - trimi = atoi(Ptr->value); - trimo = atoi(p + 1); - } - else - trimi = trimo = atoi(Ptr->value); - } - else + if (!strcmp(Ptr->name, CONF_ENT_TRIM)) { + trim++; + if ((p = strchr(Ptr->value, ':'))) { + *p = 0; + trimi = atoi(Ptr->value); + trimo = atoi(p + 1); + } + else + trimi = trimo = atoi(Ptr->value); + } + else if (!strcmp(Ptr->name,CONF_ENT_BI)) bilingual = toupper(*(Ptr->value)) == 'Y'?1:0; else @@ -1222,7 +1226,7 @@ static int read_param_file(char *FileName) } else if (!strcmp(Ptr->name,CONF_ENT_AMT)) - amtsholung = strdup(Ptr->value); + amtsholung = strdup(Ptr->value); else #ifdef Q931 if (!strcmp(Ptr->name,CONF_ENT_Q931)) @@ -1244,33 +1248,36 @@ static int read_param_file(char *FileName) if (!strcmp(Ptr->name,CONF_ENT_INTERNS0)) interns0 = (int)strtol(Ptr->value, NIL, 0); else - if (!strcmp(Ptr->name,CONF_ENT_PRESELECT)) - preselect = (int)strtol(Ptr->value, NIL, 0); - else - if (!strcmp(Ptr->name,CONF_ENT_OTHER)) - other = toupper(*(Ptr->value)) == 'Y'?1:0; - else + if (!strcmp(Ptr->name,CONF_ENT_PRESELECT)) + preselect = (int)strtol(Ptr->value, NIL, 0); + else + if (!strcmp(Ptr->name,CONF_ENT_OTHER)) + other = toupper(*(Ptr->value)) == 'Y'?1:0; + else #if 0 /* Fixme: remove */ if (!strcmp(Ptr->name,CONF_ENT_CW)) CityWeekend++; - else + else #endif - if (!strcmp(Ptr->name,CONF_ENT_IGNORERR)) - ignoreRR = (int)strtol(Ptr->value, NIL, 0); - else - if (!strcmp(Ptr->name,CONF_ENT_IGNORECOLP)) - ignoreCOLP = (int)strtol(Ptr->value, NIL, 0); - else - if (!strcmp(Ptr->name,CONF_ENT_VBN)) { - free(vbn); - vbn = strdup(Ptr->value); - } - else - if (!strcmp(Ptr->name,CONF_ENT_VBNLEN)) { - free(vbnlen); - vbnlen = strdup(Ptr->value); - } - else + if (!strcmp(Ptr->name,CONF_ENT_IGNORERR)) + ignoreRR = (int)strtol(Ptr->value, NIL, 0); + else + if (!strcmp(Ptr->name,CONF_ENT_IGNORECOLP)) + ignoreCOLP = (int)strtol(Ptr->value, NIL, 0); + else + if (!strcmp(Ptr->name,CONF_ENT_VBN)) { + free(vbn); + vbn = strdup(Ptr->value); + } + else + if (!strcmp(Ptr->name,CONF_ENT_VBNLEN)) { + free(vbnlen); + vbnlen = strdup(Ptr->value); + } + else + if (!strcmp(Ptr->name,CONF_ENT_CLOSEFDS)) + param_closefds = toupper(*(Ptr->value)) == 'Y'?1:0; + else print_msg(PRT_ERR,"Error: Invalid entry `%s'!\n",Ptr->name); Ptr = Ptr->next; diff --git a/isdnlog/isdnlog/isdnlog.h b/isdnlog/isdnlog/isdnlog.h index 9b66b9b8..cc12c56c 100644 --- a/isdnlog/isdnlog/isdnlog.h +++ b/isdnlog/isdnlog/isdnlog.h @@ -1,4 +1,4 @@ -/* $Id: isdnlog.h,v 1.27 2004/01/26 15:20:08 tobiasb Exp $ +/* $Id: isdnlog.h,v 1.28 2004/01/28 14:27:46 tobiasb Exp $ * * ISDN accounting for isdn4linux. * @@ -20,6 +20,13 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: isdnlog.h,v $ + * Revision 1.28 2004/01/28 14:27:46 tobiasb + * Second step in restricting fds at isdnlog restart and script starting. + * The fd limit is now taken from getrlimit() instead of NR_OPEN. + * Close_Fds(first) which tries to close all possible fds is generally + * built in but the execution must be requested with "closefds=yes" in + * the parameterfile otherwise the isdnlog behaviour remains unchanged. + * * Revision 1.27 2004/01/26 15:20:08 tobiasb * First step to close all unnecessary open file descriptors before * starting a start script as reaction to a call. The same applies to the @@ -414,14 +421,6 @@ /****************************************************************************/ -#ifndef FD_AT_EXEC_MODE -#define FD_AT_EXEC_MODE 0 -#endif -#define FD_AT_EXEC_CLOSE (FD_AT_EXEC_MODE & 1) -#define FD_AT_EXEC_FLAG (FD_AT_EXEC_MODE & 2) /* not implemented yet */ - -/****************************************************************************/ - typedef struct { int current; int shift; @@ -444,10 +443,12 @@ typedef struct _interval { #define _EXTERN socket_queue *sockets = NULL; _EXTERN int ignore_unknown_IE = 0xFE; /* codesets 7 to 1 */ +_EXTERN int param_closefds = 0; #else #define _EXTERN extern extern socket_queue *sockets; _EXTERN int ignore_unknown_IE; +_EXTERN int param_closefds; #endif _EXTERN FILE *flog; /* /var/adm/isdn.log */ @@ -596,12 +597,7 @@ _EXTERN int Del_Interval(int chan, info_args *infoarg); _EXTERN struct timeval *Get_Interval(int Sec); _EXTERN int Change_Channel_Ring( int old_channel, int new_channel); _EXTERN int Start_Interval(void); - -#if FD_AT_EXEC_CLOSE _EXTERN void Close_Fds( const int first ); -#else -#define Close_Fds(a) ; -#endif #undef _EXTERN diff --git a/isdnlog/isdnlog/start_prog.c b/isdnlog/isdnlog/start_prog.c index 2622596c..f745f9d3 100644 --- a/isdnlog/isdnlog/start_prog.c +++ b/isdnlog/isdnlog/start_prog.c @@ -1,4 +1,4 @@ -/* $Id: start_prog.c,v 1.17 2004/01/26 15:20:07 tobiasb Exp $ +/* $Id: start_prog.c,v 1.18 2004/01/28 14:27:46 tobiasb Exp $ * * ISDN accounting for isdn4linux. * @@ -20,6 +20,13 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: start_prog.c,v $ + * Revision 1.18 2004/01/28 14:27:46 tobiasb + * Second step in restricting fds at isdnlog restart and script starting. + * The fd limit is now taken from getrlimit() instead of NR_OPEN. + * Close_Fds(first) which tries to close all possible fds is generally + * built in but the execution must be requested with "closefds=yes" in + * the parameterfile otherwise the isdnlog behaviour remains unchanged. + * * Revision 1.17 2004/01/26 15:20:07 tobiasb * First step to close all unnecessary open file descriptors before * starting a start script as reaction to a call. The same applies to the @@ -103,11 +110,11 @@ #define _START_PROG_C_ -#include /* for NR_OPEN, must precede isdnlog.h */ #include "isdnlog.h" #include #include #include +#include /*************************************************************************/ @@ -271,7 +278,8 @@ int Ring(info_args *Cmd, char *Opts[], int Die, int Async) dup2(filedes[1],STDOUT_FILENO); dup2(filedes[1],STDERR_FILENO); - Close_Fds(3); /* do not leave isdnlog's fds to script */ + if (param_closefds) + Close_Fds(3); /* do not leave isdnlog's fds to script */ /* execvp(Pathfind(Args[0],NULL,NULL), Args);*/ execvp(Args[0], Args); @@ -1180,18 +1188,24 @@ int Change_Channel_Ring( int old_channel, int new_channel) /****************************************************************************/ -#if FD_AT_EXEC_CLOSE void Close_Fds( const int first ) { - int i,r; - for (i = first; i < NR_OPEN; i++) { - r = close(i); + int i, r; + struct rlimit rlim; + + r = getrlimit(RLIMIT_NOFILE, &rlim); + if (r == -1) { + print_msg(PRT_WARN, "number of fds unknown, no close prior to exec: %s", strerror(errno)); + return; + } + + for (i = first; i < rlim.rlim_cur; i++) { + r = close(i); if (r == -1 && errno != EBADF) print_msg(PRT_WARN, "close of fd %i prior to exec failed: %s", i, strerror(errno)); } } -#endif /****************************************************************************/ diff --git a/isdnlog/tools/tools.h b/isdnlog/tools/tools.h index 8687d5d1..4c92176f 100644 --- a/isdnlog/tools/tools.h +++ b/isdnlog/tools/tools.h @@ -1,4 +1,4 @@ -/* $Id: tools.h,v 1.59 2003/08/26 19:46:13 tobiasb Exp $ +/* $Id: tools.h,v 1.60 2004/01/28 14:27:47 tobiasb Exp $ * * ISDN accounting for isdn4linux. * @@ -20,6 +20,13 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: tools.h,v $ + * Revision 1.60 2004/01/28 14:27:47 tobiasb + * Second step in restricting fds at isdnlog restart and script starting. + * The fd limit is now taken from getrlimit() instead of NR_OPEN. + * Close_Fds(first) which tries to close all possible fds is generally + * built in but the execution must be requested with "closefds=yes" in + * the parameterfile otherwise the isdnlog behaviour remains unchanged. + * * Revision 1.59 2003/08/26 19:46:13 tobiasb * isdnlog-4.66: * - Added support for AVM B1 (with layer 2 d-channel trace) in point-to- @@ -884,6 +891,7 @@ #define CONF_ENT_CIINTERVAL "CIINTERVAL" #define CONF_ENT_ABCLCR "ABCLCR" #define CONF_ENT_PROVIDERCHANGE "PROVIDERCHANGE" +#define CONF_ENT_CLOSEFDS "CLOSEFDS" /****************************************************************************/ /* Keywords for isdn.conf */ @@ -1133,14 +1141,17 @@ _EXTERN char ilabel[256]; _EXTERN char olabel[256]; _EXTERN char idate[256]; _EXTERN CALL call[MAXCHAN]; + #ifdef Q931 _EXTERN int q931dmp; #else #define q931dmp 0 #endif + #if 0 /* Fixme: remove */ _EXTERN int CityWeekend; #endif + _EXTERN int preselect; /* global variables specific to isdnlog (e.g. for parameterfile/commandline * settings) should be moved to isdnlog/isdnlog.h. |TB| 2003-08-22 */