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 /common/bbs | |
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
Diffstat (limited to 'common/bbs')
-rw-r--r-- | common/bbs/cache.c | 42 |
1 files changed, 31 insertions, 11 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); |