Bugfix: adding/removing use_xft in the config had no effect unless you restarted...
[monky] / src / conky.c
index bd592f3..7a2adad 100644 (file)
@@ -10,7 +10,7 @@
  * Please see COPYING for details
  *
  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
  *     (see AUTHORS)
  * All rights reserved.
  *
@@ -147,6 +147,9 @@ char *get_apm_battery_time(void);
 /* debugging level, used by logging.h */
 int global_debug_level = 0;
 
+/* disable inotify auto reload feature if desired */
+int disable_auto_reload = 0;
+
 /* two strings for internal use */
 static char *tmpstring1, *tmpstring2;
 
@@ -203,6 +206,9 @@ static void print_version(void)
 # ifdef XFT
                   "  * Xft\n"
 # endif /* XFT */
+# ifdef USE_ARGB
+                  "  * ARGB visual\n"
+# endif /* USE_ARGB */
 #endif /* X11 */
                   "\n Music detection:\n"
 #ifdef AUDACIOUS
@@ -314,7 +320,8 @@ static int text_width, text_height;
 
 /* alignments */
 enum alignment {
-       TOP_LEFT = 1,
+       ALIGNMENT_ERROR,
+       TOP_LEFT,
        TOP_RIGHT,
        TOP_MIDDLE,
        BOTTOM_LEFT,
@@ -347,6 +354,10 @@ static unsigned long total_run_times;
 /* fork? */
 static int fork_to_background;
 
+/* set to 0 after the first time conky is run, so we don't fork again after the
+ * first forking */
+static int first_pass = 1;
+
 static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
 
 /* filenames for output */
@@ -452,14 +463,14 @@ int check_contains(char *f, char *s)
                }
                fclose(where);
        } else {
-               NORM_ERR("Could not open the file");
+               NORM_ERR("Could not open the file '%s'", f);
        }
        return ret;
 }
 
 #define SECRIT_MULTILINE_CHAR '\x02'
 
