- LOCK(&lock);
- for (; index < TMP_MAX; index++) {
- snprintf(s, l, "%s/%s-%d-%d", dir, pfx, pid, index);
- if (access(s, F_OK) != 0) {
- UNLOCK(&lock);
- return s;
- }
+ do {
+ clock_gettime(CLOCK_REALTIME, &ts);
+ n = ts.tv_nsec ^ (unsigned)&s ^ (unsigned)s;
+ snprintf(s, l, "%s/%s-%d-%d-%x", dir, pfx, pid, a_fetch_add(&index, 1), n);
+ } while (!access(s, F_OK) && try++<MAXTRIES);
+ if (try>=MAXTRIES) {
+ free(s);
+ return 0;