@mitu
I don't know why that error occurs, I don't think RetroArch uses directly this env var - may be a Wayland/screensaver warning.
So I fixed that error regarding XDG_RUNTIME_DIR, maybe RetroArch does use it after all. I was mistaken when I said it flashed up when launching, it actually flashes up when exiting! Same for the CD-ROM warning.
To solve it, I did the following:
run:
sudo sudo -V
scrolled up a bit to see which environment variables are preserved. XDG_RUNTIME_DIR is not one of them.
I then had to edit the sudoers file (sudo visudo) and add the following in:
Defaults env_keep += "XDG_RUNTIME_DIR"
Save and exit, you can then run 'sudo sudo -V' again and you'll see XDG_RUNTIME_DIR is in the list of environment variables to preserve. Reboot the system and the error should go away when quitting Retroarch.
For whatever reason, sudo does not preserve this environment variable, and i'm guessing because Retroarch launches from the Retropie menu with root privileges, it cannot see or have access to this environment variable. Adding the above in preserves it, suppressing the error (after a reboot).
The CD error still pops up though, but not much that can be done about that at this time it seems.
FYI, this error only pops up when you quit Retroarch after launching it on its own from the Retropie menu - it doesn't come up when quitting out of a game. I guess this is because games are launched as the 'pi' user, rather than with root privileges.
My question would be, is there a reason Retroarch needs to be launched with root privileges from the Retropie menu? Maybe I am misunderstanding how it launches, but that is what it looks like to me.
Cheers!