-static inline int calc_text_width(const char *s)
+int calc_text_width(const char *s)
 {
        size_t slen = strlen(s);
 
@@ -859,7 +870,7 @@ void generate_text_internal(char *p, int p_max_size,
                                get_acpi_fan(p, p_max_size);
                        }
                        OBJ(acpiacadapter) {
-                               get_acpi_ac_adapter(p, p_max_size);
+                               get_acpi_ac_adapter(p, p_max_size, (const char *)obj->data.opaque);
                        }
                        OBJ(battery) {
                                get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
@@ -888,13 +899,15 @@ void generate_text_internal(char *p, int p_max_size,
                                print_cmdline_to_pid(obj, p, p_max_size);
                        }
                        OBJ(cpu) {
-                               if (obj->data.i > info.cpu_count) {
-                                       NORM_ERR("obj->data.i %i info.cpu_count %i",
-                                                       obj->data.i, info.cpu_count);
-                                       CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!");
-                               }
-                               percent_print(p, p_max_size,
+                               if (cur->cpu_usage) {
+                                       if (obj->data.i > info.cpu_count) {
+                                               NORM_ERR("obj->data.i %i info.cpu_count %i",
+                                                               obj->data.i, info.cpu_count);
+                                               CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!");
+                                       }
+                                   percent_print(p, p_max_size,
                                              round_to_int(cur->cpu_usage[obj->data.i] * 100.0));
+                               }
                        }
                        OBJ(cpugauge)
                                new_gauge(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
@@ -1060,10 +1073,10 @@ void generate_text_internal(char *p, int p_max_size,
                                print_diskiograph(obj, p, p_max_size);
                        }
                        OBJ(diskiograph_read) {
-                               print_diskiograph(obj, p, p_max_size);
+                               print_diskiograph_read(obj, p, p_max_size);
                        }
                        OBJ(diskiograph_write) {
-                               print_diskiograph(obj, p, p_max_size);
+                               print_diskiograph_write(obj, p, p_max_size);
                        }
 #endif /* X11 */
                        OBJ(downspeed) {
@@ -1317,7 +1330,7 @@ void generate_text_internal(char *p, int p_max_size,
                                        DO_JUMP;
                                } else if (spc) {
                                        *spc = '\0';
-                                       if (check_contains(obj->data.s, spc + 1))
+                                       if (!check_contains(obj->data.s, spc + 1))
                                                DO_JUMP;
                                        *spc = ' ';
                                }
@@ -2391,7 +2404,7 @@ void evaluate(const char *text, char *p, int p_max_size)
        tmp_info = malloc(sizeof(struct information));
        memcpy(tmp_info, &info, sizeof(struct information));
        parse_conky_vars(&subroot, text, p, p_max_size, tmp_info);
-       DBGP("evaluated '%s' to '%s'", text, p);
+       DBGP2("evaluated '%s' to '%s'", text, p);
 
        free_text_objects(&subroot, 1);
        free(tmp_info);
@@ -2463,7 +2476,7 @@ void set_update_interval(double interval)
        update_interval_old = interval;
 }
 
-static inline int get_string_width(const char *s)
+int get_string_width(const char *s)
 {
        return *s ? calc_text_width(s) : 0;
 }
@@ -2616,6 +2629,8 @@ static long current_color;
 static int text_size_updater(char *s, int special_index)
 {
        int w = 0;
+       int lw;
+       int contain_SECRIT_MULTILINE_CHAR = 0;
        char *p;
 
        if ((output_methods & TO_X) == 0)
@@ -2664,7 +2679,7 @@ static int text_size_updater(char *s, int special_index)
                        special_index++;
                        s = p + 1;
                } else if (*p == SECRIT_MULTILINE_CHAR) {
-                       int lw;
+                       contain_SECRIT_MULTILINE_CHAR = 1;
                        *p = '\0';
                        lw = get_string_width(s);
                        *p = SECRIT_MULTILINE_CHAR;
@@ -2674,7 +2689,13 @@ static int text_size_updater(char *s, int special_index)
                }
                p++;
        }
-       w += get_string_width(s);
+       /* Check also last substring if string contains SECRIT_MULTILINE_CHAR */
+       if (contain_SECRIT_MULTILINE_CHAR) {
+               lw = get_string_width(s);
+               w = lw > w ? lw : w;
+       } else {
+               w += get_string_width(s);
+       }
        if (w > text_width) {
                text_width = w;
        }
@@ -2692,8 +2713,16 @@ static inline void set_foreground_color(long c)
 {
 #ifdef X11
        if (output_methods & TO_X) {
-               current_color = c;
-               XSetForeground(display, window.gc, c);
+#ifdef USE_ARGB
+               if (have_argb_visual) {
+                       current_color = c | (own_window_argb_value << 24);
+               } else {
+#endif /* USE_ARGB */
+                       current_color = c;
+#ifdef USE_ARGB
+               }
+#endif /* USE_ARGB */
+               XSetForeground(display, window.gc, current_color);
        }
 #endif /* X11 */
 #ifdef NCURSES
@@ -2794,7 +2823,8 @@ static void draw_string(const char *s)
                        XftColor c2;
 
                        c.pixel = current_color;
-                       XQueryColor(display, DefaultColormap(display, screen), &c);
+                       // query color on custom colormap
+                       XQueryColor(display, window.colourmap, &c);
 
                        c2.pixel = c.pixel;
                        c2.color.red = c.red;
@@ -3089,36 +3119,49 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
                                                if (seconds != 0) {
                                                        timeunits = seconds / 86400; seconds %= 86400;
                                                        if (timeunits > 0) {
-                                                               asprintf(&tmp_day_str, "%dd", timeunits);
+                                                               if (asprintf(&tmp_day_str, "%dd", timeunits) < 0) {
+                                                                       tmp_day_str = 0;
+                                                               }
                                                        } else {
                                                                tmp_day_str = strdup("");
                                                        }
                                                        timeunits = seconds / 3600; seconds %= 3600;
                                                        if (timeunits > 0) {
-                                                               asprintf(&tmp_hour_str, "%dh", timeunits);
+                                                               if (asprintf(&tmp_hour_str, "%dh", timeunits) < 0) {
+                                                                       tmp_day_str = 0;
+                                                               }
                                                        } else {
                                                                tmp_hour_str = strdup("");
                                                        }
                                                        timeunits = seconds / 60; seconds %= 60;
                                                        if (timeunits > 0) {
-                                                               asprintf(&tmp_min_str, "%dm", timeunits);
+                                                               if (asprintf(&tmp_min_str, "%dm", timeunits) < 0) {
+                                                                       tmp_min_str = 0;
+                                                               }
                                                        } else {
                                                                tmp_min_str = strdup("");
                                                        }
                                                        if (seconds > 0) {
-                                                               asprintf(&tmp_sec_str, "%ds", seconds);
+                                                               if (asprintf(&tmp_sec_str, "%ds", seconds) < 0) {
+                                                                       tmp_sec_str = 0;
+                                                               }
                                                        } else {
                                                                tmp_sec_str = strdup("");
                                                        }
-                                                       asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
-                                                       free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
+                                                       if (asprintf(&tmp_str, "%s%s%s%s", tmp_day_str,
+                                                                               tmp_hour_str, tmp_min_str, tmp_sec_str) < 0) {
+                                                               tmp_str = 0;
+                                                       }
+#define FREE(a) if ((a)) free((a));
+                                                       FREE(tmp_day_str); FREE(tmp_hour_str); FREE(tmp_min_str); FREE(tmp_sec_str);
                                                } else {
-                                                       asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry
+                                                       tmp_str = strdup("Range not possible"); /* should never happen, but better safe then sorry */
                                                }
                                                cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
                                                cur_y += font_h / 2;
                                                draw_string(tmp_str);
-                                               free(tmp_str);
+                                               FREE(tmp_str);
+#undef FREE
                                                cur_x = tmp_x;
                                                cur_y = tmp_y;
                                        }
@@ -3555,7 +3598,7 @@ static void main_loop(void)
                                                draw_stuff(); /* redraw everything in our newly sized window */
                                                XResizeWindow(display, window.window, window.width,
                                                                window.height); /* resize window */
-                                               set_transparent_background(window.window);
+                                               set_transparent_background(window.window, own_window_argb_value);
 #ifdef HAVE_XDBE
                                                /* swap buffers */
                                                xdbe_swap_buffers();
@@ -3655,9 +3698,9 @@ static void main_loop(void)
 
 #ifdef OWN_WINDOW
                                        case ReparentNotify:
-                                               /* set background to ParentRelative for all parents */
+                                               /* make background transparent */
                                                if (own_window) {
-                                                       set_transparent_background(window.window);
+                                                       set_transparent_background(window.window, own_window_argb_value);
                                                }
                                                break;
 
@@ -3864,12 +3907,12 @@ static void main_loop(void)
                                break;
                }
 #ifdef HAVE_SYS_INOTIFY_H
-               if (inotify_fd != -1 && inotify_config_wd == -1 && current_config != 0) {
+               if (!disable_auto_reload && inotify_fd != -1 && inotify_config_wd == -1 && current_config != 0) {
                        inotify_config_wd = inotify_add_watch(inotify_fd,
                                        current_config,
                                        IN_MODIFY);
                }
-               if (inotify_fd != -1 && inotify_config_wd != -1 && current_config != 0) {
+               if (!disable_auto_reload && inotify_fd != -1 && inotify_config_wd != -1 && current_config != 0) {
                        int len = 0, idx = 0;
                        fd_set descriptors;
                        struct timeval time_to_wait;
@@ -3896,6 +3939,7 @@ static void main_loop(void)
                                                                        current_config,
                                                                        IN_MODIFY);
                                                }
+                                               break;
                                        }
 #ifdef HAVE_LUA
                                        else {
@@ -3905,6 +3949,10 @@ static void main_loop(void)
                                        idx += INOTIFY_EVENT_SIZE + ev->len;
                                }
                        }
+               } else if (disable_auto_reload && inotify_fd != -1) {
+                       inotify_rm_watch(inotify_fd, inotify_config_wd);
+                       close(inotify_fd);
+                       inotify_fd = inotify_config_wd = 0;
                }
 #endif /* HAVE_SYS_INOTIFY_H */
 
