+ struct stat tmpstat;
+ char * tmpdir;
+ if ((0 == stat(tmpdir = getenv("TMPDIR"), &tmpstat)
+ && (S_ISDIR(tmpstat.st_mode)))
+ || ((0 == stat(tmpdir = (char*)P_tmpdir, &tmpstat))
+ && (S_ISDIR(tmpstat.st_mode)))
+ || ((0 == stat(tmpdir = (char*)"/tmp", &tmpstat))
+ && (S_ISDIR(tmpstat.st_mode))));
+ else goto error;
+ std::stringstream tmpname;
+ long int rnd = now ^ getpid();
+ do
+ {
+ srandom(rnd);
+ rnd = random();
+ tmpname << tmpdir << "/rmk-";
+ tmpname.fill('0');
+ tmpname.width(8);
+ tmpname << rnd;
+ }
+ while (access (tmpname.str().c_str(), F_OK) == 0);
+ socket_name = strdup(tmpname.str().c_str());