Repository: zellij-org/zellij (language: rust)

Issue:
zellij sessions sockets may get deleted
zellij places its server sockets in XDG_RUNTIME_DIR.
Per specification*, this directory may be cleaned of old files periodically, and I suspect at least one user on discord lost access to his session this way.
The problem can be solved in two ways, ideally we do both:
- set the sticky bit on the socket file to avoid automatic cleanup *
- provide a method to recreate the socket file, e.g. on SIGUSR1

*Sources:
https://wiki.archlinux.org/title/XDG_Base_Directory#User_directories
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html


Discussion / hints:
Oh yeah, I was the user :D 

Fix patch:
diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs
index ac1b268d47..61f0c7667b 100644
--- a/zellij-server/src/lib.rs
+++ b/zellij-server/src/lib.rs
@@ -275,7 +275,10 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
             move || {
                 drop(std::fs::remove_file(&socket_path));
                 let listener = LocalSocketListener::bind(&*socket_path).unwrap();
-                set_permissions(&socket_path, 0o700).unwrap();
+                // set the sticky bit to avoid the socket file being potentially cleaned up
+                // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html states that for XDG_RUNTIME_DIR:
+                // "To ensure that your files are not removed, they should have their access time timestamp modified at least once every 6 hours of monotonic time or the 'sticky' bit should be set on the file. "
+                set_permissions(&socket_path, 0o1700).unwrap();
                 for stream in listener.incoming() {
                     match stream {
                         Ok(stream) => {


Test patch: