Signed-off-by: Anton Khirnov <anton@khirnov.net>
Based on the code by Luca Barbato <lu_zero@gentoo.org> and Yukinori Yamazoe <drocon11@gmail.com>.