If I understand this report correctly, the problem is just the spurious warning about XDG_RUNTIME_DIR? Instead of changing the functionality (which breaks other use cases, see my message to emacs-devel), wouldn't it make more sense to just suppress the warning if the variable is set? As in attached patch?