From: Miloš Mulač Date: Fri, 9 Jun 2006 09:32:27 +0000 (+0000) Subject: add microseconds to filename to avoid two registrations in one second X-Git-Tag: gridsite-core_R_1_3_2~140 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=75e3ac281bf1b9291944659adf990a8b6b5ea325;p=jra1mw.git add microseconds to filename to avoid two registrations in one second (now two registrations in one usec, from one slave are very unlikely) --- diff --git a/org.glite.lb.common/src/lb_maildir.c b/org.glite.lb.common/src/lb_maildir.c index 14bda68..ede0b3d 100644 --- a/org.glite.lb.common/src/lb_maildir.c +++ b/org.glite.lb.common/src/lb_maildir.c @@ -78,6 +78,7 @@ int edg_wll_MaildirStoreMsg( written, msgsz, ct, i; + struct timeval tv; if ( !root ) root = DEFAULT_ROOT; @@ -90,9 +91,11 @@ int edg_wll_MaildirStoreMsg( snprintf(lbm_errdesc, MAX_ERR_LEN, "Maximum tries limit reached with unsuccessful file creation"); return -1; } - snprintf(fname, PATH_MAX, "%s/%s/%ld.%d.%s", root, dirs[LBMD_DIR_TMP], (long) time(NULL), getpid(), srvname); + gettimeofday(&tv,NULL); + snprintf(fname, PATH_MAX, "%s/%s/%ld.%ld_%d.%s", root, dirs[LBMD_DIR_TMP], + (long) tv.tv_sec, (long) tv.tv_usec, getpid(), srvname); if ( (fhnd = open(fname, O_CREAT|O_EXCL|O_WRONLY, 00600)) < 0 ) { - if ( errno == EEXIST ) { sleep(2); continue; } + if ( errno == EEXIST ) { /* hypothetic error */ continue; } snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't create file %s", fname); return -1; }