summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/admin.c3
-rw-r--r--mbbsd/announce.c5
-rw-r--r--mbbsd/bbs.c20
-rw-r--r--mbbsd/cal.c4
-rw-r--r--mbbsd/chicken.c20
-rw-r--r--mbbsd/edit.c4
-rw-r--r--mbbsd/mbbsd.c11
-rw-r--r--mbbsd/stuff.c20
-rw-r--r--mbbsd/talk.c4
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: �u��q���I�q�i��Ʀ�] */
- 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�t��ĵ��", "Cross-post", "�@��B��");
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:
+ ���F��� system calls , �{�b������e������� +1 �g�J .DIR ��.
+ �y��
+ 1.�Y�Ӥ��ɦW�Q��������, ����N�g�����ɦW�� (�y�����F��)
+ 2.�S�����sŪ�@��, �ҥH����ƥi��Q�ֺ�
+ 3.�Y�����ɭԫe��Q�R, �N�[���媺�����
+ */
setdirpath(path, direct, fhdr->filename);
- if( (fd = open(path, O_WRONLY | O_APPEND)) < 0 ){ // �u APPEND, �� CREAT
+ if( log_file(path, buf, 0) == -1 ){ // �� CREATE
vmsg("����/�v����");
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; /* ú���|�N�S�����F */
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, "�n�ۦ�Ѽg���]�U�ܡH[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�i�F�@���s\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�_�F �� %s", cuser.userid, mychicken->name,
+ "\033[m�_�F �� %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 ��F �� %s",
+ "\033[32m%s\033[m �� \033[36m%d\033[m ��F �� %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 �үk�R��\033[33m %s\033[32m %s "
- "\033[m���F �� %s",
+ "\033[m���F �� %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 ��k�R��\033[33m %s\033[32m %s "
- "\033[m��W��\033[33m %s\033[m �� %s",
+ "\033[m��W��\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)
/* �s��240��interval�@�� , �����O�b�İ]
if (count >= 240) {
char buf[200];
- snprintf(buf, sizeof(buf), "\033[1;33;46m%s\033[37m�b\033[37;45m%s"
+ snprintf(buf, sizeof(buf), "\033[1;33;46m%s\033[37m�b\033[37;45m%s\n"
"\033[37m�O�H�k�ȿ� , %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 �t��ĵ��", "�H�k�ȿ�", "�������k�ұo");
mail_violatelaw(cuser.userid, "Ptt �t��ĵ��", "�H�k�ȿ�", "�������k�ұo");
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);
/* �l�ܨϥΪ� */
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 ��..�ٳѤU %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');
}