vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "apache");
        strcpy (vl.plugin_instance, "");
        strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "apache");
        strcpy (vl.plugin_instance, "");
 
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "apcups");
        strcpy (vl.plugin_instance, "");
        strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "apple_sensors");
        strcpy (vl.plugin_instance, "");
        strcpy (vl.type_instance, type_instance);
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "battery");
        strcpy (vl.plugin_instance, plugin_instance);
 
 
 #include "plugin.h"
 #include "configfile.h"
 
-static int loop = 0;
-
+/*
+ * Global variables
+ */
+char hostname_g[DATA_MAX_NAME_LEN];
+int  interval_g;
 #if HAVE_LIBKSTAT
 kstat_ctl_t *kc;
 #endif /* HAVE_LIBKSTAT */
 
-/*
- * exported variables
- */
-time_t curtime;
+static int loop = 0;
 
 static void sigIntHandler (int signal)
 {
        loop++;
 }
 
+static int init_global_variables (void)
+{
+       const char *str;
+
+       str = global_option_get ("Hostname");
+       if (str != NULL)
+       {
+               strncpy (hostname_g, str, sizeof (hostname_g));
+       }
+       else
+       {
+               if (gethostname (hostname_g, sizeof (hostname_g)) != 0)
+               {
+                       fprintf (stderr, "`gethostname' failed and no "
+                                       "hostname was configured.\n");
+                       return (-1);
+               }
+       }
+       DBG ("hostname_g = %s;", hostname_g);
+
+       str = global_option_get ("Interval");
+       if (str == NULL)
+               str = COLLECTD_STEP;
+       interval_g = atoi (str);
+       if (interval_g <= 0)
+       {
+               fprintf (stderr, "Cannot set the interval to a correct value.\n"
+                               "Please check your settings.\n");
+               return (-1);
+       }
+       DBG ("interval_g = %i;", interval_g);
+
+       return (0);
+} /* int init_global_variables */
+
 static int change_basedir (const char *orig_dir)
 {
        char *dir = strdup (orig_dir);
 
 static int do_loop (void)
 {
-       int step;
-
        struct timeval tv_now;
        struct timeval tv_next;
        struct timespec ts_wait;
 
-       step = atoi (COLLECTD_STEP);
-       if (step <= 0)
-               step = 10;
-
        while (loop == 0)
        {
                if (gettimeofday (&tv_next, NULL) < 0)
                        syslog (LOG_ERR, "gettimeofday failed: %s", strerror (errno));
                        return (-1);
                }
-               tv_next.tv_sec += step;
+               tv_next.tv_sec += interval_g;
 
 #if HAVE_LIBKSTAT
                update_kstat ();
 #endif
-               /* `curtime' is used by many (all?) plugins as the
-                * data-sample-time passed to RRDTool */
-               curtime = time (NULL);
 
                /* Issue all plugins */
                plugin_read_all (&loop);
        struct sigaction sigIntAction;
        struct sigaction sigTermAction;
        char *configfile = CONFIGFILE;
-       const char *datadir;
+       const char *basedir;
 #if COLLECT_DAEMON
        struct sigaction sigChldAction;
        pid_t pid;
         * Change directory. We do this _after_ reading the config and loading
         * modules to relative paths work as expected.
         */
-       if ((datadir = global_option_get ("BaseDir")) == NULL)
+       if ((basedir = global_option_get ("BaseDir")) == NULL)
        {
-               fprintf (stderr, "Don't have a datadir to use. This should not happen. Ever.");
+               fprintf (stderr, "Don't have a basedir to use. This should not happen. Ever.");
                return (1);
        }
-       else if (change_basedir (datadir))
+       else if (change_basedir (basedir))
        {
-               fprintf (stderr, "Error: Unable to change to directory `%s'.\n", datadir);
+               fprintf (stderr, "Error: Unable to change to directory `%s'.\n", basedir);
                return (1);
        }
 
+       /*
+        * Set global variables or, if that failes, exit. We cannot run with
+        * them being uninitialized. If nothing is configured, then defaults
+        * are being used. So this means that the user has actually done
+        * something wrong.
+        */
+       if (init_global_variables () != 0)
+               return (1);
+
 #if COLLECT_DAEMON
        /*
         * fork off child
 
 Sets the file to write debugging output to. This is only used if compiled with
 debugging enabled. It's ignored otherwise.
 
+=item B<Interval> I<Seconds>
+
+Configures the interval in which to query the read plugins. Obviously smaller
+values lead to a higher system load produces by collectd, while higher values
+lead to more coarse statistics. Please note that changing this value may render
+your RRD-files unuseable, if you use the C<rrdtool plugin>. You have been
+warned.
+
 =back
 
 =head1 PLUGIN OPTIONS
 
 
 #define STATIC_ARRAY_LEN(array) (sizeof (array) / sizeof ((array)[0]))
 
-extern time_t curtime;
-
-int pidfile_set (const char *file);
-const char *pidfile_get (void);
+extern char hostname_g[];
+extern int  interval_g;
 
 /* int main (int argc, char **argv); */
 
 
 
 static cf_global_option_t cf_global_options[] =
 {
-       {"BaseDir", NULL, PKGLOCALSTATEDIR},
-       {"LogFile", NULL, LOGFILE},
-       {"PIDFile", NULL, PIDFILE}
+       {"BaseDir",   NULL, PKGLOCALSTATEDIR},
+       {"LogFile",   NULL, LOGFILE},
+       {"PIDFile",   NULL, PIDFILE},
+       {"Hostname",  NULL, NULL},
+       {"Interval",  NULL, "10"}
 };
 static int cf_global_options_num = STATIC_ARRAY_LEN (cf_global_options);
 
 {
        int i;
 
+       DBG ("option = %s; value = %s;", option, value);
+
        for (i = 0; i < cf_global_options_num; i++)
                if (strcasecmp (cf_global_options[i].key, option) == 0)
                        break;
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "cpu");
        snprintf (vl.plugin_instance, sizeof (vl.type_instance),
                        "%i", cpu_num);
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "cpufreq");
        snprintf (vl.type_instance, sizeof (vl.type_instance),
                        "%i", cpu_num);
 
        vl.values = values;
        vl.values_len = 2;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "df");
        strcpy (vl.plugin_instance, "");
        strncpy (vl.type_instance, df_name, sizeof (vl.type_instance));
 
        vl.values = values;
        vl.values_len = 2;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "disk");
        strncpy (vl.plugin_instance, plugin_instance,
                        sizeof (vl.plugin_instance));
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "dns");
        strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 
        vl.values = values;
        vl.values_len = 2;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "dns");
 
        plugin_dispatch_values ("dns_octets", &vl);
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "entropy");
        strcpy (vl.plugin_instance, "");
        strcpy (vl.type_instance, "");
 
   vl.values = values;
   vl.values_len = 1;
   vl.time = time (NULL);
