Replace os.getlogin() by our own helper

os.getlogin() returns the user of the controlling tty which doesn't
work when running headless (or gives an unexpected result on ssh+su)