summaryrefslogtreecommitdiff
path: root/src/common/lock.c
diff options
context:
space:
mode:
authorMadCamel <madcamel@gmail.com>2009-08-21 13:35:28 -0400
committerMadCamel <madcamel@gmail.com>2009-08-21 13:35:28 -0400
commit44a76629cb297e949a8f8290e999504daffbda9e (patch)
treef3e795a060d5e1a06f30d09e8a174fddd03e5ead /src/common/lock.c
parentb51bc31600679344486d8e8cfe9d525e58bfc0bb (diff)
downloadtmwa-44a76629cb297e949a8f8290e999504daffbda9e.tar.gz
tmwa-44a76629cb297e949a8f8290e999504daffbda9e.tar.bz2
tmwa-44a76629cb297e949a8f8290e999504daffbda9e.tar.xz
tmwa-44a76629cb297e949a8f8290e999504daffbda9e.zip
Made temporary files more robust against race conditions
Diffstat (limited to 'src/common/lock.c')
-rw-r--r--src/common/lock.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/common/lock.c b/src/common/lock.c
index 67001f9..c584017 100644
--- a/src/common/lock.c
+++ b/src/common/lock.c
@@ -1,4 +1,5 @@
+#include <unistd.h>
#include <stdio.h>
#include "lock.h"
#include "socket.h"
@@ -10,12 +11,12 @@
FILE* lock_fopen(const char* filename,int *info) {
char newfile[512];
FILE *fp;
- int no = 0;
+ int no = getpid();
// 安全なファイル名を得る(手抜き)
do {
sprintf(newfile,"%s_%04d.tmp",filename,++no);
- } while((fp = fopen_(newfile,"r")) && (fclose_(fp), no<9999) );
+ } while((fp = fopen_(newfile,"r")) && (fclose_(fp), no<99999) );
*info = no;
return fopen_(newfile,"w");
}