mirror of
https://github.com/systemd/systemd.git
synced 2025-01-10 05:18:17 +03:00
resolved: rename DnssdService "name" field to "id"
"name" is a bit confusing since this field is *not* the DNS-SD service identifier, bust just some string derived from the .dnssd filename that is used as handle for the service. Let's hence give it a better name: "id". While we are at it, switch from basename() to path_extract_filename().
This commit is contained in:
parent
407630164e
commit
0ef0e2691a
@ -1866,7 +1866,7 @@ 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;
|
||||
const char *id, *name_template, *type;
|
||||
_cleanup_free_ char *path = NULL;
|
||||
DnssdService *s = NULL;
|
||||
Manager *m = ASSERT_PTR(userdata);
|
||||
@ -1892,21 +1892,21 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata,
|
||||
service->originator = euid;
|
||||
service->config_source = RESOLVE_CONFIG_SOURCE_DBUS;
|
||||
|
||||
r = sd_bus_message_read(message, "sssqqq", &name, &name_template, &type,
|
||||
r = sd_bus_message_read(message, "sssqqq", &id, &name_template, &type,
|
||||
&service->port, &service->priority,
|
||||
&service->weight);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
s = hashmap_get(m->dnssd_services, name);
|
||||
s = hashmap_get(m->dnssd_services, id);
|
||||
if (s)
|
||||
return sd_bus_error_setf(error, BUS_ERROR_DNSSD_SERVICE_EXISTS, "DNS-SD service '%s' exists already", name);
|
||||
return sd_bus_error_setf(error, BUS_ERROR_DNSSD_SERVICE_EXISTS, "DNS-SD service '%s' exists already", id);
|
||||
|
||||
if (!dnssd_srv_type_is_valid(type))
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "DNS-SD service type '%s' is invalid", type);
|
||||
|
||||
service->name = strdup(name);
|
||||
if (!service->name)
|
||||
service->id = strdup(id);
|
||||
if (!service->id)
|
||||
return log_oom();
|
||||
|
||||
service->name_template = strdup(name_template);
|
||||
@ -1999,7 +1999,7 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata,
|
||||
txt_data = NULL;
|
||||
}
|
||||
|
||||
r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", service->name, &path);
|
||||
r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", service->id, &path);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -2014,7 +2014,7 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata,
|
||||
if (r == 0)
|
||||
return 1; /* Polkit will call us back */
|
||||
|
||||
r = hashmap_ensure_put(&m->dnssd_services, &string_hash_ops, service->name, service);
|
||||
r = hashmap_ensure_put(&m->dnssd_services, &string_hash_ops, service->id, service);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -2178,7 +2178,7 @@ static const sd_bus_vtable resolve_vtable[] = {
|
||||
bus_method_revert_link,
|
||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD_WITH_ARGS("RegisterService",
|
||||
SD_BUS_ARGS("s", name,
|
||||
SD_BUS_ARGS("s", id,
|
||||
"s", name_template,
|
||||
"s", type,
|
||||
"q", service_port,
|
||||
|
@ -107,7 +107,7 @@ static int dnssd_node_enumerator(sd_bus *bus, const char *path, void *userdata,
|
||||
HASHMAP_FOREACH(service, m->dnssd_services) {
|
||||
char *p;
|
||||
|
||||
r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", service->name, &p);
|
||||
r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", service->id, &p);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -3,10 +3,11 @@
|
||||
#include "conf-files.h"
|
||||
#include "conf-parser.h"
|
||||
#include "constants.h"
|
||||
#include "resolved-dnssd.h"
|
||||
#include "resolved-dns-rr.h"
|
||||
#include "resolved-manager.h"
|
||||
#include "path-util.h"
|
||||
#include "resolved-conf.h"
|
||||
#include "resolved-dns-rr.h"
|
||||
#include "resolved-dnssd.h"
|
||||
#include "resolved-manager.h"
|
||||
#include "specifier.h"
|
||||
#include "strv.h"
|
||||
|
||||
@ -40,7 +41,7 @@ DnssdService *dnssd_service_free(DnssdService *service) {
|
||||
return NULL;
|
||||
|
||||
if (service->manager)
|
||||
hashmap_remove(service->manager->dnssd_services, service->name);
|
||||
hashmap_remove(service->manager->dnssd_services, service->id);
|
||||
|
||||
dns_resource_record_unref(service->ptr_rr);
|
||||
dns_resource_record_unref(service->sub_ptr_rr);
|
||||
@ -49,7 +50,7 @@ DnssdService *dnssd_service_free(DnssdService *service) {
|
||||
dnssd_txtdata_free_all(service->txt_data_items);
|
||||
|
||||
free(service->path);
|
||||
free(service->name);
|
||||
free(service->id);
|
||||
free(service->type);
|
||||
free(service->subtype);
|
||||
free(service->name_template);
|
||||
@ -62,16 +63,36 @@ void dnssd_service_clear_on_reload(Hashmap *services) {
|
||||
|
||||
HASHMAP_FOREACH(service, services)
|
||||
if (service->config_source == RESOLVE_CONFIG_SOURCE_FILE) {
|
||||
hashmap_remove(services, service->name);
|
||||
hashmap_remove(services, service->id);
|
||||
dnssd_service_free(service);
|
||||
}
|
||||
}
|
||||
|
||||
static int dnssd_id_from_path(const char *path, char **ret_id) {
|
||||
int r;
|
||||
|
||||
assert(path);
|
||||
assert(ret_id);
|
||||
|
||||
_cleanup_free_ char *fn = NULL;
|
||||
r = path_extract_filename(path, &fn);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
char *d = endswith(fn, ".dnssd");
|
||||
if (!d)
|
||||
return -EINVAL;
|
||||
|
||||
*d = '\0';
|
||||
|
||||
*ret_id = TAKE_PTR(fn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dnssd_service_load(Manager *manager, const char *path) {
|
||||
_cleanup_(dnssd_service_freep) DnssdService *service = NULL;
|
||||
_cleanup_(dnssd_txtdata_freep) DnssdTxtData *txt_data = NULL;
|
||||
char *d;
|
||||
const char *dropin_dirname;
|
||||
_cleanup_free_ char *dropin_dirname = NULL;
|
||||
int r;
|
||||
|
||||
assert(manager);
|
||||
@ -85,20 +106,14 @@ static int dnssd_service_load(Manager *manager, const char *path) {
|
||||
if (!service->path)
|
||||
return log_oom();
|
||||
|
||||
service->name = strdup(basename(path));
|
||||
if (!service->name)
|
||||
r = dnssd_id_from_path(path, &service->id);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to extract DNS-SD service id from filename: %m");
|
||||
|
||||
dropin_dirname = strjoin(service->id, ".dnssd.d");
|
||||
if (!dropin_dirname)
|
||||
return log_oom();
|
||||
|
||||
d = endswith(service->name, ".dnssd");
|
||||
if (!d)
|
||||
return -EINVAL;
|
||||
|
||||
assert(streq(d, ".dnssd"));
|
||||
|
||||
*d = '\0';
|
||||
|
||||
dropin_dirname = strjoina(service->name, ".dnssd.d");
|
||||
|
||||
r = config_parse_many(
|
||||
STRV_MAKE_CONST(path), DNSSD_SERVICE_DIRS, dropin_dirname, /* root = */ NULL,
|
||||
"Service\0",
|
||||
@ -113,12 +128,12 @@ static int dnssd_service_load(Manager *manager, const char *path) {
|
||||
if (!service->name_template)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s doesn't define service instance name",
|
||||
service->name);
|
||||
service->id);
|
||||
|
||||
if (!service->type)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s doesn't define service type",
|
||||
service->name);
|
||||
service->id);
|
||||
|
||||
if (!service->txt_data_items) {
|
||||
txt_data = new0(DnssdTxtData, 1);
|
||||
@ -133,7 +148,7 @@ static int dnssd_service_load(Manager *manager, const char *path) {
|
||||
TAKE_PTR(txt_data);
|
||||
}
|
||||
|
||||
r = hashmap_ensure_put(&manager->dnssd_services, &string_hash_ops, service->name, service);
|
||||
r = hashmap_ensure_put(&manager->dnssd_services, &string_hash_ops, service->id, service);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -369,7 +384,7 @@ int dnssd_signal_conflict(Manager *manager, const char *name) {
|
||||
|
||||
s->withdrawn = true;
|
||||
|
||||
r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", s->name, &path);
|
||||
r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", s->id, &path);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Can't get D-BUS object path: %m");
|
||||
|
||||
|
@ -27,7 +27,7 @@ struct DnssdTxtData {
|
||||
|
||||
struct DnssdService {
|
||||
char *path;
|
||||
char *name;
|
||||
char *id;
|
||||
char *name_template;
|
||||
char *type;
|
||||
char *subtype;
|
||||
|
@ -1349,7 +1349,7 @@ void manager_refresh_rrs(Manager *m) {
|
||||
if (m->mdns_support == RESOLVE_SUPPORT_YES)
|
||||
HASHMAP_FOREACH(s, m->dnssd_services)
|
||||
if (dnssd_update_rrs(s) < 0)
|
||||
log_warning("Failed to refresh DNS-SD service '%s'", s->name);
|
||||
log_warning("Failed to refresh DNS-SD service '%s'", s->id);
|
||||
|
||||
HASHMAP_FOREACH(l, m->links)
|
||||
link_add_rrs(l, false);
|
||||
@ -1778,7 +1778,7 @@ bool manager_next_dnssd_names(Manager *m) {
|
||||
|
||||
r = manager_next_random_name(s->name_template, &new_name);
|
||||
if (r < 0) {
|
||||
log_warning_errno(r, "Failed to get new name for service '%s': %m", s->name);
|
||||
log_warning_errno(r, "Failed to get new name for service '%s': %m", s->id);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user