-  strcpy (vl.host, hostname);
+  strcpy (vl.host, hostname_g);
   strcpy (vl.plugin, "exec");
   strcpy (vl.plugin_instance, "");
   strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
   vl.values = values;
   vl.values_len = 1;
   vl.time = time (NULL);
-  strcpy (vl.host, hostname);
+  strcpy (vl.host, hostname_g);
   strcpy (vl.plugin, "exec");
   strcpy (vl.plugin_instance, "");
   strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "hddtemp");
        strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "irq");
 
        status = snprintf (vl.type_instance, sizeof (vl.type_instance),
 
        vl.values = values;
        vl.values_len = 3;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "load");
        strcpy (vl.plugin_instance, "");
        strcpy (vl.type_instance, "");
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "mbmon");
        strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 
 
        vl.values = values;
        vl.values_len = 4;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "memory");
 
        plugin_dispatch_values ("memory", &vl);
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "multimeter");
 
        plugin_dispatch_values ("multimeter", &vl);
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "mysql");
        strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 
        vl.values = values;
        vl.values_len = 5;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "mysql");
 
        plugin_dispatch_values ("mysql_qcache", &vl);
        vl.values = values;
        vl.values_len = 4;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "mysql");
 
        plugin_dispatch_values ("mysql_threads", &vl);
        vl.values = values;
        vl.values_len = 2;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "mysql");
 
        plugin_dispatch_values ("mysql_octets", &vl);
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "nfs");
        strncpy (vl.plugin_instance, plugin_instance,
                        sizeof (vl.plugin_instance));
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "ntpd");
        strcpy (vl.plugin_instance, "");
        strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "ping");
        strcpy (vl.plugin_instance, "");
        strncpy (vl.type_instance, host, sizeof (vl.type_instance));
 
 
 static char *plugindir = NULL;
 
-char hostname[DATA_MAX_NAME_LEN] = "localhost";
-
 /*
  * Static functions
  */
        llentry_t *le;
        int status;
 
-       gethostname (hostname, sizeof (hostname));
-
        if (list_init == NULL)
                return;
 
 
        unsigned int delay;    /* how many more iterations we still need to wait */
 } complain_t;
 
-extern char hostname[DATA_MAX_NAME_LEN];
-
 /*
  * NAME
  *  plugin_set_dir
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "processes");
        strcpy (vl.plugin_instance, "");
        strncpy (vl.type_instance, state, sizeof (vl.type_instance));
        vl.values = values;
        vl.values_len = 2;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "processes");
        strncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance));
 
 
                return (-1);
        memset (rra_def, '\0', (rra_max + 1) * sizeof (char *));
 
-       step = atoi (COLLECTD_STEP);
+       step = interval_g;
+       /* FIXME: Use config here */
        rows = atoi (COLLECTD_ROWS);
 
        if ((step <= 0) || (rows <= 0))
        char **ds_def;
        int ds_num;
        int i, j;
+       char step[16];
        int status = 0;
 
        if (check_create_dir (filename))
                return (-1);
        }
 
+       status = snprintf (step, sizeof (step), "%i", interval_g);
+       if ((status < 1) || (status >= sizeof (step)))
+       {
+               syslog (LOG_ERR, "rrdtool plugin: snprintf failed.");
+               return (-1);
+       }
+
        argv[0] = "create";
        argv[1] = filename;
        argv[2] = "-s";
-       argv[3] = COLLECTD_STEP;
+       argv[3] = step;
 
        j = 4;
        for (i = 0; i < ds_num; i++)
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "sensors");
        strcpy (vl.plugin_instance, plugin_instance);
        strcpy (vl.type_instance, type_instance);
 
        vl.values = values;
        vl.values_len = 2;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "serial");
        strncpy (vl.type_instance, type_instance,
                        sizeof (vl.type_instance));
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "swap");
        strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 
 
        vl.values = values;
        vl.values_len = 2;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "tape");
        strncpy (vl.plugin_instance, plugin_instance,
                        sizeof (vl.plugin_instance));
 
        vl.values = values;
        vl.values_len = 2;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "interface");
        strncpy (vl.type_instance, dev, sizeof (vl.type_instance));
 
 
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "wireless");
        strncpy (vl.plugin_instance, plugin_instance,
                        sizeof (vl.plugin_instance));