diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-12-07 19:48:42 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-12-07 19:48:42 +0800 |
commit | e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2 (patch) | |
tree | 6917e3ead4beec72534673b799b5e51add0a0519 /mbbsd | |
parent | f596ac6e290311dea6c2181816b7d096127696a8 (diff) | |
download | pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.tar pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.tar.gz pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.tar.bz2 pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.tar.lz pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.tar.xz pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.tar.zst pttbbs-e67dbfb410cb519dbd4ae3e0f3cd12aef46e48f2.zip |
use open() instead of fopen() in log_file()
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1405 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/admin.c | 3 | ||||
-rw-r--r-- | mbbsd/announce.c | 5 | ||||
-rw-r--r-- | mbbsd/bbs.c | 20 | ||||
-rw-r--r-- | mbbsd/cal.c | 4 | ||||
-rw-r--r-- | mbbsd/chicken.c | 20 | ||||
-rw-r--r-- | mbbsd/edit.c | 4 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 11 | ||||
-rw-r--r-- | mbbsd/stuff.c | 20 | ||||
-rw-r--r-- | mbbsd/talk.c | 4 |
9 files changed, 50 insertions, 41 deletions
diff --git a/mbbsd/admin.c b/mbbsd/admin.c index db28cb99..b1553f3c 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -974,7 +974,8 @@ scan_register_form(char *regfile, int automode, int neednum) "%s:%s:%s", fdata[5], fdata[3], uid); strncpy(muser.justify, genbuf, REGLEN); sethomefile(buf, muser.userid, "justify"); - log_file(buf, genbuf); + strncat(genbuf, "\n", sizeof(genbuf)); + log_file(buf, genbuf, 1); passwd_update(unum, &muser); if ((fout = fopen(logfile, "a"))) { diff --git a/mbbsd/announce.c b/mbbsd/announce.c index c316db20..f63c5730 100644 --- a/mbbsd/announce.c +++ b/mbbsd/announce.c @@ -914,7 +914,10 @@ a_menu(char *maintitle, char *path, int lastlevel) Fexit = 1; if (currstat == OSONG) { /* XXX: 只選歌未點歌可灌排行榜 */ - log_file(FN_USSONG, fhdr->title); + char buf[128]; + snprintf(buf, sizeof(buf), + "%s\n", fhdr->title); + log_file(FN_USSONG, buf, 1); } free(me.header); return FULLUPDATE; diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 8d1f4aca..a0385552 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -29,9 +29,9 @@ anticrosspost() char buf[200]; snprintf(buf, sizeof(buf), - "\033[1;33;46m%s \033[37;45mcross post 文章 \033[37m %s\033[m", + "\033[1;33;46m%s \033[37;45mcross post 文章 \033[37m %s\033[m\n", cuser.userid, ctime(&now)); - log_file("etc/illegal_money", buf); + log_file("etc/illegal_money", buf, 1); post_violatelaw(cuser.userid, "Ptt系統警察", "Cross-post", "罰單處份"); cuser.userlevel |= PERM_VIOLATELAW; @@ -1465,13 +1465,19 @@ do_add_recommend(char *direct, fileheader_t *fhdr, int ent, char *buf) { char path[256]; int fd; + /* + race here: + 為了減少 system calls , 現在直接用當前的推文數 +1 寫入 .DIR 中. + 造成 + 1.若該文檔名被換掉的話, 推文將寫至舊檔名中 (造成幽靈檔) + 2.沒有重新讀一次, 所以推文數可能被少算 + 3.若推的時候前文被刪, 將加到後文的推文數 + */ setdirpath(path, direct, fhdr->filename); - if( (fd = open(path, O_WRONLY | O_APPEND)) < 0 ){ // 只 APPEND, 不 CREAT + if( log_file(path, buf, 0) == -1 ){ // 不 CREATE vmsg("推薦/競標失敗"); return -1; } - write(fd, buf, strlen(buf)); - close(fd); if( fhdr->recommend < 100 ){ fileheader_t t; @@ -2542,9 +2548,9 @@ log_board(char *mode, time_t usetime) char buf[256]; if (usetime > 30) { - snprintf(buf, sizeof(buf), "USE %-20.20s Stay: %5ld (%s) %s", + snprintf(buf, sizeof(buf), "USE %-20.20s Stay: %5ld (%s) %s\n", mode, usetime, cuser.userid, ctime(&now)); - log_file(FN_USEBOARD, buf); + log_file(FN_USEBOARD, buf, 1); } } #endif diff --git a/mbbsd/cal.c b/mbbsd/cal.c index 37123a01..4d5bfe13 100644 --- a/mbbsd/cal.c +++ b/mbbsd/cal.c @@ -396,9 +396,9 @@ p_give() return 0; /* 繳完稅就沒錢給了 */ deumoney(searchuser(id), money - tax); demoney(-money); - snprintf(genbuf, sizeof(genbuf), "%s\t給%s\t%d\t%s", + snprintf(genbuf, sizeof(genbuf), "%s\t給%s\t%d\t%s\n", cuser.userid, id, money - tax, ctime(&now)); - log_file(FN_MONEY, genbuf); + log_file(FN_MONEY, genbuf, 1); genbuf[0] = 'n'; getdata(3, 0, "要自行書寫紅包袋嗎?[y/N]", genbuf, 2, LCECHO); mail_redenvelop(cuser.userid, id, money - tax, genbuf[0]); diff --git a/mbbsd/chicken.c b/mbbsd/chicken.c index 0c769fe7..7bb7e5ee 100644 --- a/mbbsd/chicken.c +++ b/mbbsd/chicken.c @@ -135,9 +135,9 @@ new_chicken() snprintf(buf, sizeof(buf), "\033[31m%s \033[m養了一隻叫\033[33m %s \033[m的 " - "\033[32m%s\033[m 於 %s", cuser.userid, + "\033[32m%s\033[m 於 %s\n", cuser.userid, mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); - log_file(CHICKENLOG, buf); + log_file(CHICKENLOG, buf, 1); mychicken->lastvisit = mychicken->birthday = mychicken->cbirth = now; mychicken->food = 0; mychicken->weight = time_change[(int)mychicken->type][WEIGHT] / 3; @@ -442,9 +442,9 @@ ch_kill() more(CHICKEN_PIC "/deadth", YEA); snprintf(buf, sizeof(buf), "\033[31m%s \033[m把 \033[33m%s\033[m\033[32m %s " - "\033[m宰了 於 %s", cuser.userid, mychicken->name, + "\033[m宰了 於 %s\n", cuser.userid, mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); - log_file(CHICKENLOG, buf); + log_file(CHICKENLOG, buf, 1); mychicken->name[0] = 0; } } @@ -500,10 +500,10 @@ ch_sell() getdata_str(23, 0, buf, ans, sizeof(ans), DOECHO, "N"); if (ans[0] == 'y') { snprintf(buf, sizeof(buf), "\033[31m%s\033[m 把 \033[33m%s\033[m " - "\033[32m%s\033[m 用 \033[36m%d\033[m 賣了 於 %s", + "\033[32m%s\033[m 用 \033[36m%d\033[m 賣了 於 %s\n", cuser.userid, mychicken->name, chicken_type[(int)mychicken->type], money, ctime(&now)); - log_file(CHICKENLOG, buf); + log_file(CHICKENLOG, buf, 1); mychicken->lastvisit = mychicken->name[0] = 0; passwd_update(usernum, &cuser); more(CHICKEN_PIC "/sell", YEA); @@ -657,11 +657,11 @@ deadtype(chicken_t * thechicken) if (thechicken == mychicken) { snprintf(buf, sizeof(buf), "\033[31m%s\033[m 所疼愛的\033[33m %s\033[32m %s " - "\033[m掛了 於 %s", + "\033[m掛了 於 %s\n", cuser.userid, thechicken->name, chicken_type[(int)thechicken->type], ctime(&now)); - log_file(CHICKENLOG, buf); + log_file(CHICKENLOG, buf, 1); mychicken->name[0] = 0; passwd_update(usernum, &cuser); } @@ -715,12 +715,12 @@ ch_changename() if (strlen(newname) >= 3 && strcmp(newname, mychicken->name)) { snprintf(buf, sizeof(buf), "\033[31m%s\033[m 把疼愛的\033[33m %s\033[32m %s " - "\033[m改名為\033[33m %s\033[m 於 %s", + "\033[m改名為\033[33m %s\033[m 於 %s\n", cuser.userid, mychicken->name, chicken_type[(int)mychicken->type], newname, ctime(&now)); strlcpy(mychicken->name, newname, sizeof(mychicken->name)); - log_file(CHICKENLOG, buf); + log_file(CHICKENLOG, buf, 1); } } diff --git a/mbbsd/edit.c b/mbbsd/edit.c index 10f33d33..bc94d5a9 100644 --- a/mbbsd/edit.c +++ b/mbbsd/edit.c @@ -1701,10 +1701,10 @@ vedit(char *fpath, int saveheader, int *islocal) /* 連續240個interval一樣 , 分明是在斂財 if (count >= 240) { char buf[200]; - snprintf(buf, sizeof(buf), "\033[1;33;46m%s\033[37m在\033[37;45m%s" + snprintf(buf, sizeof(buf), "\033[1;33;46m%s\033[37m在\033[37;45m%s\n" "\033[37m板違法賺錢 , %s\033[m", cuser.userid, currboard, ctime(&now)); - log_file("etc/illegal_money", buf); + log_file("etc/illegal_money", buf, 1); money = 0; post_violatelaw(cuser.userid, "Ptt 系統警察", "違法賺錢", "扣除不法所得"); mail_violatelaw(cuser.userid, "Ptt 系統警察", "違法賺錢", "扣除不法所得"); diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 028a91b6..1b932dad 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -99,11 +99,12 @@ reapchild(int sig) void log_user(char *msg) { - char filename[200]; + char filename[200], buf[200]; snprintf(filename, sizeof(filename), BBSHOME "/home/%c/%s/USERLOG", cuser.userid[0], cuser.userid); - log_file(filename, msg); + snprintf(buf, sizeof(buf), "%s\n", msg); + log_file(filename, msg, 1); } @@ -115,14 +116,14 @@ log_usies(char *mode, char *mesg) if (!mesg) snprintf(genbuf, sizeof(genbuf), cuser.userid[0] ? "%s %s %-12s Stay:%d (%s)" : - "%s %s %s Stay:%d (%s)", + "%s %s %s Stay:%d (%s)\n", Cdate(&now), mode, cuser.userid, (int)(now - login_start_time) / 60, cuser.username); else snprintf(genbuf, sizeof(genbuf), - cuser.userid[0] ? "%s %s %-12s %s" : "%s %s %s%s", + cuser.userid[0] ? "%s %s %-12s %s" : "%s %s %s%s\n", Cdate(&now), mode, cuser.userid, mesg); - log_file(FN_USIES, genbuf); + log_file(FN_USIES, genbuf, 1); /* 追蹤使用者 */ if (HAS_PERM(PERM_LOGUSER)) diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index 0970e58c..90294609 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -600,19 +600,17 @@ printdash(char *mesg) outch('\n'); } -int -log_file(char *filename, char *buf) +int log_file(char *fn, char *buf, int ifcreate) { - FILE *fp; - - if ((fp = fopen(filename, "a")) != NULL) { - fputs(buf, fp); - if (!strchr(buf, '\n')) - fputc('\n', fp); - fclose(fp); - return 0; - } else + int fd; + if( (fd = open(fn, O_APPEND | O_WRONLY | (ifcreate ? O_CREAT : 0))) < 0 ) + return -1; + if( write(fd, buf, strlen(buf)) < 0 ){ + close(fd); return -1; + } + close(fd); + return 0; } void diff --git a/mbbsd/talk.c b/mbbsd/talk.c index ec0fff2d..698d0d3c 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -2286,10 +2286,10 @@ userlist(void) prints("\033[44m 嗯..還剩下 %d 錢.." "\033[m", demoney(-ch)); snprintf(genbuf, sizeof(genbuf), - "%s\t給%s\t%d\t%s", cuser.userid, + "%s\t給%s\t%d\t%s\n", cuser.userid, uentp->userid, ch, ctime(&currutmp->lastact)); - log_file(FN_MONEY, genbuf); + log_file(FN_MONEY, genbuf, 1); mail_redenvelop(cuser.userid, uentp->userid, ch - give_tax(ch), 'Y'); } |