diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-02-04 21:12:42 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-02-04 21:12:42 +0800 |
commit | c2f38e91d221f96b7877c95becd9c5fbccbde03f (patch) | |
tree | ecd328d9f07ab6d7aeb86a0804c532490a30d957 /mbbsd/emaildb.c | |
parent | 3dd3ec79c7807da0c31411b6981fda8c23d77dab (diff) | |
download | pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.tar pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.tar.gz pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.tar.bz2 pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.tar.lz pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.tar.xz pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.tar.zst pttbbs-c2f38e91d221f96b7877c95becd9c5fbccbde03f.zip |
- emaildb: use fork to reduce memory wasting
- user: add more emaildb check
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3900 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/emaildb.c')
-rw-r--r-- | mbbsd/emaildb.c | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/mbbsd/emaildb.c b/mbbsd/emaildb.c index f60d85e8..fa057102 100644 --- a/mbbsd/emaildb.c +++ b/mbbsd/emaildb.c @@ -4,9 +4,8 @@ #define EMAILDB_PATH BBSHOME "/emaildb.db" -#if defined(__GLIBC__) -void __libc_freeres(); -#endif +// define FORK model to minimize memory usage. +#define FORK_MODEL static int emaildb_open(sqlite3 **Db) { int rc; @@ -26,9 +25,27 @@ static int emaildb_open(sqlite3 **Db) { int emaildb_check_email(char * email, int email_len) { int count = -1; + pid_t pid = -1; sqlite3 *Db = NULL; sqlite3_stmt *Stmt = NULL; +#ifdef FORK_MODEL + switch((pid = fork())) + { + case -1: // error + break; + + case 0: // child + break; + + default: + waitpid(pid, &count, 0); + count = WEXITSTATUS(count); + // vmsgf(ANSI_RESET "found %d emails", count); + return count; + } +#endif + if (emaildb_open(&Db) != SQLITE_OK) goto end; @@ -68,6 +85,9 @@ end: if (Db != NULL) sqlite3_close(Db); + if (pid == 0) + exit(count); + return count; } #endif @@ -75,6 +95,24 @@ end: int emaildb_update_email(char * userid, int userid_len, char * email, int email_len) { int ret = -1; + pid_t pid = -1; + +#ifdef FORK_MODEL + switch((pid = fork())) + { + case -1: // error + break; + + case 0: // child + break; + + default: + waitpid(pid, &ret, 0); + ret = WEXITSTATUS(ret); + return ret; + } +#endif + sqlite3 *Db = NULL; sqlite3_stmt *Stmt = NULL; @@ -100,10 +138,8 @@ end: if (Db != NULL) sqlite3_close(Db); -#if defined(__GLIBC__) - // seems like causing SEGV on localtime()? - // __libc_freeres(); // discovered by wens, to reduce internal cache caused by sqlite. -#endif + if (pid == 0) + exit(ret); return ret; } @@ -200,10 +236,6 @@ int main() if (Db != NULL) sqlite3_close(Db); -#if defined(__GLIBC__) - __libc_freeres(); // discovered by wens, to reduce internal cache caused by sqlite. -#endif - close(fd); return 0; } |