@@ -3913,7 +3961,7 @@ static void main_loop(void)
 #endif /* HAVE_LUA */
                g_signal_pending = 0;
        }
-       clean_up(NULL, NULL);
+       clean_up(current_mail_spool, NULL);
 
 #ifdef HAVE_SYS_INOTIFY_H
        if (inotify_fd != -1) {
@@ -3934,6 +3982,7 @@ static void reload_config(void)
 {
        char *current_config_copy = strdup(current_config);
        clean_up(NULL, NULL);
+       sleep(1); /* slight pause */
        current_config = current_config_copy;
        initialisation(argc_copy, argv_copy);
 }
@@ -3942,6 +3991,8 @@ void clean_up(void *memtofree1, void* memtofree2)
 {
        int i;
 
+       free_update_callbacks();
+
 #ifdef NCURSES
        if(output_methods & TO_NCURSES) {
                endwin();
@@ -3993,8 +4044,6 @@ void clean_up(void *memtofree1, void* memtofree2)
 
 #endif /* X11 */
 
-       free_update_callbacks();
-
        free_templates();
 
        free_text_objects(&global_root_object, 0);
@@ -4118,7 +4167,7 @@ static enum alignment string_to_alignment(const char *s)
        } else if (strcasecmp(s, "none") == EQUAL) {
                return NONE;
        }
-       return TOP_LEFT;
+       return ALIGNMENT_ERROR;
 }
 #endif /* X11 */
 
@@ -4216,6 +4265,9 @@ static void set_default_configurations(void)
        output_methods = TO_STDOUT;
 #endif
 #ifdef X11
+#ifdef BUILD_XFT
+       use_xft = 0;
+#endif
        show_graph_scale = 0;
        show_graph_range = 0;
        draw_shades = 1;
@@ -4234,6 +4286,10 @@ static void set_default_configurations(void)
        window.hints = 0;
        strcpy(window.class_name, PACKAGE_NAME);
        sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
+#ifdef USE_ARGB
+       use_argb_visual = 0;
+       own_window_argb_value = 255;
+#endif
 #endif
        stippled_borders = 0;
        window.border_inner_margin = 3;
@@ -4242,11 +4298,11 @@ static void set_default_configurations(void)
        text_alignment = BOTTOM_LEFT;
        info.x11.monitor.number = 1;
        info.x11.monitor.current = 0;
-       info.x11.desktop.current = 1; 
+       info.x11.desktop.current = 1;
        info.x11.desktop.number = 1;
        info.x11.desktop.nitems = 0;
-       info.x11.desktop.all_names = NULL; 
-       info.x11.desktop.name = NULL; 
+       info.x11.desktop.all_names = NULL;
+       info.x11.desktop.name = NULL;
 #endif /* X11 */
 
        free_templates();
@@ -4369,7 +4425,7 @@ static void X11_create_window(void)
                        XMoveWindow(display, window.window, window.x, window.y);
                }
                if (own_window) {
-                       set_transparent_background(window.window);
+                       set_transparent_background(window.window, own_window_argb_value);
                }
 #endif
 
