diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2014-03-25 18:11:05 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2014-03-25 18:11:05 +0800 |
commit | e4f9dee49d4c9fa4239a765a548e26ce200c5be6 (patch) | |
tree | 58e2f978b529467fb7326ee37b099ad1764514d3 | |
parent | a765c2a83a8fe8430f04d0c622772a90f97574c0 (diff) | |
download | pttbbs-e4f9dee49d4c9fa4239a765a548e26ce200c5be6.tar pttbbs-e4f9dee49d4c9fa4239a765a548e26ce200c5be6.tar.gz pttbbs-e4f9dee49d4c9fa4239a765a548e26ce200c5be6.tar.bz2 pttbbs-e4f9dee49d4c9fa4239a765a548e26ce200c5be6.tar.lz pttbbs-e4f9dee49d4c9fa4239a765a548e26ce200c5be6.tar.xz pttbbs-e4f9dee49d4c9fa4239a765a548e26ce200c5be6.tar.zst pttbbs-e4f9dee49d4c9fa4239a765a548e26ce200c5be6.zip |
Update using ulist.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5960 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/util/update_online.c | 91 |
1 files changed, 60 insertions, 31 deletions
diff --git a/pttbbs/util/update_online.c b/pttbbs/util/update_online.c index 0be7cafd..dfb42568 100644 --- a/pttbbs/util/update_online.c +++ b/pttbbs/util/update_online.c @@ -3,45 +3,74 @@ /* Update user online info. */ -int check(void *data GCC_UNUSED, int n, userec_t *u) +static int verbose = 0; + +void fastcheck() { - time4_t now; - userinfo_t *utmp; - if (!u->userid[0] || - (u->userlevel & PERM_VIOLATELAW) || - !(u->userlevel & PERM_LOGINOK)) - return 0; - - utmp = search_ulistn(n + 1, 1); - if (utmp == NULL) - return 0; - - // If the process does not exist... - if (utmp->pid <= 0 || kill(utmp->pid, 0) != 0) - return 0; - - // TODO how to make sure the UTMP has already logged? - now = (time4_t)time(0); - - /* user still online, let's mock it. */ - if (u->lastlogin + DAY_SECONDS <= now) - return 0; - - fprintf(stderr, "."); - u->lastlogin = now; - u->numlogindays++; - passwd_update(n + 1, u); - return 0; + int i, sorted[USHM_SIZE], last_uid = -1; + userec_t urec; + userinfo_t u; + + assert(sizeof(sorted) == sizeof(**SHM->sorted)); + memcpy(sorted, SHM->sorted[SHM->currsorted][7], + sizeof(sorted)); + for (i = 0; i < USHM_SIZE; i++) { + if (sorted[i] < 0 || sorted[i] >= USHM_SIZE) + continue; + memcpy(&u, SHM->uinfo + sorted[i], sizeof(u)); + if (u.mode == DEBUGSLEEPING || + !u.userid[0] || + (u.userlevel & PERM_VIOLATELAW) || + !(u.userlevel & PERM_LOGINOK) || + u.pid <= 0 || + kill(u.pid, 0) != 0) + continue; + if (last_uid == u.uid) + continue; + + // Found new online user. + passwd_query(u.uid, &urec); + if (strcmp(urec.userid, u.userid) != 0) { + if (verbose) + fprintf(stderr, "warning: UTMP (%s) does not match PW(%s).\n", + u.userid, urec.userid); + continue; + } + last_uid = u.uid; + if (verbose) + fprintf(stderr, "checking: %s (%s)\n", urec.userid, Cdatelite(&urec.lastlogin)); + + /* user still online, let's mock it. */ + if (now < urec.lastlogin + DAY_SECONDS) + continue; + + if (verbose) + fprintf(stderr, "update: %s (%s, %d) ->", urec.userid, + Cdatelite(&urec.lastlogin), urec.numlogindays); + urec.lastlogin = now; + urec.numlogindays++; + if (verbose) + fprintf(stderr, "(%s, %d).\n", Cdatelite(&urec.lastlogin), urec.numlogindays); + passwd_update(last_uid, &urec); + } } int main(int argc GCC_UNUSED, char **argv GCC_UNUSED) { + const char *prog = argv[0]; + while (argc > 1) { + if (strcmp(argv[1], "-v") == 0) { + verbose++; + argc--, argv++; + } else { + fprintf(stderr, "usage: %s [-v]\n", prog); + return -1; + } + } now = time(NULL); chdir(BBSHOME); attach_SHM(); - if(passwd_init()) - exit(1); - passwd_fast_apply(NULL, check); + fastcheck(); return 0; } |