diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-09-14 19:30:57 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-09-14 19:30:57 +0800 |
commit | e2e4bfa7a26b8b90d03b1e1167d24096e7ff9ea0 (patch) | |
tree | d7803e24a2aca264a386097e66b5824cd1942f8e | |
parent | 31b9bab65b95c6ccabff24b90fa80dc3a8344122 (diff) | |
download | pttbbs-e2e4bfa7a26b8b90d03b1e1167d24096e7ff9ea0.tar pttbbs-e2e4bfa7a26b8b90d03b1e1167d24096e7ff9ea0.tar.gz pttbbs-e2e4bfa7a26b8b90d03b1e1167d24096e7ff9ea0.tar.bz2 pttbbs-e2e4bfa7a26b8b90d03b1e1167d24096e7ff9ea0.tar.lz pttbbs-e2e4bfa7a26b8b90d03b1e1167d24096e7ff9ea0.tar.xz pttbbs-e2e4bfa7a26b8b90d03b1e1167d24096e7ff9ea0.tar.zst pttbbs-e2e4bfa7a26b8b90d03b1e1167d24096e7ff9ea0.zip |
* more robust check of SHM version and size
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4843 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | common/bbs/cache.c | 42 | ||||
-rw-r--r-- | include/cmbbs.h | 3 |
2 files changed, 33 insertions, 12 deletions
diff --git a/common/bbs/cache.c b/common/bbs/cache.c index e224e5f4..d202b61b 100644 --- a/common/bbs/cache.c +++ b/common/bbs/cache.c @@ -94,22 +94,42 @@ attach_shm(int shmkey, int shmsize) return shmptr; } +static void +shm_check_error() +{ + fprintf(stderr, "Please use the source code version corresponding to SHM,\n" + "or use ipcrm(1) command to clean share memory.\n"); + exit(1); +} + void -attach_SHM(void) +attach_check_SHM(int version, int SHM_t_size) { SHM = attach_shm(SHM_KEY, SHMSIZE); - if(SHM->version != SHM_VERSION) { - fprintf(stderr, "Error: SHM->version(%d) != SHM_VERSION(%d)\n", SHM->version, SHM_VERSION); - fprintf(stderr, "Please use the source code version corresponding to SHM,\n" - "or use ipcrm(1) command to clean share memory.\n"); - exit(1); + + // check main program -> common bbs library + if (version != SHM_VERSION) { + fprintf(stderr, "Error: version(%d) != SHM_VERSION(%d)\n", + version, SHM_VERSION); + shm_check_error(); + } + if (SHM_t_size != sizeof(SHM_t)) { + fprintf(stderr, "Error: SHM_t_size(%d) != sizeof(SHM_t)(%lu)\n", + SHM_t_size, sizeof(SHM_t)); + shm_check_error(); } - if(SHM->size != sizeof(SHM_t)) { - fprintf(stderr, "Error: SHM->size(%d) != sizeof(SHM_t)(%d)\n", SHM->size, sizeof(SHM_t)); - fprintf(stderr, "Please use the configuration corresponding to SHM,\n" - "or use ipcrm(1) command to clean share memory.\n"); - exit(1); + // check common bbs library -> SHM + if (SHM->version != SHM_VERSION) { + fprintf(stderr, "Error: SHM->version(%d) != SHM_VERSION(%d)\n", + SHM->version, SHM_VERSION); + shm_check_error(); } + if (SHM->size != sizeof(SHM_t)) { + fprintf(stderr, "Error: SHM->size(%d) != sizeof(SHM_t)(%lu)\n", + SHM->size, sizeof(SHM_t)); + shm_check_error(); + } + if (!SHM->loaded) /* (uhash) assume fresh shared memory is * zeroed */ exit(1); diff --git a/include/cmbbs.h b/include/cmbbs.h index 7ea98e7a..26f695fe 100644 --- a/include/cmbbs.h +++ b/include/cmbbs.h @@ -45,7 +45,8 @@ extern int stamplink(char *fpath, fileheader_t * fh); #define getbottomtotal(bid) SHM->n_bottom[bid-1] extern unsigned int safe_sleep(unsigned int seconds); extern void *attach_shm(int shmkey, int shmsize); -extern void attach_SHM(void); +#define attach_SHM() attach_check_SHM(SHM_VERSION, sizeof(SHM_t)) +extern void attach_check_SHM(int version, int SHM_t_size); extern void add_to_uhash(int n, const char *id); extern void remove_from_uhash(int n); extern int dosearchuser(const char *userid, char *rightid); |