PowerDNS没有从管道后端得到答案



我正在尝试为powerdns编写自己的管道后端,但无法正常工作。我正在用我的后端启动pdn_server,并尝试用以下命令进行测试:

# nslookup example.com 127.0.0.1

# dig @127.0.0.1 example.com

第一个问题是,对后端的第一个查询带有类型"SOA"(后端abi版本2):

Q   example.com IN  SOA -1  127.0.0.1   0.0.0.0

我想"好吧,让我们从SOA开始",并尝试编写部分代码。在调试中,我可以看到后端启动了,确实收到了查询并将答案发送给了pdns。但似乎出了问题,pdns没有得到它。不知道是什么问题。源代码和调试如下:

#!/usr/bin/python
from sys import stdin, stdout, stderr
data = stdin.readline()
stdout.write("OKtCC DNS Backendn")
stdout.flush()
stderr.write("$$$ Main loop started...n")
while True:
    line = stdin.readline().strip()
    kind, qname, qclass, qtype, id, ip, mask = line.split('t')
    if kind == 'Q':
        stderr.write('$$$ Got request ' + qname + 'n')
        if qtype != 'SOA':
            r = "DATAt'+qname+'t'+qtype+'t'+qclass+'t'+'127.0.0.1n"
            stderr.write(r)
            stdout.write(r)
        else:
            stderr.write("$$$ Sending SOAn")
            r = "DATAtexample.comtINtSOAt86400t1tahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600n"
            stdout.write(r)
            stderr.write(r)
        stdout.write("ENDn")
        stderr.write("ENDn")

调试:

Dec 05 15:36:43 Done launching threads, ready to distribute questions
Dec 05 15:36:49 Query: 'Q   example.com IN  SOA -1  127.0.0.1   0.0.0.0'
$$$ Got request example.com
$$$ Sending SOA
DATA    example.com IN  SOA 86400   1   ahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600
END
$$$ Main loop started...
Dec 05 15:36:49 Backend launched with banner: OK    CC DNS Backend
$$$ Main loop started...
Dec 05 15:36:49 Backend launched with banner: OK    CC DNS Backend
Dec 05 15:36:54 Query: 'Q   example.com IN  SOA -1  127.0.0.1   0.0.0.0'
$$$ Got request example.com
$$$ Sending SOA
DATA    example.com IN  SOA 86400   1   ahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600
END
Dec 05 15:36:59 Query: 'Q   example.com IN  SOA -1  127.0.0.1   0.0.0.0'
$$$ Got request example.com
$$$ Sending SOA
DATA    example.com IN  SOA 86400   1   ahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600
END

问题出在python的缓冲输入输出中。邮件列表用户给出了答案-更改行:

#!/usr/bin/python

#!/usr/bin/python -u

'-u'禁用缓冲。

最新更新