summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2006-03-23 02:00:02 +0800
committerkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2006-03-23 02:00:02 +0800
commit5f8b21df87a664c9880c3ab481ae37e2537c2c69 (patch)
treec3552a7bcadca9d774364ab16fe35c812198e334 /mbbsd
parent85e551026c0b73f77ed38804c5785edb36481e2b (diff)
downloadpttbbs-5f8b21df87a664c9880c3ab481ae37e2537c2c69.tar
pttbbs-5f8b21df87a664c9880c3ab481ae37e2537c2c69.tar.gz
pttbbs-5f8b21df87a664c9880c3ab481ae37e2537c2c69.tar.bz2
pttbbs-5f8b21df87a664c9880c3ab481ae37e2537c2c69.tar.lz
pttbbs-5f8b21df87a664c9880c3ab481ae37e2537c2c69.tar.xz
pttbbs-5f8b21df87a664c9880c3ab481ae37e2537c2c69.tar.zst
pttbbs-5f8b21df87a664c9880c3ab481ae37e2537c2c69.zip
dirty workaround for race condition in multi-login checking.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3300 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/mbbsd.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c
index 5de68ea1..84233efc 100644
--- a/mbbsd/mbbsd.c
+++ b/mbbsd/mbbsd.c
@@ -517,43 +517,56 @@ write_request(int sig)
#endif
}
+static userinfo_t*
+getotherlogin(void)
+{
+ userinfo_t *ui;
+ if (!(ui = (userinfo_t *) search_ulist(usernum)))
+ return NULL; /* user isn't logged in */
+
+#ifdef DEBUGSLEEP
+ /* skip sleeping process */
+ while (ui->pid &&
+ (ui->uid == usernum && ui->mode == DEBUGSLEEPING))
+ ui++;
+
+ if(ui->uid != usernum)
+ return NULL;
+#endif
+ return ui;
+}
+
static void
multi_user_check(void)
{
register userinfo_t *ui;
- register pid_t pid;
char genbuf[3];
if (HasUserPerm(PERM_SYSOP))
return; /* don't check sysops */
if (cuser.userlevel) {
- if (!(ui = (userinfo_t *) search_ulist(usernum)))
- return; /* user isn't logged in */
-
-#ifdef DEBUGSLEEP
- /* skip sleeping process */
- while (ui->pid &&
- (ui->uid == usernum && ui->mode == DEBUGSLEEPING))
- ui++;
-
- if(ui->uid != usernum)
+ ui = getotherlogin();
+ if(ui == NULL)
return;
-#endif
-
- pid = ui->pid;
- if (!pid /* || (kill(pid, 0) == -1) */ )
+ if (!ui->pid /* || (kill(pid, 0) == -1) */ )
return; /* stale entry in utmp file */
getdata(b_lines - 1, 0, "您想刪除其他重複的 login (Y/N)嗎?[Y] ",
genbuf, 3, LCECHO);
if (genbuf[0] != 'n') {
- if (pid > 0)
- kill(pid, SIGHUP);
+ // race condition here, sleep may help..?
+ usleep(random()%1000000+100000); // 0.1~1.1s
+ // scan again, old ui may be invalid
+ ui = getotherlogin();
+ if(ui == NULL)
+ return;
+ if (ui->pid > 0)
+ kill(ui->pid, SIGHUP);
log_usies("KICK ", cuser.nickname);
} else {
- /* what are we doing here? magic number 3? */
+ /* deny login if still have 3 */
if (search_ulistn(usernum, 3) != NULL)
abort_bbs(0); /* Goodbye(); */
}