make range allocation dynamic
[debian/dhcpd-pools.git] / src / getdata.c
index 7fbe4d0..1334855 100644 (file)
@@ -163,6 +163,7 @@ int parse_leases(void)
        if (macaddr != NULL) {
                free(macstring);
        }
+       fclose(dhcpd_leases);
        return 0;
 }
 
@@ -385,9 +386,14 @@ char *parse_config(int is_include, char *config_file,
                                range_p->backups = 0;
                                range_p->shared_net = shared_p;
                                num_ranges++;
-                               if (RANGES < num_ranges) {
-                                       errx(EXIT_FAILURE,
-                                            "parse_config: Range space full! Increase RANGES and recompile.");
+                               if (RANGES < num_ranges + 1) {
+                                       RANGES *= 2;
+                                       ranges =
+                                           safe_realloc(ranges,
+                                                        sizeof(struct
+                                                               range_t) *
+                                                        RANGES);
+                                       range_p = ranges + num_ranges;
                                }
                                newclause = true;
                                break;
@@ -426,7 +432,15 @@ char *parse_config(int is_include, char *config_file,
                                         * away by reallocationg
                                         * more space. */
                                        errx(EXIT_FAILURE,
-                                            "parse_config: End of shared-network space, increase SHARED_NETWORKS_NAMES and recompile");
+                                            "parse_config: increase default.h SHARED_NETWORKS_NAMES and recompile");
+                               }
+                               if (SHARED_NETWORKS <
+                                   num_shared_networks + 2) {
+                                       /* FIXME: make this
+                                        * away by reallocationg
+                                        * more space. */
+                                       errx(EXIT_FAILURE,
+                                            "parse_config: increase default.h SHARED_NETWORKS and recompile");
                                }
                                argument = 0;
                                braces_shared = braces;
@@ -452,5 +466,6 @@ char *parse_config(int is_include, char *config_file,
                }
        }
        free(word);
+       fclose(dhcpd_config);
        return next_free_shared_name;
 }