isc_nm_t* netmgr;
} ctx_t;
-static void logger(ctx_t* ctx, int priority, const char* format, ...) {
+// Create the context
+static ctx_t ctx = {
+ .path = DEFAULT_PATH,
+};
+
+static void logger(int priority, const char* format, ...) {
char buffer[4096];
FILE* f = NULL;
ssize_t length;
va_list args;
// Don't log if below log level
- if (priority > ctx->log_level)
+ if (priority > ctx.log_level)
return;
// Format the log message
}
static void run_loop(void* data) {
- ctx_t* ctx = data;
-
- DEBUG(ctx, "Event loop started\n");
+ DEBUG("Event loop started\n");
// Process all zones
- for (unsigned int i = 0; i < ctx->num_zones; i++) {
- do_zone(ctx, ctx->zones[i]);
+ for (unsigned int i = 0; i < ctx.num_zones; i++) {
+ do_zone(ctx.zones[i]);
}
}
};
static error_t parse(int key, char* arg, struct argp_state* state) {
- ctx_t* ctx = state->input;
const char** zones = NULL;
switch (key) {
case OPT_DEBUG:
- ctx->log_level = LOG_DEBUG;
+ ctx.log_level = LOG_DEBUG;
break;
case OPT_PATH:
- ctx->path = arg;
+ ctx.path = arg;
break;
case ARGP_KEY_ARG:
- zones = reallocarray(ctx->zones, ctx->num_zones + 1, sizeof(*ctx->zones));
+ zones = reallocarray(ctx.zones, ctx.num_zones + 1, sizeof(*ctx.zones));
if (!zones) {
argp_failure(state, EXIT_FAILURE, 0, "%m");
return ARGP_ERR_UNKNOWN;
}
// Store the pointer to the argument
- zones[ctx->num_zones++] = arg;
+ zones[ctx.num_zones++] = arg;
- ctx->zones = zones;
+ ctx.zones = zones;
break;
case ARGP_KEY_SUCCESS:
// Fail if we don't have any zones
- if (!ctx->zones) {
+ if (!ctx.zones) {
argp_failure(state, EXIT_FAILURE, 0, "You must pass a zone");
}
break;
int main(int argc, char* argv[]) {
int r;
- // Create the context
- ctx_t ctx = {
- .path = DEFAULT_PATH,
- };
-
// Setup the command line parser
struct argp parser = {
.options = options,
int arg_index = 0;
// Parse the command line
- r = argp_parse(&parser, argc, argv, ARGP_IN_ORDER, &arg_index, &ctx);
+ r = argp_parse(&parser, argc, argv, ARGP_IN_ORDER, &arg_index, NULL);
if (r)
return r;