xauth has window when there is no usable XAUTHORITY file or can abort destroying the XAUTHORITY file
The following command sequence (on Solaris) demonstrates the issue; but the equivalent sequence on Linux also shows the problem.
XAUTHORITY=/tmp/junk
export XAUTHORITY
touch $XAUTHORITY
truss xauth add ALL:34 MIT-MAGIC-COOKIE-1 a1a64cb8296b0988852ebbb6bc18be08 2>&1 | grep junk
the output from the truss | grep is...
stat("/tmp/junk-c", 0xFFBFEB70) Err#2 ENOENT
open("/tmp/junk-c", O_WRONLY|O_CREAT|O_EXCL, 0600) = 3
link("/tmp/junk-c", "/tmp/junk-l") = 0
access("/tmp/junk", F_OK) = 0
access("/tmp/junk", W_OK) = 0
open("/tmp/junk", O_RDONLY) = 3
unlink("/tmp/junk-n") Err#2 ENOENT
open("/tmp/junk-n", O_WRONLY|O_CREAT|O_EXCL, 0600) = 4
unlink("/tmp/junk") = 0
##############################################################
link("/tmp/junk-n", "/tmp/junk") = 0
unlink("/tmp/junk-n") = 0
unlink("/tmp/junk-c") = 0
unlink("/tmp/junk-l") = 0
where the line of ####s
is is a window during which the XAUTHORITY file does not exist so X applications that attempt to start in this window fail because that cannot determine a valid X authority. Also, if the xauth is terminated (EG SIGKILL) at this point no usable XAUTHORITY file remains
Perhaps the link() that follows the #####s should be a rename() to ensure that the XAUTHORITY file is never not present