2 * collection4 - graph_config.c
3 * Copyright (C) 2010 Florian octo Forster
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 * Florian octo Forster <ff at octo.it>
28 #include <sys/types.h>
32 #include "graph_config.h"
34 #include "graph_list.h"
39 # define CONFIGFILE "/etc/collection.conf"
42 time_t last_read_mtime = 0;
44 static int dispatch_config (const oconfig_item_t *ci) /* {{{ */
48 for (i = 0; i < ci->children_num; i++)
50 oconfig_item_t *child;
52 child = ci->children + i;
53 if (strcasecmp ("Graph", child->key) == 0)
54 graph_config_add (child);
57 DEBUG ("Unknown config option: %s", child->key);
62 } /* }}} int dispatch_config */
64 static int internal_read_config (void) /* {{{ */
68 ci = oconfig_parse_file (CONFIGFILE);
79 } /* }}} int internal_read_config */
81 static time_t get_config_mtime (void) /* {{{ */
86 memset (&statbuf, 0, sizeof (statbuf));
87 status = stat (CONFIGFILE, &statbuf);
91 return (statbuf.st_mtime);
92 } /* }}} time_t get_config_mtime */
94 int graph_read_config (void) /* {{{ */
98 mtime = get_config_mtime ();
100 if (mtime <= last_read_mtime)
103 internal_read_config ();
105 last_read_mtime = mtime;
108 } /* }}} int graph_read_config */
110 int graph_config_get_string (const oconfig_item_t *ci, /* {{{ */
115 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
118 tmp = strdup (ci->values[0].value.string);
126 } /* }}} int graph_config_get_string */
128 int graph_config_get_bool (const oconfig_item_t *ci, /* {{{ */
131 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
134 if (ci->values[0].value.boolean)
140 } /* }}} int graph_config_get_bool */
142 /* vim: set sw=2 sts=2 et fdm=marker : */