+/* Add tuple */
+static void load_watchdog_uci_add_process(const char *section, struct uci_process_itr_ctx *itr)
+{
+ process_tuple_t *t;
+ const char *ucitmp;
+ int val = 0;
+
+ if( (t = (process_tuple_t *)malloc(sizeof(process_tuple_t))) != NULL )
+ {
+ t->restart = 0;
+
+ ucitmp = ucix_get_option(itr->ctx, "freifunk-watchdog", section, "process");
+ if(ucitmp)
+ {
+ strncpy(t->process, ucitmp, sizeof(t->process));
+ val++;
+ }
+
+ ucitmp = ucix_get_option(itr->ctx, "freifunk-watchdog", section, "initscript");
+ if(ucitmp)
+ {
+ strncpy(t->initscript, ucitmp, sizeof(t->initscript));
+ val++;
+ }
+
+ if( val == 2 )
+ {
+ syslog(LOG_INFO, "Monitoring %s: initscript=%s",
+ t->process, t->initscript);
+
+ t->next = itr->list;
+ itr->list = t;
+ }
+ else
+ {
+ free(t);
+ }
+ }
+}
+
+/* Load config */
+static process_tuple_t * load_watchdog_uci(process_tuple_t *procs)
+{
+ struct uci_context *ctx;
+ struct uci_process_itr_ctx itr;
+ process_tuple_t *cur, *next;
+
+ syslog(LOG_INFO, "Loading watchdog config");
+
+ if( (ctx = ucix_init("freifunk-watchdog")) != NULL )
+ {
+ if( procs != NULL )
+ {
+ for(cur = procs; cur; cur = next)
+ {
+ next = cur->next;
+ free(cur);
+ }
+ }
+
+ itr.list = NULL;
+ itr.ctx = ctx;
+
+ ucix_for_each_section_type(ctx, "freifunk-watchdog", "process",
+ (void *)load_watchdog_uci_add_process, &itr);
+
+ return itr.list;
+ }
+
+ return procs;
+}
+