[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
configuration framework patch
From: |
Martin Pala |
Subject: |
configuration framework patch |
Date: |
Fri, 27 Sep 2002 01:42:20 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.0.0) Gecko/20020530 |
Hi,
there's open interface framework patch for allowing monit to support
more configuration sources in addition to present plaintext file. It is
based on general interface, that can call optional sub-procedures for
specific configuration sources. In the patch is for illustration
attached void parse_ldap() function, that actually does nothing (it is
the target for my next work). It works well on my station.
If you agree this architectural modification, i can commit it to the CVS :)
Greetings,
Martin
diff -Naur monit/files.c monit-devel/files.c
--- monit/files.c 2002-09-27 00:31:30.000000000 +0200
+++ monit-devel/files.c 2002-09-27 00:38:35.000000000 +0200
@@ -128,8 +128,8 @@
/**
* Search the system for the monit control file. Try first
* ~/.monitrc, if that fails try ./monitrc and finally /etc/monitrc.
- * Exit the application if the control file is not found.
- * @return The location of monits control file (monitrc)
+ * @return The location of monits control file (monitrc) or NULL if
+ * control file wasn't found
*/
char *find_rcfile() {
@@ -158,10 +158,7 @@
if ( exist_file(rcfile) )
return (rcfile);
- error("%s: Cannot find the control file at ~/.%s, ./%s or at /etc/%s\n",
- prog, MONITRC, MONITRC, MONITRC);
-
- exit(1);
+ return (NULL);
}
diff -Naur monit/ldap.c monit-devel/ldap.c
--- monit/ldap.c 1970-01-01 01:00:00.000000000 +0100
+++ monit-devel/ldap.c 2002-09-27 00:38:35.000000000 +0200
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C), 2000-2002 by Contributors to the monit codebase.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "monitor.h"
+
+/**
+ * LDAP access methods.
+ *
+ * @author Jan-Henrik Haukeland, <address@hidden>
+ * @author Martin Pala, <address@hidden>
+ *
+ * @version $Id$
+ *
+ * @file
+ */
+
+
+/* ------------------------------------------------------------------ Public */
+
+
+int parse_ldap() {
+
+ return TRUE;
+
+}
+
diff -Naur monit/monitor.c monit-devel/monitor.c
--- monit/monitor.c 2002-09-27 00:38:59.000000000 +0200
+++ monit-devel/monitor.c 2002-09-27 00:38:35.000000000 +0200
@@ -104,7 +104,7 @@
/**
* Initialize this application - Register signal handlers,
- * Parse the control file and initialize the program's
+ * Parse the configuration and initialize the program's
* datastructures and the log system.
*/
static void do_init() {
@@ -158,9 +158,9 @@
/*
* Start the Parser and create the process list. This will also set
- * any Runtime constants defined in the controlfile.
+ * any Runtime constants defined in the configuration.
*/
- if ( ! parse(Run.controlfile) ) {
+ if ( ! parse() ) {
exit(1);
@@ -208,7 +208,7 @@
/* Run the garbage collector */
gc();
- if ( ! parse(Run.controlfile) ) {
+ if ( ! parse() ) {
log("%s daemon died\n", prog);
exit(1);
diff -Naur monit/monitor.h monit-devel/monitor.h
--- monit/monitor.h 2002-09-26 20:04:08.000000000 +0200
+++ monit-devel/monitor.h 2002-09-27 00:38:35.000000000 +0200
@@ -296,7 +296,9 @@
char *url_encode(char *uri);
char *get_basic_authentication_header();
int set_md5sum(char **, char *);
-int parse(char *);
+int parse();
+int parse_plain(char *);
+int parse_ldap();
void start();
void start_group(char *);
void start_process(Process_T);
diff -Naur monit/p.y monit-devel/p.y
--- monit/p.y 2002-09-26 20:04:09.000000000 +0200
+++ monit-devel/p.y 2002-09-27 00:38:35.000000000 +0200
@@ -130,7 +130,6 @@
1, RESOURCE_ACTION_ALERT };
/* Private prototypes */
- static void initialize();
static void addprocess(Process_T);
static void addmail(char *, struct MailFilter *);
static void createprocess(char *, char *);
@@ -146,7 +145,6 @@
static void setuname(char *);
static void setpasswd(char *);
static void reset_mailfilter();
- static void reset_runmail();
static void reset_portset();
static void reset_resourceset();
static void check_name(char *);
@@ -507,10 +505,10 @@
/*
- * The Parser hook - start parsing the control file
- * Returns TRUE if parsing succeeded, otherwise FALSE
+ * Start parsing the plaintext control file
+ * @return TRUE if parsing succeeded, otherwise FALSE
*/
-int parse(char *controlfile) {
+int parse_plain(char *controlfile) {
processlist= tail= current= NULL;
@@ -524,15 +522,12 @@
error("%s: Error opening the control file '%s' -- %s\n",
prog, controlfile, STRERROR);
+
return(FALSE);
}
- /* Creation of the global process list is synchronized */
- LOCK(Run.mutex)
- initialize();
- yyparse();
- END_LOCK;
+ yyparse();
fclose(yyin);
@@ -552,26 +547,6 @@
/* ----------------------------------------------------------------- Private */
-/**
- * Initialize objects. Placeholder for setting values that can change
- * between cycles (changed config file) and not easily supported by
- * the grammar implementation.
- */
-static void initialize() {
-
- destroy_hosts_allow();
- Run.dolog= FALSE;
- Run.dohttpd= FALSE;
- Run.Auth.defined= FALSE;
- reset_runmail();
- if(Run.bind_addr) {
- free(Run.bind_addr);
- Run.bind_addr= NULL;
- }
-
-}
-
-
/*
* Create a new process object and add any current objects to the
* process list.
@@ -1011,21 +986,6 @@
}
-/*
- * Reset and release the Run mail-format sub-structure
- */
-static void reset_runmail() {
-
- free(Run.MailFormat.from);
- Run.MailFormat.from= NULL;
- free(Run.MailFormat.subject);
- Run.MailFormat.subject= NULL;
- free(Run.MailFormat.message);
- Run.MailFormat.message= NULL;
-
-}
-
-
/* ---------------------------------------------------------------- Checkers */
diff -Naur monit/util.c monit-devel/util.c
--- monit/util.c 2002-09-16 12:20:38.000000000 +0200
+++ monit-devel/util.c 2002-09-27 00:38:35.000000000 +0200
@@ -55,6 +55,8 @@
static int is_unsafe(unsigned char *c);
static char *is_str_defined(char *);
static char *is_str_defined_default(char *);
+static void initialize();
+static void reset_runmail();
/**
* General purpose utility methods.
@@ -935,6 +937,35 @@
}
+/**
+ * High level function to monit's configuration interface
+ */
+int parse() {
+
+ /* Creation of the global process list is synchronized */
+ LOCK(Run.mutex)
+
+ initialize();
+
+ if(Run.controlfile)
+ if(!parse_plain(Run.controlfile)) {
+ error("%s: Parsing of configuration file failed\n", prog);
+ return FALSE;
+ }
+
+ if( TRUE /* this will be replaced by test on variables that will define
ldap source */ )
+ if(!parse_ldap()) {
+ error("%s: Parsing of LDAP configuration failed\n", prog);
+ return FALSE;
+ }
+
+ END_LOCK;
+
+ return TRUE;
+
+}
+
+
/* ----------------------------------------------------------------- Private */
@@ -985,3 +1016,42 @@
}
+
+/**
+ * Initialize objects. Placeholder for setting values that can change
+ * between cycles (changed configuration) and not easily supported by
+ * the grammar implementation.
+ */
+static void initialize() {
+
+ destroy_hosts_allow();
+ reset_runmail();
+
+ Run.dolog= FALSE;
+ Run.dohttpd= FALSE;
+ Run.Auth.defined= FALSE;
+
+ if(Run.bind_addr) {
+ free(Run.bind_addr);
+ Run.bind_addr= NULL;
+ }
+
+}
+
+
+/*
+ * Reset and release the Run mail-format sub-structure
+ */
+static void reset_runmail() {
+
+ free(Run.MailFormat.from);
+ Run.MailFormat.from= NULL;
+
+ free(Run.MailFormat.subject);
+ Run.MailFormat.subject= NULL;
+
+ free(Run.MailFormat.message);
+ Run.MailFormat.message= NULL;
+
+}
+
- configuration framework patch,
Martin Pala <=