dnsmasq: generate the dns object name dynamically
Fixes an issue with running multiple dnsmasq instances Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
		| @@ -162,7 +162,7 @@ | ||||
|        ttl = find_soa(header, qlen, doctored); | ||||
| --- a/src/ubus.c | ||||
| +++ b/src/ubus.c | ||||
| @@ -72,6 +72,14 @@ static struct ubus_object ubus_object = | ||||
| @@ -72,6 +72,13 @@ static struct ubus_object ubus_object = | ||||
|    .subscribe_cb = ubus_subscribe_cb, | ||||
|  }; | ||||
|   | ||||
| @@ -170,23 +170,35 @@ | ||||
| +   { .name = "dnsmasq.dns" }; | ||||
| + | ||||
| +static struct ubus_object ubus_dns_object = { | ||||
| +	.name = "dnsmasq.dns", | ||||
| +	.type = &ubus_dns_object_type, | ||||
| +}; | ||||
| + | ||||
|  static void ubus_subscribe_cb(struct ubus_context *ctx, struct ubus_object *obj) | ||||
|  { | ||||
|    (void)ctx; | ||||
| @@ -112,6 +120,8 @@ char *ubus_init() | ||||
| @@ -105,13 +112,21 @@ static void ubus_disconnect_cb(struct ub | ||||
|  char *ubus_init() | ||||
|  { | ||||
|    struct ubus_context *ubus = NULL; | ||||
| +  char *dns_name; | ||||
|    int ret = 0; | ||||
|   | ||||
|    if (!(ubus = ubus_connect(NULL))) | ||||
|      return NULL; | ||||
|     | ||||
| +  dns_name = whine_malloc(strlen(daemon->ubus_name) + 5); | ||||
| +  sprintf(dns_name, "%s.dns", daemon->ubus_name); | ||||
| + | ||||
|    ubus_object.name = daemon->ubus_name; | ||||
| +  ubus_dns_object.name = dns_name; | ||||
| + | ||||
|    ret = ubus_add_object(ubus, &ubus_object); | ||||
| +  if (!ret) | ||||
| +    ret = ubus_add_object(ubus, &ubus_dns_object); | ||||
|    if (ret) | ||||
|      { | ||||
|        ubus_destroy(ubus); | ||||
| @@ -181,6 +191,17 @@ void check_ubus_listeners() | ||||
| @@ -181,6 +196,17 @@ void check_ubus_listeners() | ||||
|        } \ | ||||
|    } while (0) | ||||
|   | ||||
| @@ -204,7 +216,7 @@ | ||||
|  static int ubus_handle_metrics(struct ubus_context *ctx, struct ubus_object *obj, | ||||
|  			       struct ubus_request_data *req, const char *method, | ||||
|  			       struct blob_attr *msg) | ||||
| @@ -328,6 +349,50 @@ fail: | ||||
| @@ -328,6 +354,50 @@ fail: | ||||
|        } \ | ||||
|    } while (0) | ||||
|   | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Felix Fietkau
					Felix Fietkau