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"
37 #include "data_provider.h"
40 # define CONFIGFILE "/etc/collection.conf"
44 # define CACHEFILE "/tmp/collection4.json"
47 static time_t last_read_mtime = 0;
49 static char *cache_file = NULL;
51 static int dispatch_config (const oconfig_item_t *ci) /* {{{ */
55 for (i = 0; i < ci->children_num; i++)
57 oconfig_item_t *child;
59 child = ci->children + i;
60 if (strcasecmp ("Graph", child->key) == 0)
61 graph_config_add (child);
62 else if (strcasecmp ("DataProvider", child->key) == 0)
63 data_provider_config (child);
64 else if (strcasecmp ("CacheFile", child->key) == 0)
65 graph_config_get_string (child, &cache_file);
68 DEBUG ("Unknown config option: %s", child->key);
73 } /* }}} int dispatch_config */
75 static int internal_read_config (void) /* {{{ */
79 ci = oconfig_parse_file (CONFIGFILE);
90 } /* }}} int internal_read_config */
92 static time_t get_config_mtime (void) /* {{{ */
97 memset (&statbuf, 0, sizeof (statbuf));
98 status = stat (CONFIGFILE, &statbuf);
102 return (statbuf.st_mtime);
103 } /* }}} time_t get_config_mtime */
105 int graph_read_config (void) /* {{{ */
109 mtime = get_config_mtime ();
111 if (mtime <= last_read_mtime)
114 internal_read_config ();
116 last_read_mtime = mtime;
119 } /* }}} int graph_read_config */
121 int graph_config_get_string (const oconfig_item_t *ci, /* {{{ */
126 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
129 tmp = strdup (ci->values[0].value.string);
137 } /* }}} int graph_config_get_string */
139 int graph_config_get_bool (const oconfig_item_t *ci, /* {{{ */
142 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
145 if (ci->values[0].value.boolean)
151 } /* }}} int graph_config_get_bool */
153 const char *graph_config_get_cache_file (void) /* {{{ */
155 if (cache_file == NULL)
158 } /* }}} char graph_config_get_cache_file */
160 /* vim: set sw=2 sts=2 et fdm=marker : */