mirror of
https://github.com/systemd/systemd
synced 2025-09-30 01:04:45 +02:00
Compare commits
No commits in common. "ca9fab8896995b1766787b70963ea752cbb68939" and "7bac23e8af9104d578be27358f92664c2595e152" have entirely different histories.
ca9fab8896
...
7bac23e8af
@ -115,6 +115,7 @@ node /org/freedesktop/resolve1 {
|
|||||||
ResetStatistics();
|
ResetStatistics();
|
||||||
FlushCaches();
|
FlushCaches();
|
||||||
ResetServerFeatures();
|
ResetServerFeatures();
|
||||||
|
GetMulticastHosts(out a(stiiay) UNNAMED);
|
||||||
properties:
|
properties:
|
||||||
readonly s LLMNRHostname = '...';
|
readonly s LLMNRHostname = '...';
|
||||||
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
|
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
|
||||||
@ -164,6 +165,8 @@ node /org/freedesktop/resolve1 {
|
|||||||
|
|
||||||
<!--method ResetServerFeatures is not documented!-->
|
<!--method ResetServerFeatures is not documented!-->
|
||||||
|
|
||||||
|
<!--method GetMulticastHosts is not documented!-->
|
||||||
|
|
||||||
<!--property DNSSECNegativeTrustAnchors is not documented!-->
|
<!--property DNSSECNegativeTrustAnchors is not documented!-->
|
||||||
|
|
||||||
<!--Autogenerated cross-references for systemd.directives, do not edit-->
|
<!--Autogenerated cross-references for systemd.directives, do not edit-->
|
||||||
@ -212,6 +215,8 @@ node /org/freedesktop/resolve1 {
|
|||||||
|
|
||||||
<variablelist class="dbus-method" generated="True" extra-ref="ResetServerFeatures()"/>
|
<variablelist class="dbus-method" generated="True" extra-ref="ResetServerFeatures()"/>
|
||||||
|
|
||||||
|
<variablelist class="dbus-method" generated="True" extra-ref="GetMulticastHosts()"/>
|
||||||
|
|
||||||
<variablelist class="dbus-property" generated="True" extra-ref="LLMNRHostname"/>
|
<variablelist class="dbus-property" generated="True" extra-ref="LLMNRHostname"/>
|
||||||
|
|
||||||
<variablelist class="dbus-property" generated="True" extra-ref="LLMNR"/>
|
<variablelist class="dbus-property" generated="True" extra-ref="LLMNR"/>
|
||||||
|
@ -180,6 +180,13 @@
|
|||||||
automatically, an explicit reverting is not necessary in that case.</para></listitem>
|
automatically, an explicit reverting is not necessary in that case.</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><command>show-multicast</command></term>
|
||||||
|
|
||||||
|
<listitem><para>Display the discovered LLMNR and mDNS hostnames along with their IPv4/IPv6 addresses.
|
||||||
|
</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<xi:include href="systemctl.xml" xpointer="log-level" />
|
<xi:include href="systemctl.xml" xpointer="log-level" />
|
||||||
</variablelist>
|
</variablelist>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
5
mkosi.postinst
Executable file
5
mkosi.postinst
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
mkdir -p /root/build
|
||||||
|
echo "directory /root/build" > ~/.gdbinit
|
@ -1656,37 +1656,23 @@ int conservative_renameat(
|
|||||||
goto do_rename;
|
goto do_rename;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
uint8_t buf1[16*1024];
|
char buf1[16*1024];
|
||||||
uint8_t buf2[sizeof(buf1)];
|
char buf2[sizeof(buf1) + 1];
|
||||||
ssize_t l1, l2;
|
ssize_t l1, l2;
|
||||||
|
|
||||||
l1 = read(old_fd, buf1, sizeof(buf1));
|
l1 = read(old_fd, buf1, sizeof(buf1));
|
||||||
if (l1 < 0)
|
if (l1 < 0)
|
||||||
goto do_rename;
|
goto do_rename;
|
||||||
|
|
||||||
if (l1 == sizeof(buf1))
|
|
||||||
/* Read the full block, hence read a full block in the other file too */
|
|
||||||
|
|
||||||
l2 = read(new_fd, buf2, l1);
|
|
||||||
else {
|
|
||||||
assert((size_t) l1 < sizeof(buf1));
|
|
||||||
|
|
||||||
/* Short read. This hence was the last block in the first file, and then came
|
|
||||||
* EOF. Read one byte more in the second file, so that we can verify we hit EOF there
|
|
||||||
* too. */
|
|
||||||
|
|
||||||
assert((size_t) (l1 + 1) <= sizeof(buf2));
|
|
||||||
l2 = read(new_fd, buf2, l1 + 1);
|
l2 = read(new_fd, buf2, l1 + 1);
|
||||||
}
|
if (l1 != l2)
|
||||||
if (l2 != l1)
|
|
||||||
goto do_rename;
|
goto do_rename;
|
||||||
|
|
||||||
|
if (l1 == 0) /* EOF on both! And everything's the same so far, yay! */
|
||||||
|
break;
|
||||||
|
|
||||||
if (memcmp(buf1, buf2, l1) != 0)
|
if (memcmp(buf1, buf2, l1) != 0)
|
||||||
goto do_rename;
|
goto do_rename;
|
||||||
|
|
||||||
if ((size_t) l1 < sizeof(buf1)) /* We hit EOF on the first file, and the second file too, hence exit
|
|
||||||
* now. */
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is_same:
|
is_same:
|
||||||
|
@ -2500,6 +2500,90 @@ static int verb_log_level(int argc, char *argv[], void *userdata) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *resolve_flags_to_string(uint64_t flags) {
|
||||||
|
return flags & SD_RESOLVED_DNS ? "DNS" :
|
||||||
|
flags & SD_RESOLVED_LLMNR_IPV4 ? "LLMNR/IPv4" :
|
||||||
|
flags & SD_RESOLVED_LLMNR_IPV6 ? "LLMNR/IPv6" :
|
||||||
|
flags & SD_RESOLVED_MDNS_IPV4 ? "mDNS/IPv4" :
|
||||||
|
flags & SD_RESOLVED_MDNS_IPV6 ? "mDNS/IPv6" :
|
||||||
|
"";
|
||||||
|
}
|
||||||
|
|
||||||
|
static int verb_show_multicast(int argc, char *argv[], void *userdata) {
|
||||||
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
|
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
||||||
|
_cleanup_(table_unrefp) Table *table = NULL;
|
||||||
|
sd_bus *bus = userdata;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(bus);
|
||||||
|
|
||||||
|
table = table_new("Hostname", "Address", "Source");
|
||||||
|
if (!table)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
|
r = bus_call_method(bus, bus_resolve_mgr, "GetMulticastHosts", &error, &reply, NULL);
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to query systemd-resolved: %s", bus_error_message(&error, r));
|
||||||
|
|
||||||
|
r = sd_bus_message_enter_container(reply, 'a', "(stiiay)");
|
||||||
|
if (r < 0)
|
||||||
|
return bus_log_parse_error(r);
|
||||||
|
|
||||||
|
while ((r = sd_bus_message_enter_container(reply, 'r', "stiiay")) > 0) {
|
||||||
|
char *canonical;
|
||||||
|
uint64_t flags;
|
||||||
|
_cleanup_free_ char *pretty = NULL;
|
||||||
|
int ifindex, family;
|
||||||
|
union in_addr_union a;
|
||||||
|
|
||||||
|
r = sd_bus_message_read(reply, "st", &canonical, &flags);
|
||||||
|
if (r < 0)
|
||||||
|
return bus_log_parse_error(r);
|
||||||
|
|
||||||
|
r = sd_bus_message_read(reply, "i", &ifindex);
|
||||||
|
if (r < 0)
|
||||||
|
return bus_log_parse_error(r);
|
||||||
|
|
||||||
|
sd_bus_error_free(&error);
|
||||||
|
r = bus_message_read_in_addr_auto(reply, &error, &family, &a);
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(
|
||||||
|
r,
|
||||||
|
"systemd-resolved returned invalid result: %s",
|
||||||
|
bus_error_message(&error, r));
|
||||||
|
|
||||||
|
r = sd_bus_message_exit_container(reply);
|
||||||
|
if (r < 0)
|
||||||
|
return bus_log_parse_error(r);
|
||||||
|
|
||||||
|
r = in_addr_ifindex_to_string(family, &a, ifindex, &pretty);
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to print address: %m");
|
||||||
|
|
||||||
|
r = table_add_many(
|
||||||
|
table,
|
||||||
|
TABLE_STRING,
|
||||||
|
canonical,
|
||||||
|
TABLE_STRING,
|
||||||
|
pretty,
|
||||||
|
TABLE_STRING,
|
||||||
|
resolve_flags_to_string(flags));
|
||||||
|
if (r < 0)
|
||||||
|
return table_log_add_error(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
r = sd_bus_message_exit_container(reply);
|
||||||
|
if (r < 0)
|
||||||
|
return bus_log_parse_error(r);
|
||||||
|
|
||||||
|
r = table_print(table, NULL);
|
||||||
|
if (r < 0)
|
||||||
|
return table_log_print_error(r);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void help_protocol_types(void) {
|
static void help_protocol_types(void) {
|
||||||
if (arg_legend)
|
if (arg_legend)
|
||||||
puts("Known protocol types:");
|
puts("Known protocol types:");
|
||||||
@ -2609,6 +2693,7 @@ static int native_help(void) {
|
|||||||
" nta [LINK [DOMAIN...]] Get/set per-interface DNSSEC NTA\n"
|
" nta [LINK [DOMAIN...]] Get/set per-interface DNSSEC NTA\n"
|
||||||
" revert LINK Revert per-interface configuration\n"
|
" revert LINK Revert per-interface configuration\n"
|
||||||
" log-level [LEVEL] Get/set logging threshold for systemd-resolved\n"
|
" log-level [LEVEL] Get/set logging threshold for systemd-resolved\n"
|
||||||
|
" show-multicast Show domain names discovered via LLMNR/mDNS\n"
|
||||||
"\nOptions:\n"
|
"\nOptions:\n"
|
||||||
" -h --help Show this help\n"
|
" -h --help Show this help\n"
|
||||||
" --version Show package version\n"
|
" --version Show package version\n"
|
||||||
@ -3152,7 +3237,7 @@ static int native_parse_argv(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int native_main(int argc, char *argv[], sd_bus *bus) {
|
static int native_main(int argc, char *argv[], sd_bus *bus) {
|
||||||
|
/* clang-format off */
|
||||||
static const Verb verbs[] = {
|
static const Verb verbs[] = {
|
||||||
{ "help", VERB_ANY, VERB_ANY, 0, verb_help },
|
{ "help", VERB_ANY, VERB_ANY, 0, verb_help },
|
||||||
{ "status", VERB_ANY, VERB_ANY, VERB_DEFAULT, verb_status },
|
{ "status", VERB_ANY, VERB_ANY, VERB_DEFAULT, verb_status },
|
||||||
@ -3174,8 +3259,10 @@ static int native_main(int argc, char *argv[], sd_bus *bus) {
|
|||||||
{ "nta", VERB_ANY, VERB_ANY, 0, verb_nta },
|
{ "nta", VERB_ANY, VERB_ANY, 0, verb_nta },
|
||||||
{ "revert", VERB_ANY, 2, 0, verb_revert_link },
|
{ "revert", VERB_ANY, 2, 0, verb_revert_link },
|
||||||
{ "log-level", VERB_ANY, 2, 0, verb_log_level },
|
{ "log-level", VERB_ANY, 2, 0, verb_log_level },
|
||||||
|
{ "show-multicast", VERB_ANY, VERB_ANY, 0, verb_show_multicast },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
return dispatch_verb(argc, argv, verbs, bus);
|
return dispatch_verb(argc, argv, verbs, bus);
|
||||||
}
|
}
|
||||||
|
@ -132,15 +132,17 @@ static int reply_query_state(DnsQuery *q) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int append_address(sd_bus_message *reply, DnsResourceRecord *rr, int ifindex) {
|
static int append_address(sd_bus_message *reply, DnsResourceRecord *rr, int ifindex, bool is_container) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(reply);
|
assert(reply);
|
||||||
assert(rr);
|
assert(rr);
|
||||||
|
|
||||||
|
if (is_container) {
|
||||||
r = sd_bus_message_open_container(reply, 'r', "iiay");
|
r = sd_bus_message_open_container(reply, 'r', "iiay");
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
r = sd_bus_message_append(reply, "i", ifindex);
|
r = sd_bus_message_append(reply, "i", ifindex);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -165,9 +167,11 @@ static int append_address(sd_bus_message *reply, DnsResourceRecord *rr, int ifin
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
if (is_container) {
|
||||||
r = sd_bus_message_close_container(reply);
|
r = sd_bus_message_close_container(reply);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -216,7 +220,7 @@ static void bus_method_resolve_hostname_complete(DnsQuery *q) {
|
|||||||
if (r == 0)
|
if (r == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
r = append_address(reply, rr, ifindex);
|
r = append_address(reply, rr, ifindex, true);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
@ -851,7 +855,7 @@ static int append_srv(DnsQuery *q, sd_bus_message *reply, DnsResourceRecord *rr)
|
|||||||
if (r == 0)
|
if (r == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
r = append_address(reply, zz, ifindex);
|
r = append_address(reply, zz, ifindex, true);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -2000,6 +2004,76 @@ static int bus_method_unregister_service(sd_bus_message *message, void *userdata
|
|||||||
return call_dnssd_method(m, message, bus_dnssd_method_unregister, error);
|
return call_dnssd_method(m, message, bus_dnssd_method_unregister, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int bus_method_get_multicast_hosts(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||||
|
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
||||||
|
DnsScope *s;
|
||||||
|
Manager *m = userdata;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(message);
|
||||||
|
assert(m);
|
||||||
|
|
||||||
|
r = sd_bus_message_new_method_return(message, &reply);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = sd_bus_message_open_container(reply, 'a', "(stiiay)");
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
LIST_FOREACH(scopes, s, m->dns_scopes) {
|
||||||
|
_cleanup_(dns_answer_unrefp) DnsAnswer *answer = NULL;
|
||||||
|
DnsResourceRecord *rr;
|
||||||
|
DnsAnswerFlags flags;
|
||||||
|
int ifindex;
|
||||||
|
|
||||||
|
if (s->protocol == DNS_PROTOCOL_DNS)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
r = dns_cache_dump_to_answer(&s->cache, &answer);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
if (r == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
DNS_ANSWER_FOREACH_FULL(rr, ifindex, flags, answer) {
|
||||||
|
_cleanup_free_ char *normalized = NULL;
|
||||||
|
bool authenticated = FLAGS_SET(flags, DNS_ANSWER_AUTHENTICATED);
|
||||||
|
|
||||||
|
r = dns_name_normalize(dns_resource_key_name(rr->key), 0, &normalized);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = sd_bus_message_open_container(reply, 'r', "stiiay");
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = sd_bus_message_append(
|
||||||
|
reply,
|
||||||
|
"st",
|
||||||
|
normalized,
|
||||||
|
SD_RESOLVED_FLAGS_MAKE(s->protocol, s->family, authenticated));
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = append_address(reply, rr, ifindex, false);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = sd_bus_message_close_container(reply);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
r = sd_bus_message_close_container(reply);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
return sd_bus_reply(message, reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clang-format off */
|
||||||
static const sd_bus_vtable resolve_vtable[] = {
|
static const sd_bus_vtable resolve_vtable[] = {
|
||||||
SD_BUS_VTABLE_START(0),
|
SD_BUS_VTABLE_START(0),
|
||||||
SD_BUS_PROPERTY("LLMNRHostname", "s", NULL, offsetof(Manager, llmnr_hostname), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
SD_BUS_PROPERTY("LLMNRHostname", "s", NULL, offsetof(Manager, llmnr_hostname), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||||
@ -2138,9 +2212,14 @@ static const sd_bus_vtable resolve_vtable[] = {
|
|||||||
SD_BUS_NO_RESULT,
|
SD_BUS_NO_RESULT,
|
||||||
bus_method_reset_server_features,
|
bus_method_reset_server_features,
|
||||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
|
SD_BUS_METHOD_WITH_ARGS("GetMulticastHosts",
|
||||||
|
SD_BUS_NO_ARGS,
|
||||||
|
SD_BUS_RESULT("a(stiiay)", addresses),
|
||||||
|
bus_method_get_multicast_hosts,
|
||||||
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
SD_BUS_VTABLE_END,
|
SD_BUS_VTABLE_END,
|
||||||
};
|
};
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
const BusObjectImplementation manager_object = {
|
const BusObjectImplementation manager_object = {
|
||||||
"/org/freedesktop/resolve1",
|
"/org/freedesktop/resolve1",
|
||||||
|
@ -1066,7 +1066,55 @@ int dns_cache_export_shared_to_packet(DnsCache *cache, DnsPacket *p) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dns_cache_dump(DnsCache *cache, FILE *f) {
|
int dns_cache_dump_to_answer(DnsCache *cache, DnsAnswer **ret) {
|
||||||
|
_cleanup_(dns_answer_unrefp) DnsAnswer *answer = NULL;
|
||||||
|
DnsCacheItem *i;
|
||||||
|
size_t n = 0;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(cache);
|
||||||
|
assert(ret);
|
||||||
|
|
||||||
|
HASHMAP_FOREACH(i, cache->by_key) {
|
||||||
|
DnsCacheItem *j;
|
||||||
|
|
||||||
|
LIST_FOREACH(by_key, j, i) {
|
||||||
|
if (!j->rr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n == 0) {
|
||||||
|
*ret = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
answer = dns_answer_new(n);
|
||||||
|
if (!answer)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
HASHMAP_FOREACH(i, cache->by_key) {
|
||||||
|
DnsCacheItem *j;
|
||||||
|
|
||||||
|
LIST_FOREACH(by_key, j, i) {
|
||||||
|
if (!j->rr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
r = dns_answer_add(
|
||||||
|
answer, j->rr, j->ifindex, j->authenticated ? DNS_ANSWER_AUTHENTICATED : 0);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*ret = TAKE_PTR(answer);
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dns_cache_dump_to_file(DnsCache *cache, FILE *f) {
|
||||||
DnsCacheItem *i;
|
DnsCacheItem *i;
|
||||||
|
|
||||||
if (!cache)
|
if (!cache)
|
||||||
|
@ -27,7 +27,8 @@ int dns_cache_lookup(DnsCache *c, DnsResourceKey *key, bool clamp_ttl, int *rcod
|
|||||||
|
|
||||||
int dns_cache_check_conflicts(DnsCache *cache, DnsResourceRecord *rr, int owner_family, const union in_addr_union *owner_address);
|
int dns_cache_check_conflicts(DnsCache *cache, DnsResourceRecord *rr, int owner_family, const union in_addr_union *owner_address);
|
||||||
|
|
||||||
void dns_cache_dump(DnsCache *cache, FILE *f);
|
void dns_cache_dump_to_file(DnsCache *cache, FILE *f);
|
||||||
|
int dns_cache_dump_to_answer(DnsCache *cache, DnsAnswer **answer);
|
||||||
bool dns_cache_is_empty(DnsCache *cache);
|
bool dns_cache_is_empty(DnsCache *cache);
|
||||||
|
|
||||||
unsigned dns_cache_size(DnsCache *cache);
|
unsigned dns_cache_size(DnsCache *cache);
|
||||||
|
@ -1159,7 +1159,7 @@ void dns_scope_dump(DnsScope *s, FILE *f) {
|
|||||||
|
|
||||||
if (!dns_cache_is_empty(&s->cache)) {
|
if (!dns_cache_is_empty(&s->cache)) {
|
||||||
fputs("CACHE:\n", f);
|
fputs("CACHE:\n", f);
|
||||||
dns_cache_dump(&s->cache, f);
|
dns_cache_dump_to_file(&s->cache, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
#include "mkdir.h"
|
#include "mkdir.h"
|
||||||
#include "path-util.h"
|
#include "path-util.h"
|
||||||
#include "random-util.h"
|
|
||||||
#include "rm-rf.h"
|
#include "rm-rf.h"
|
||||||
#include "stdio-util.h"
|
#include "stdio-util.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
@ -837,24 +836,12 @@ static void test_path_is_encrypted(void) {
|
|||||||
test_path_is_encrypted_one("/dev", booted > 0 ? false : -1);
|
test_path_is_encrypted_one("/dev", booted > 0 ? false : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create_binary_file(const char *p, const void *data, size_t l) {
|
|
||||||
_cleanup_close_ int fd = -1;
|
|
||||||
|
|
||||||
fd = open(p, O_CREAT|O_WRONLY|O_EXCL|O_CLOEXEC, 0600);
|
|
||||||
assert_se(fd >= 0);
|
|
||||||
assert_se(write(fd, data, l) == (ssize_t) l);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_conservative_rename(void) {
|
static void test_conservative_rename(void) {
|
||||||
_cleanup_(unlink_and_freep) char *p = NULL;
|
_cleanup_(unlink_and_freep) char *p = NULL;
|
||||||
_cleanup_free_ char *q = NULL;
|
_cleanup_free_ char *q = NULL;
|
||||||
size_t l = 16*1024 + random_u64() % (32 * 1024); /* some randomly sized buffer 16k…48k */
|
|
||||||
uint8_t buffer[l+1];
|
|
||||||
|
|
||||||
random_bytes(buffer, l);
|
|
||||||
|
|
||||||
assert_se(tempfn_random_child(NULL, NULL, &p) >= 0);
|
assert_se(tempfn_random_child(NULL, NULL, &p) >= 0);
|
||||||
create_binary_file(p, buffer, l);
|
assert_se(write_string_file(p, "this is a test", WRITE_STRING_FILE_CREATE) >= 0);
|
||||||
|
|
||||||
assert_se(tempfn_random_child(NULL, NULL, &q) >= 0);
|
assert_se(tempfn_random_child(NULL, NULL, &q) >= 0);
|
||||||
|
|
||||||
@ -869,30 +856,27 @@ static void test_conservative_rename(void) {
|
|||||||
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
|
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
|
||||||
|
|
||||||
/* Check that a manual new writeout is also detected */
|
/* Check that a manual new writeout is also detected */
|
||||||
create_binary_file(q, buffer, l);
|
assert_se(write_string_file(q, "this is a test", WRITE_STRING_FILE_CREATE) >= 0);
|
||||||
assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) == 0);
|
assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) == 0);
|
||||||
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
|
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
|
||||||
|
|
||||||
/* Check that a minimally changed version is detected */
|
/* Check that a minimally changed version is detected */
|
||||||
buffer[47] = ~buffer[47];
|
assert_se(write_string_file(q, "this is a_test", WRITE_STRING_FILE_CREATE) >= 0);
|
||||||
create_binary_file(q, buffer, l);
|
|
||||||
assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) > 0);
|
assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) > 0);
|
||||||
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
|
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
|
||||||
|
|
||||||
/* Check that this really is new updated version */
|
/* Check that this really is new updated version */
|
||||||
create_binary_file(q, buffer, l);
|
assert_se(write_string_file(q, "this is a_test", WRITE_STRING_FILE_CREATE) >= 0);
|
||||||
assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) == 0);
|
assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) == 0);
|
||||||
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
|
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
|
||||||
|
|
||||||
/* Make sure we detect extended files */
|
/* Make sure we detect extended files */
|
||||||
buffer[l++] = 47;
|
assert_se(write_string_file(q, "this is a_testx", WRITE_STRING_FILE_CREATE) >= 0);
|
||||||
create_binary_file(q, buffer, l);
|
|
||||||
assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) > 0);
|
assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) > 0);
|
||||||
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
|
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
|
||||||
|
|
||||||
/* Make sure we detect truncated files */
|
/* Make sure we detect truncated files */
|
||||||
l--;
|
assert_se(write_string_file(q, "this is a_test", WRITE_STRING_FILE_CREATE) >= 0);
|
||||||
create_binary_file(q, buffer, l);
|
|
||||||
assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) > 0);
|
assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) > 0);
|
||||||
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
|
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user