During development or testing, it's often inconvenient that you can't try a new version of wsl2-ssh-agent unless you manually stop the existing daemon process using wsl2-ssh-agent -stop.
I want to add a small hack that uses signal-based communication to detect whether an existing wsl2-ssh-agent process is running and whether it is the same version. Specifically:
- On startup, if an existing daemon process is found, send
SIGUSR1 to that process and wait for SIGUSR2.
- When
SIGUSR1 is received, compute the FNV hash of /proc/self/exe and send SIGUSR2 back to the sender process along with the hash value.
- When
SIGUSR2 is received, compare the hash value with the one computed locally. If they match, exit; if they differ, terminate the existing process with SIGINT and take over as the new daemon.
Since this communication will likely occur on every execution when invoked from .bashrc or similar, we should evaluate the performance impact carefully.
During development or testing, it's often inconvenient that you can't try a new version of
wsl2-ssh-agentunless you manually stop the existing daemon process usingwsl2-ssh-agent -stop.I want to add a small hack that uses signal-based communication to detect whether an existing
wsl2-ssh-agentprocess is running and whether it is the same version. Specifically:SIGUSR1to that process and wait forSIGUSR2.SIGUSR1is received, compute the FNV hash of/proc/self/exeand sendSIGUSR2back to the sender process along with the hash value.SIGUSR2is received, compare the hash value with the one computed locally. If they match, exit; if they differ, terminate the existing process withSIGINTand take over as the new daemon.Since this communication will likely occur on every execution when invoked from .bashrc or similar, we should evaluate the performance impact carefully.