]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: make it more robust to calculate timeout value
authorZhang Bo <oscar.zhangbo@huawei.com>
Mon, 25 May 2015 06:22:42 +0000 (14:22 +0800)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 27 May 2015 14:59:18 +0000 (16:59 +0200)
commit39d0396f398e321e98fcd0f9e9b7f78ced398bcb
tree9608ac0629d5b2e5172dce85b1e01f216bb06cd5
parentb071ec43471ec7de57339debc8622d03f2782a1b
util: make it more robust to calculate timeout value

When we change system clock to years ago, a certain CPU may use up 100% cputime.
The reason is that in function virEventPollCalculateTimeout(), we assign the
unsigned long long result to an INT variable,
        *timeout = then - now; // timeout is INT, and then/now are long long
        if (*timeout < 0)
            *timeout = 0;
there's a chance that variable @then minus variable @now may be a very large number
that overflows INT value expression, then *timeout will be negative and be assigned to 0.
Next the 'poll' in function virEventPollRunOnce() will get into an 'endless' while loop there.
thus, the cpu that virEventPollRunOnce() thread runs on will go up to 100%.

Although as we discussed before in https://www.redhat.com/archives/libvir-list/2015-May/msg00400.html
it should be prohibited to set-time while other applications are running, but it does
seems to have no harm to make the codes more robust.

Signed-off-by: Wang Yufei <james.wangyufei@huawei.com>
Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
src/util/vireventpoll.c