src/shared: import more code cleanups from upstream

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