I think the problem is with the pflocal/io.c implementation of S_io_stat. emacsclient is trying to
compare the uid provided by geteuid with the uid in the stat buffer from calling fstat on the
file descriptor of a socket created with cloexec_socket (AF_UNIX, SOCK_STREAM, 0);. But
S_io_stat doesn't set uid.
memset (st, 0, sizeof (struct stat));
st->st_fstype = FSTYPE_SOCKET;
st->st_mode = sock->mode;
st->st_fsid = getpid ();
st->st_ino = sock->id;
/* As we try to be clever with large transfers, ask for them. */
st->st_blksize = vm_page_size * 16;
And because of that, it's defaulting to 0 (as determined by memset). The solution could be as
simple as adding
st->st_uid = geteuid(); // or something like that
to S_io_stat. But I'm still trying to figure out how to build and test it.
Andrew