@@ -4467,6 +4523,29 @@ static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **va
        return 0;
 }
 
+#ifdef X11
+void setalignment(int* ltext_alignment, unsigned int windowtype, const char* value, const char *f, int line, char setbyconffile) {
+#ifdef OWN_WINDOW
+       if (windowtype == TYPE_DOCK) {
+               NORM_ERR("alignment is disabled when own_window_type is dock");
+       } else
+#endif /*OWN_WINDOW */
+       if (value) {
+               int a = string_to_alignment(value);
+
+               if (a <= 0) {
+                       if (setbyconffile) {
+                               CONF_ERR;
+                       } else NORM_ERR("'%s' is not a alignment setting", value);
+               } else {
+                       *ltext_alignment = a;
+               }
+       } else if (setbyconffile) {
+               CONF_ERR;
+       }
+}
+#endif /* X11 */
+
 char load_config_file(const char *f)
 {
        int line = 0;
@@ -4510,22 +4589,7 @@ char load_config_file(const char *f)
                        }
                }
                CONF("alignment") {
-#ifdef OWN_WINDOW
-                       if (window.type == TYPE_DOCK)
-                               ;
-                       else
-#endif /*OWN_WINDOW */
-                       if (value) {
-                               int a = string_to_alignment(value);
-
-                               if (a <= 0) {
-                                       CONF_ERR;
-                               } else {
-                                       text_alignment = a;
-                               }
-                       } else {
-                               CONF_ERR;
-                       }
+                       setalignment(&text_alignment, window.type, value, f, line, 1);
                }
                CONF("background") {
                        fork_to_background = string_to_bool(value);
@@ -4561,7 +4625,7 @@ char load_config_file(const char *f)
                CONF("border_width") {
                        if (value) {
                                window.border_width = strtol(value, 0, 0);
-                               if (window.border_width < 0) window.border_width = 0;
+                               if (window.border_width < 1) window.border_width = 1;
                        } else {
                                CONF_ERR;
                        }
@@ -4749,6 +4813,9 @@ char load_config_file(const char *f)
                CONF("extra_newline") {
                        extra_newline = string_to_bool(value);
                }
+               CONF("disable_auto_reload") {
+                       disable_auto_reload = string_to_bool(value);
+               }
                CONF("out_to_stderr") {
                        if(string_to_bool(value))
                                output_methods |= TO_STDERR;
@@ -5006,6 +5073,17 @@ char load_config_file(const char *f)
                                CONF_ERR;
                        }
                }
+#ifdef USE_ARGB
+               CONF("own_window_argb_visual") {
+                       use_argb_visual = string_to_bool(value);
+               }
+               CONF("own_window_argb_value") {
+                       own_window_argb_value = strtol(value, 0, 0);
+                       if (own_window_argb_value > 255 || own_window_argb_value < 0) {
+                               CONF_ERR2("own_window_argb_value must be <= 255 and >= 0");
+                       }
+               }
+#endif /* USE_ARGB */
 #endif
                CONF("stippled_borders") {
                        if (value) {
@@ -5500,6 +5578,7 @@ static const char *getopt_string = "vVqdDt:u:i:hc:p:"
 static const struct option longopts[] = {
        { "help", 0, NULL, 'h' },
        { "version", 0, NULL, 'V' },
+       { "quiet", 0, NULL, 'q' },
        { "debug", 0, NULL, 'D' },
        { "config", 1, NULL, 'c' },
 #ifdef CONFIG_OUTPUT
@@ -5519,15 +5598,64 @@ static const struct option longopts[] = {
        { "window-id", 1, NULL, 'w' },
 #endif /* X11 */
        { "text", 1, NULL, 't' },
-       { "interval", 0, NULL, 'u' },
-       { "pause", 0, NULL, 'p' },
+       { "interval", 1, NULL, 'u' },
+       { "pause", 1, NULL, 'p' },
        { 0, 0, 0, 0 }
 };
 
+void set_current_config(void);
+void set_current_config(void)
+{
+       /* check if specified config file is valid */
+       if (current_config) {
+               struct stat sb;
+               if (stat(current_config, &sb) ||
+                               (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
+                       NORM_ERR("invalid configuration file '%s'\n", current_config);
+                       free(current_config);
+                       current_config = 0;
+               }
+       }
+
+       /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
+
+       if (!current_config) {
+               /* load default config file */
+               char buf[DEFAULT_TEXT_BUFFER_SIZE];
+               FILE *fp;
+
+               /* Try to use personal config file first */
+               to_real_path(buf, CONFIG_FILE);
+               if (buf[0] && (fp = fopen(buf, "r"))) {
+                       current_config = strndup(buf, max_user_text);
+                       fclose(fp);
+               }
+
+               /* Try to use system config file if personal config not readable */
+               if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
+                       current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
+                       fclose(fp);
+               }
+
+               /* No readable config found */
+               if (!current_config) {
+#define NOCFGFILEFOUND "no readable personal or system-wide config file found"
+#ifdef BUILD_BUILTIN_CONFIG
+                       current_config = strdup("==builtin==");
+                       NORM_ERR(NOCFGFILEFOUND
+                                       ", using builtin default");
+#else
+                       CRIT_ERR(NULL, NULL, NOCFGFILEFOUND);
+#endif /* ! CONF_OUTPUT */
+               }
+       }
+}
+
 void initialisation(int argc, char **argv) {
        struct sigaction act, oact;
 
        set_default_configurations();
+       set_current_config();
        load_config_file(current_config);
        currentconffile = conftree_add(currentconffile, current_config);
 
@@ -5584,7 +5712,7 @@ void initialisation(int argc, char **argv) {
                                set_first_font(optarg);
                                break;
                        case 'a':
-                               text_alignment = string_to_alignment(optarg);
+                               setalignment(&text_alignment, window.type, optarg, NULL, 0, 0);
                                break;
 
 #ifdef OWN_WINDOW
@@ -5629,8 +5757,10 @@ void initialisation(int argc, char **argv) {
                                break;
 #endif /* X11 */
                        case 'p':
-                               startup_pause = atoi(optarg);
-                               sleep(startup_pause);
+                               if (first_pass) {
+                                       startup_pause = atoi(optarg);
+                                       sleep(startup_pause);
+                               }
                                break;
 
                        case '?':
@@ -5653,7 +5783,7 @@ void initialisation(int argc, char **argv) {
        }
        global_text = NULL;
        /* fork */
-       if (fork_to_background) {
+       if (fork_to_background && first_pass) {
                int pid = fork();
 
                switch (pid) {
@@ -5781,7 +5911,9 @@ int main(int argc, char **argv)
                                current_config = strndup(optarg, max_user_text);
                                break;
                        case 'q':
-                               freopen("/dev/null", "w", stderr);
+                               if (!freopen("/dev/null", "w", stderr)) {
+                                       NORM_ERR("unable to redirect stderr to /dev/null");
+                               }
                                break;
                        case 'h':
                                print_help(argv[0]);
@@ -5807,48 +5939,7 @@ int main(int argc, char **argv)
                }
        }
 
-       /* check if specified config file is valid */
-       if (current_config) {
-               struct stat sb;
-               if (stat(current_config, &sb) ||
-                               (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
-                       NORM_ERR("invalid configuration file '%s'\n", current_config);
-                       free(current_config);
-                       current_config = 0;
-               }
-       }
-
-       /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
-
-       if (!current_config) {
-               /* load default config file */
-               char buf[DEFAULT_TEXT_BUFFER_SIZE];
-               FILE *fp;
-
-               /* Try to use personal config file first */
-               to_real_path(buf, CONFIG_FILE);
-               if (buf[0] && (fp = fopen(buf, "r"))) {
-                       current_config = strndup(buf, max_user_text);
-                       fclose(fp);
-               }
-
-               /* Try to use system config file if personal config not readable */
-               if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
-                       current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
-                       fclose(fp);
-               }
-
-               /* No readable config found */
-               if (!current_config) {
-#ifdef CONFIG_OUTPUT
-                       current_config = strdup("==builtin==");
-                       NORM_ERR("no readable personal or system-wide config file found,"
-                                       " using builtin default");
-#else
-                       CRIT_ERR(NULL, NULL, "no readable personal or system-wide config file found");
-#endif /* ! CONF_OUTPUT */
-               }
-       }
+       set_current_config();
 
 #ifdef XOAP
        /* Load xoap keys, if existing */
@@ -5856,11 +5947,19 @@ int main(int argc, char **argv)
 #endif /* XOAP */
 
 #ifdef HAVE_SYS_INOTIFY_H
-       inotify_fd = inotify_init1(IN_NONBLOCK);
+       inotify_fd = inotify_init();
+       if(inotify_fd != -1) {
+               int fl;
+
+               fl = fcntl(inotify_fd, F_GETFL);
+               fcntl(inotify_fd, F_SETFL, fl | O_NONBLOCK);
+       }
 #endif /* HAVE_SYS_INOTIFY_H */
 
        initialisation(argc, argv);
 
+       first_pass = 0; /* don't ever call fork() again */
+
        main_loop();
 
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)