summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2022-05-15 15:49:24 +0200
committerGitHub <noreply@github.com>2022-05-15 15:49:24 +0200
commit488b8acaeac450cce18f3ef3d081af697d481be9 (patch)
treea2cd001084d58ccf2b511081018ec8a6fd9295e7
parent hwdb: Add accel orientation for the I15-TG (diff)
parentresolve: merge variable declaration with same type (diff)
downloadsystemd-488b8acaeac450cce18f3ef3d081af697d481be9.tar.xz
systemd-488b8acaeac450cce18f3ef3d081af697d481be9.zip
Merge pull request #23382 from yuwata/resolve-fix-dnssd-assertion
resolve: fix dnssd assertion
-rw-r--r--src/resolve/resolved-bus.c9
-rw-r--r--src/resolve/resolved-dnssd.c22
-rw-r--r--src/resolve/resolved-dnssd.h2
3 files changed, 14 insertions, 19 deletions
diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c
index 4425a2f320..8207a04196 100644
--- a/src/resolve/resolved-bus.c
+++ b/src/resolve/resolved-bus.c
@@ -1899,13 +1899,10 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata,
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
_cleanup_(dnssd_service_freep) DnssdService *service = NULL;
_cleanup_(sd_bus_track_unrefp) sd_bus_track *bus_track = NULL;
+ const char *name, *name_template, *type;
_cleanup_free_ char *path = NULL;
- _cleanup_free_ char *instance_name = NULL;
- Manager *m = userdata;
DnssdService *s = NULL;
- const char *name;
- const char *name_template;
- const char *type;
+ Manager *m = userdata;
uid_t euid;
int r;
@@ -1953,7 +1950,7 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata,
if (!service->type)
return log_oom();
- r = dnssd_render_instance_name(service, &instance_name);
+ r = dnssd_render_instance_name(m, service, NULL);
if (r < 0)
return r;
diff --git a/src/resolve/resolved-dnssd.c b/src/resolve/resolved-dnssd.c
index 443760ab70..9c2594c1ba 100644
--- a/src/resolve/resolved-dnssd.c
+++ b/src/resolve/resolved-dnssd.c
@@ -136,14 +136,12 @@ static int dnssd_service_load(Manager *manager, const char *filename) {
}
static int specifier_dnssd_hostname(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
- DnssdService *s = (DnssdService *) userdata;
+ const Manager *m = ASSERT_PTR(userdata);
char *n;
- assert(s);
- assert(s->manager);
- assert(s->manager->llmnr_hostname);
+ assert(m->llmnr_hostname);
- n = strdup(s->manager->llmnr_hostname);
+ n = strdup(m->llmnr_hostname);
if (!n)
return -ENOMEM;
@@ -151,7 +149,7 @@ static int specifier_dnssd_hostname(char specifier, const void *data, const char
return 0;
}
-int dnssd_render_instance_name(DnssdService *s, char **ret_name) {
+int dnssd_render_instance_name(Manager *m, DnssdService *s, char **ret) {
static const Specifier specifier_table[] = {
{ 'a', specifier_architecture, NULL },
{ 'b', specifier_boot_id, NULL },
@@ -167,10 +165,11 @@ int dnssd_render_instance_name(DnssdService *s, char **ret_name) {
_cleanup_free_ char *name = NULL;
int r;
+ assert(m);
assert(s);
assert(s->name_template);
- r = specifier_printf(s->name_template, DNS_LABEL_MAX, specifier_table, NULL, s, &name);
+ r = specifier_printf(s->name_template, DNS_LABEL_MAX, specifier_table, NULL, m, &name);
if (r < 0)
return log_debug_errno(r, "Failed to replace specifiers: %m");
@@ -179,7 +178,8 @@ int dnssd_render_instance_name(DnssdService *s, char **ret_name) {
"Service instance name '%s' is invalid.",
name);
- *ret_name = TAKE_PTR(name);
+ if (ret)
+ *ret = TAKE_PTR(name);
return 0;
}
@@ -207,9 +207,7 @@ int dnssd_load(Manager *manager) {
}
int dnssd_update_rrs(DnssdService *s) {
- _cleanup_free_ char *n = NULL;
- _cleanup_free_ char *service_name = NULL;
- _cleanup_free_ char *full_name = NULL;
+ _cleanup_free_ char *n = NULL, *service_name = NULL, *full_name = NULL;
int r;
assert(s);
@@ -221,7 +219,7 @@ int dnssd_update_rrs(DnssdService *s) {
LIST_FOREACH(items, txt_data, s->txt_data_items)
txt_data->rr = dns_resource_record_unref(txt_data->rr);
- r = dnssd_render_instance_name(s, &n);
+ r = dnssd_render_instance_name(s->manager, s, &n);
if (r < 0)
return r;
diff --git a/src/resolve/resolved-dnssd.h b/src/resolve/resolved-dnssd.h
index d020bb531c..219c0ddfea 100644
--- a/src/resolve/resolved-dnssd.h
+++ b/src/resolve/resolved-dnssd.h
@@ -53,7 +53,7 @@ DnssdTxtData *dnssd_txtdata_free_all(DnssdTxtData *txt_data);
DEFINE_TRIVIAL_CLEANUP_FUNC(DnssdService*, dnssd_service_free);
DEFINE_TRIVIAL_CLEANUP_FUNC(DnssdTxtData*, dnssd_txtdata_free);
-int dnssd_render_instance_name(DnssdService *s, char **ret_name);
+int dnssd_render_instance_name(Manager *m, DnssdService *s, char **ret);
int dnssd_load(Manager *manager);
int dnssd_txt_item_new_from_string(const char *key, const char *value, DnsTxtItem **ret_item);
int dnssd_txt_item_new_from_data(const char *key, const void *value, const size_t size, DnsTxtItem **ret_item);