提交 d7dd4e1f 编写于 作者: M Michal Privoznik

nss: Don't fail on empty files

Before we rewrote nss plugin so that it doesn't use libvirt's
internal functions it used virLeaseReadCustomLeaseFile() to parse
.status files. After the rewrite it's using read() + yajl_parse()
+ yajl_complete_parse(). There's one catch though,
virLeaseReadCustomLeaseFile() skipped over empty files.

An empty .status file is created when a network is started. This
is because we configure dnsmasq to use our leasehelper. So the
first thing it does it calls it as follows:

  DNSMASQ_INTERFACE=virbr0 /usr/libexec/libvirt_leaseshelper init

which causes the leasehelper to create empty virbr0.status file.
If there is only one libvirt network then that is no problem -
there are no other .status files to parse anyway. But if there
are two or more networks then the first empty .status file causes
whole parsing process and subsequently the whole name lookup
process to fail.

Fixes: v5.7.0-rc1~343
Reported-by: NPavel Hrdina <phrdina@redhat.com>
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 8d9ca128
......@@ -379,6 +379,7 @@ findLeases(const char *file,
};
yajl_handle parser = NULL;
char line[1024];
ssize_t nreadTotal = 0;
int rv;
if ((fd = open(file, O_RDONLY)) < 0) {
......@@ -398,6 +399,7 @@ findLeases(const char *file,
goto cleanup;
if (rv == 0)
break;
nreadTotal += rv;
if (yajl_parse(parser, (const unsigned char *)line, rv) !=
yajl_status_ok) {
......@@ -409,7 +411,8 @@ findLeases(const char *file,
}
}
if (yajl_complete_parse(parser) != yajl_status_ok) {
if (nreadTotal > 0 &&
yajl_complete_parse(parser) != yajl_status_ok) {
ERROR("Parse failed %s",
yajl_get_error(parser, 1, NULL, 0));
goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册