src/shared: refactor shared code

Signed-off-by: Anthony G. Basile <blueness@gentoo.org>