summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-10-01 15:55:58 +0800
committervictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-10-01 15:55:58 +0800
commitd89cf5b0bc9c9ea0d36d8d128e87501c836d49f5 (patch)
tree4fbf48ebbf65de423afc342b6086ff8b3a75accb
parent3dd6dc48f21cf43074de9ab8b51abdb6ae67b389 (diff)
downloadpttbbs-d89cf5b0bc9c9ea0d36d8d128e87501c836d49f5.tar
pttbbs-d89cf5b0bc9c9ea0d36d8d128e87501c836d49f5.tar.gz
pttbbs-d89cf5b0bc9c9ea0d36d8d128e87501c836d49f5.tar.bz2
pttbbs-d89cf5b0bc9c9ea0d36d8d128e87501c836d49f5.tar.lz
pttbbs-d89cf5b0bc9c9ea0d36d8d128e87501c836d49f5.tar.xz
pttbbs-d89cf5b0bc9c9ea0d36d8d128e87501c836d49f5.tar.zst
pttbbs-d89cf5b0bc9c9ea0d36d8d128e87501c836d49f5.zip
solved a frequent race
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2216 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--mbbsd/gamble.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/mbbsd/gamble.c b/mbbsd/gamble.c
index 51fe99ef..d0e651e0 100644
--- a/mbbsd/gamble.c
+++ b/mbbsd/gamble.c
@@ -104,12 +104,24 @@ append_ticket_record(char *direct, int ch, int n, int count)
fprintf(fp, "%s %d %d\n", cuser.userid, ch, n);
fclose(fp);
}
- load_ticket_record(direct, ticket);
- ticket[ch] += n;
+
snprintf(genbuf, sizeof(genbuf), "%s/" FN_TICKET_RECORD, direct);
- if ((fp = fopen(genbuf, "w"))) {
+ if ((fp = fopen(genbuf, "w+"))) {
+
+ flock(fileno(fp), LOCK_EX);
+
+ for (i = 0; i < MAX_ITEM; i++)
+ if (fscanf(fp, "%9d ", &ticket[i]) != 1)
+ break;
+ ticket[ch] += n;
+
+ ftruncate(fileno(fp), 0);
+ rewind(fp);
for (i = 0; i < count; i++)
fprintf(fp, "%d ", ticket[i]);
+ fflush(fp);
+
+ flock(fileno(fp), LOCK_UN);
fclose(fp);
}
}
@@ -159,6 +171,7 @@ ticket(int bid)
ch_buyitem(price, "etc/buyticket", &n, 0);
if (bid && !dashf(fn_ticket)) {
+ // XXX 錢沒有退回
vmsg("哇!! 耐ㄚ捏...板主已經停止下注了 不能賭嚕");
break;
}