- static uns cnt = 0;
- char buf[20];
- sprintf(buf, "tmp/sem-%d-%d", getpid(), cnt++);
- sem_t *sem = sem_open(buf, O_CREAT, 0777, 0);
+ char buf[TEMP_FILE_NAME_LEN];
+ int mode, retry = 10;
+ sem_t *sem;
+ do
+ {
+ temp_file_name(buf, &mode);
+ sem = sem_open(buf, mode | O_CREAT, 0777, 0);
+ }
+ while (sem == (sem_t*) SEM_FAILED && errno == EEXIST && retry --);