mirror of
https://github.com/systemd/systemd
synced 2026-03-15 17:44:49 +01:00
Compare commits
No commits in common. "c856ef0457c35e9edfdbf085b69ec81c126d48e5" and "4301cb32f2513a0187951d09ebc108a4179a0877" have entirely different histories.
c856ef0457
...
4301cb32f2
@ -42,8 +42,6 @@ static void dns_query_candidate_stop(DnsQueryCandidate *c) {
|
|||||||
|
|
||||||
assert(c);
|
assert(c);
|
||||||
|
|
||||||
/* Detach all the DnsTransactions attached to this query */
|
|
||||||
|
|
||||||
while ((t = set_steal_first(c->transactions))) {
|
while ((t = set_steal_first(c->transactions))) {
|
||||||
set_remove(t->notify_query_candidates, c);
|
set_remove(t->notify_query_candidates, c);
|
||||||
set_remove(t->notify_query_candidates_done, c);
|
set_remove(t->notify_query_candidates_done, c);
|
||||||
@ -51,34 +49,21 @@ static void dns_query_candidate_stop(DnsQueryCandidate *c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DnsQueryCandidate* dns_query_candidate_unlink(DnsQueryCandidate *c) {
|
|
||||||
assert(c);
|
|
||||||
|
|
||||||
/* Detach this DnsQueryCandidate from the Query and Scope objects */
|
|
||||||
|
|
||||||
if (c->query) {
|
|
||||||
LIST_REMOVE(candidates_by_query, c->query->candidates, c);
|
|
||||||
c->query = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c->scope) {
|
|
||||||
LIST_REMOVE(candidates_by_scope, c->scope->query_candidates, c);
|
|
||||||
c->scope = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
static DnsQueryCandidate* dns_query_candidate_free(DnsQueryCandidate *c) {
|
static DnsQueryCandidate* dns_query_candidate_free(DnsQueryCandidate *c) {
|
||||||
if (!c)
|
if (!c)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
dns_query_candidate_stop(c);
|
dns_query_candidate_stop(c);
|
||||||
dns_query_candidate_unlink(c);
|
|
||||||
|
|
||||||
set_free(c->transactions);
|
set_free(c->transactions);
|
||||||
dns_search_domain_unref(c->search_domain);
|
dns_search_domain_unref(c->search_domain);
|
||||||
|
|
||||||
|
if (c->query)
|
||||||
|
LIST_REMOVE(candidates_by_query, c->query->candidates, c);
|
||||||
|
|
||||||
|
if (c->scope)
|
||||||
|
LIST_REMOVE(candidates_by_scope, c->scope->query_candidates, c);
|
||||||
|
|
||||||
return mfree(c);
|
return mfree(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +105,6 @@ static int dns_query_candidate_add_transaction(
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(c);
|
assert(c);
|
||||||
assert(c->query); /* We shan't add transactions to a candidate that has been detached already */
|
|
||||||
|
|
||||||
if (key) {
|
if (key) {
|
||||||
/* Regular lookup with a resource key */
|
/* Regular lookup with a resource key */
|
||||||
@ -239,7 +223,6 @@ static int dns_query_candidate_setup_transactions(DnsQueryCandidate *c) {
|
|||||||
int n = 0, r;
|
int n = 0, r;
|
||||||
|
|
||||||
assert(c);
|
assert(c);
|
||||||
assert(c->query); /* We shan't add transactions to a candidate that has been detached already */
|
|
||||||
|
|
||||||
dns_query_candidate_stop(c);
|
dns_query_candidate_stop(c);
|
||||||
|
|
||||||
@ -297,9 +280,6 @@ void dns_query_candidate_notify(DnsQueryCandidate *c) {
|
|||||||
|
|
||||||
assert(c);
|
assert(c);
|
||||||
|
|
||||||
if (!c->query) /* This candidate has been abandoned, do nothing. */
|
|
||||||
return;
|
|
||||||
|
|
||||||
state = dns_query_candidate_state(c);
|
state = dns_query_candidate_state(c);
|
||||||
|
|
||||||
if (DNS_TRANSACTION_IS_LIVE(state))
|
if (DNS_TRANSACTION_IS_LIVE(state))
|
||||||
@ -350,13 +330,11 @@ static void dns_query_stop(DnsQuery *q) {
|
|||||||
dns_query_candidate_stop(c);
|
dns_query_candidate_stop(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dns_query_unlink_candidates(DnsQuery *q) {
|
static void dns_query_unref_candidates(DnsQuery *q) {
|
||||||
assert(q);
|
assert(q);
|
||||||
|
|
||||||
while (q->candidates)
|
while (q->candidates)
|
||||||
/* Here we drop *our* references to each of the candidates. If we had the only reference, the
|
dns_query_candidate_unref(q->candidates);
|
||||||
* DnsQueryCandidate object will be freed. */
|
|
||||||
dns_query_candidate_unref(dns_query_candidate_unlink(q->candidates));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dns_query_reset_answer(DnsQuery *q) {
|
static void dns_query_reset_answer(DnsQuery *q) {
|
||||||
@ -386,7 +364,7 @@ DnsQuery *dns_query_free(DnsQuery *q) {
|
|||||||
LIST_REMOVE(auxiliary_queries, q->auxiliary_for->auxiliary_queries, q);
|
LIST_REMOVE(auxiliary_queries, q->auxiliary_for->auxiliary_queries, q);
|
||||||
}
|
}
|
||||||
|
|
||||||
dns_query_unlink_candidates(q);
|
dns_query_unref_candidates(q);
|
||||||
|
|
||||||
dns_question_unref(q->question_idna);
|
dns_question_unref(q->question_idna);
|
||||||
dns_question_unref(q->question_utf8);
|
dns_question_unref(q->question_utf8);
|
||||||
@ -1047,7 +1025,7 @@ static int dns_query_cname_redirect(DnsQuery *q, const DnsResourceRecord *cname)
|
|||||||
dns_question_unref(q->question_utf8);
|
dns_question_unref(q->question_utf8);
|
||||||
q->question_utf8 = TAKE_PTR(nq_utf8);
|
q->question_utf8 = TAKE_PTR(nq_utf8);
|
||||||
|
|
||||||
dns_query_unlink_candidates(q);
|
dns_query_unref_candidates(q);
|
||||||
|
|
||||||
/* Note that we do *not* reset the answer here, because the answer we previously got might already
|
/* Note that we do *not* reset the answer here, because the answer we previously got might already
|
||||||
* include everything we need, let's check that first */
|
* include everything we need, let's check that first */
|
||||||
|
|||||||
@ -4,18 +4,21 @@
|
|||||||
import sys
|
import sys
|
||||||
import collections
|
import collections
|
||||||
import re
|
import re
|
||||||
|
import concurrent.futures
|
||||||
from xml_helper import xml_parse, xml_print, tree
|
from xml_helper import xml_parse, xml_print, tree
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
COLOPHON = '''\
|
COLOPHON = '''\
|
||||||
This index contains {count} entries in {sections} sections,
|
This index contains {count} entries in {sections} sections,
|
||||||
referring to {pages} individual manual pages.
|
referring to {pages} individual manual pages.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def _extract_directives(directive_groups, formatting, page):
|
def _extract_directives(page, names):
|
||||||
|
directive_groups = {name:collections.defaultdict(set) for name in names}
|
||||||
|
|
||||||
t = xml_parse(page)
|
t = xml_parse(page)
|
||||||
section = t.find('./refmeta/manvolnum').text
|
section = t.find('./refmeta/manvolnum').text
|
||||||
pagename = t.find('./refmeta/refentrytitle').text
|
pagename = t.find('./refmeta/refentrytitle').text
|
||||||
|
formatting = {}
|
||||||
|
|
||||||
storopt = directive_groups['options']
|
storopt = directive_groups['options']
|
||||||
for variablelist in t.iterfind('.//variablelist'):
|
for variablelist in t.iterfind('.//variablelist'):
|
||||||
@ -31,7 +34,7 @@ def _extract_directives(directive_groups, formatting, page):
|
|||||||
if text.startswith('-'):
|
if text.startswith('-'):
|
||||||
# for options, merge options with and without mandatory arg
|
# for options, merge options with and without mandatory arg
|
||||||
text = text.partition('=')[0]
|
text = text.partition('=')[0]
|
||||||
stor[text].append((pagename, section))
|
stor[text].add((pagename, section))
|
||||||
if text not in formatting:
|
if text not in formatting:
|
||||||
# use element as formatted display
|
# use element as formatted display
|
||||||
if name.text[-1] in "= '":
|
if name.text[-1] in "= '":
|
||||||
@ -42,7 +45,7 @@ def _extract_directives(directive_groups, formatting, page):
|
|||||||
formatting[text] = name
|
formatting[text] = name
|
||||||
extra = variablelist.attrib.get('extra-ref')
|
extra = variablelist.attrib.get('extra-ref')
|
||||||
if extra:
|
if extra:
|
||||||
stor[extra].append((pagename, section))
|
stor[extra].add((pagename, section))
|
||||||
if extra not in formatting:
|
if extra not in formatting:
|
||||||
elt = tree.Element("varname")
|
elt = tree.Element("varname")
|
||||||
elt.text= extra
|
elt.text= extra
|
||||||
@ -68,13 +71,13 @@ def _extract_directives(directive_groups, formatting, page):
|
|||||||
name.text = text
|
name.text = text
|
||||||
if text.endswith('/'):
|
if text.endswith('/'):
|
||||||
text = text[:-1]
|
text = text[:-1]
|
||||||
storfile[text].append((pagename, section))
|
storfile[text].add((pagename, section))
|
||||||
if text not in formatting:
|
if text not in formatting:
|
||||||
# use element as formatted display
|
# use element as formatted display
|
||||||
formatting[text] = name
|
formatting[text] = name
|
||||||
else:
|
else:
|
||||||
text = ' '.join(name.itertext())
|
text = ' '.join(name.itertext())
|
||||||
storfile[text].append((pagename, section))
|
storfile[text].add((pagename, section))
|
||||||
formatting[text] = name
|
formatting[text] = name
|
||||||
|
|
||||||
storfile = directive_groups['constants']
|
storfile = directive_groups['constants']
|
||||||
@ -84,7 +87,7 @@ def _extract_directives(directive_groups, formatting, page):
|
|||||||
name.tail = ''
|
name.tail = ''
|
||||||
if name.text.startswith('('): # a cast, strip it
|
if name.text.startswith('('): # a cast, strip it
|
||||||
name.text = name.text.partition(' ')[2]
|
name.text = name.text.partition(' ')[2]
|
||||||
storfile[name.text].append((pagename, section))
|
storfile[name.text].add((pagename, section))
|
||||||
formatting[name.text] = name
|
formatting[name.text] = name
|
||||||
|
|
||||||
storfile = directive_groups['specifiers']
|
storfile = directive_groups['specifiers']
|
||||||
@ -93,18 +96,30 @@ def _extract_directives(directive_groups, formatting, page):
|
|||||||
continue
|
continue
|
||||||
if name.attrib.get('index') == 'false':
|
if name.attrib.get('index') == 'false':
|
||||||
continue
|
continue
|
||||||
storfile[name.text].append((pagename, section))
|
storfile[name.text].add((pagename, section))
|
||||||
formatting[name.text] = name
|
formatting[name.text] = name
|
||||||
for name in t.iterfind(".//literal[@class='specifiers']"):
|
for name in t.iterfind(".//literal[@class='specifiers']"):
|
||||||
storfile[name.text].append((pagename, section))
|
storfile[name.text].add((pagename, section))
|
||||||
formatting[name.text] = name
|
formatting[name.text] = name
|
||||||
|
|
||||||
|
# Serialize to allow pickling
|
||||||
|
formatting = {name:xml_print(value) for name, value in formatting.items()}
|
||||||
|
|
||||||
|
return directive_groups, formatting
|
||||||
|
|
||||||
|
def extract_directives(arg):
|
||||||
|
page, names = arg
|
||||||
|
try:
|
||||||
|
return _extract_directives(page, names)
|
||||||
|
except Exception:
|
||||||
|
raise ValueError("Failed to process {}".format(page))
|
||||||
|
|
||||||
def _make_section(template, name, directives, formatting):
|
def _make_section(template, name, directives, formatting):
|
||||||
varlist = template.find(".//*[@id='{}']".format(name))
|
varlist = template.find(".//*[@id='{}']".format(name))
|
||||||
for varname, manpages in sorted(directives.items()):
|
for varname, manpages in sorted(directives.items()):
|
||||||
entry = tree.SubElement(varlist, 'varlistentry')
|
entry = tree.SubElement(varlist, 'varlistentry')
|
||||||
term = tree.SubElement(entry, 'term')
|
term = tree.SubElement(entry, 'term')
|
||||||
display = deepcopy(formatting[varname])
|
display = tree.fromstring(formatting[varname])
|
||||||
term.append(display)
|
term.append(display)
|
||||||
|
|
||||||
para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
|
para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para')
|
||||||
@ -154,20 +169,26 @@ def make_page(template_path, xml_files):
|
|||||||
"Extract directives from xml_files and return XML index tree."
|
"Extract directives from xml_files and return XML index tree."
|
||||||
template = xml_parse(template_path)
|
template = xml_parse(template_path)
|
||||||
names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
|
names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
|
||||||
directive_groups = {name:collections.defaultdict(list)
|
|
||||||
for name in names}
|
with concurrent.futures.ProcessPoolExecutor() as pool:
|
||||||
|
args = ((xml_file, names) for xml_file in xml_files)
|
||||||
|
results = list(pool.map(extract_directives, args))
|
||||||
|
|
||||||
|
directive_groups = {name:collections.defaultdict(set) for name in names}
|
||||||
formatting = {}
|
formatting = {}
|
||||||
for page in xml_files:
|
for d_g, f in reversed(results):
|
||||||
try:
|
for group, mapping in d_g.items():
|
||||||
_extract_directives(directive_groups, formatting, page)
|
for name, value in mapping.items():
|
||||||
except Exception:
|
directive_groups[group][name].update(value)
|
||||||
raise ValueError("failed to process " + page)
|
|
||||||
|
formatting.update(f)
|
||||||
|
|
||||||
return _make_page(template, directive_groups, formatting)
|
return _make_page(template, directive_groups, formatting)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def main(output, template_path, *xml_files):
|
||||||
with open(sys.argv[1], 'wb') as f:
|
with open(output, 'wb') as f:
|
||||||
template_path = sys.argv[2]
|
|
||||||
xml_files = sys.argv[3:]
|
|
||||||
xml = make_page(template_path, xml_files)
|
xml = make_page(template_path, xml_files)
|
||||||
f.write(xml_print(xml))
|
f.write(xml_print(xml))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(*sys.argv[1:])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user