comparison extensions/rt_default/rtd_conf.y @ 1336:cec0812038bb

rt_default: add reload support. When SIGUSR1 is sent to the freeDiameter process, rt_default reloads its config file. Written for Effortel Technologies SA, published with their consent.
author Thomas Klausner <tk@giga.or.at>
date Tue, 09 Apr 2019 15:46:50 +0200
parents 1af09cc156d6
children 566bb46cc73f
comparison
equal deleted inserted replaced
1335:870eecffa3fe 1336:cec0812038bb
52 #include "rt_default.h" 52 #include "rt_default.h"
53 #include "rtd_conf.tab.h" /* bison is not smart enough to define the YYLTYPE before including this code, so... */ 53 #include "rtd_conf.tab.h" /* bison is not smart enough to define the YYLTYPE before including this code, so... */
54 54
55 /* Forward declaration */ 55 /* Forward declaration */
56 int yyparse(char * conffile); 56 int yyparse(char * conffile);
57 void rtd_confrestart(FILE *input_file);
57 58
58 static int rules_added = 0; 59 static int rules_added = 0;
59 60
60 /* Parse the configuration file */ 61 /* Parse the configuration file */
61 int rtd_conf_handle(char * conffile) 62 int rtd_conf_handle(char * conffile)
63 extern FILE * rtd_confin; 64 extern FILE * rtd_confin;
64 int ret; 65 int ret;
65 66
66 TRACE_ENTRY("%p", conffile); 67 TRACE_ENTRY("%p", conffile);
67 68
68 TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile); 69 TRACE_DEBUG (FULL, "rt_default: Parsing configuration file: %s...", conffile);
69 70
71 rules_added = 0;
70 rtd_confin = fopen(conffile, "r"); 72 rtd_confin = fopen(conffile, "r");
71 if (rtd_confin == NULL) { 73 if (rtd_confin == NULL) {
72 ret = errno; 74 ret = errno;
73 fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret)); 75 fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret));
74 TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file."); 76 TRACE_DEBUG (INFO, "rt_default: Error occurred, message logged -- configuration file.");
75 return ret; 77 return ret;
76 } 78 }
77 79
80 rtd_confrestart(rtd_confin);
78 ret = yyparse(conffile); 81 ret = yyparse(conffile);
79 82
80 fclose(rtd_confin); 83 fclose(rtd_confin);
81 84
82 if (ret != 0) { 85 if (ret != 0) {
83 TRACE_DEBUG (INFO, "Unable to parse the configuration file."); 86 TRACE_DEBUG (INFO, "rt_default: Unable to parse the configuration file.");
84 return EINVAL; 87 return EINVAL;
85 } else { 88 } else {
86 TRACE_DEBUG(FULL, "Added %d RULES routing entries successfully.", rules_added); 89 TRACE_DEBUG(INFO, "rt_default: Added %d RULES routing entries successfully.", rules_added);
87 } 90 }
88 91
89 return 0; 92 return 0;
90 } 93 }
91 94
93 int rtd_conflex(YYSTYPE *lvalp, YYLTYPE *llocp); 96 int rtd_conflex(YYSTYPE *lvalp, YYLTYPE *llocp);
94 97
95 /* Function to report the errors */ 98 /* Function to report the errors */
96 void yyerror (YYLTYPE *ploc, char * conffile, char const *s) 99 void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
97 { 100 {
98 TRACE_DEBUG(INFO, "Error in configuration parsing"); 101 TRACE_DEBUG(INFO, "rt_default: Error in configuration parsing");
99 102
100 if (ploc->first_line != ploc->last_line) 103 if (ploc->first_line != ploc->last_line)
101 fd_log_debug("%s:%d.%d-%d.%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s); 104 fd_log_debug("%s:%d.%d-%d.%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
102 else if (ploc->first_column != ploc->last_column) 105 else if (ploc->first_column != ploc->last_column)
103 fd_log_debug("%s:%d.%d-%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s); 106 fd_log_debug("%s:%d.%d-%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
"Welcome to our mercurial repository"