From a9ab0dab6e86c98cfb4fb80db1ba56d51a3c0daa Mon Sep 17 00:00:00 2001 From: in2 Date: Wed, 9 Mar 2005 02:54:02 +0000 Subject: fix alignment and permission problems when USE_HUGETLB. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2583 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- util/uhash_loader.c | 50 +++++++++++++++++++++++++++----------------------- util/userlist.c | 2 +- 2 files changed, 28 insertions(+), 24 deletions(-) (limited to 'util') diff --git a/util/uhash_loader.c b/util/uhash_loader.c index 0c7da6db..731d96a7 100644 --- a/util/uhash_loader.c +++ b/util/uhash_loader.c @@ -10,9 +10,12 @@ void load_uhash(void); SHM_t *SHM; -int main() { +int main() +{ +#ifndef USE_HUGETLB setgid(BBSGID); setuid(BBSUID); +#endif chdir(BBSHOME); load_uhash(); return 0; @@ -20,30 +23,33 @@ int main() { void load_uhash(void) { int shmid, err; - shmid = shmget(SHM_KEY, sizeof(SHM_t), + shmid = shmget(SHM_KEY, SHMSIZE, #ifdef USE_HUGETLB - SHM_HUGETLB | + SHM_HUGETLB | 0666 | +#else + 0600 #endif - IPC_CREAT | IPC_EXCL | 0600); + IPC_CREAT | IPC_EXCL); err = errno; - if( err == EEXIST) - shmid = shmget(SHM_KEY, sizeof(SHM_t), + if( err == EEXIST ) + shmid = shmget(SHM_KEY, SHMSIZE, #ifdef USE_HUGETLB - SHM_HUGETLB | + SHM_HUGETLB | 0666 | +#else + 0600 #endif - IPC_CREAT | 0600); - if (shmid < 0) - { + IPC_CREAT | IPC_EXCL); + + if( shmid < 0 ){ perror("shmget"); exit(1); } SHM = (void *) shmat(shmid, NULL, 0); - if (SHM == (void *) -1) - { + if( SHM == (void *)-1 ){ perror("shmat"); exit(1); } - if( err != EEXIST) { + if( err != EEXIST ) { SHM->number=SHM->loaded = 0; SHM->version = SHM_VERSION; } @@ -56,16 +62,14 @@ void load_uhash(void) { } // in case it's not assumed zero, this becomes a race... - if(SHM->number==0 && SHM->loaded == 0) - { - SHM->loaded = 0; - fill_uhash(0); - SHM->loaded = 1; - } - else - { - fill_uhash(1); - } + if( SHM->number == 0 && SHM->loaded == 0 ){ + SHM->loaded = 0; + fill_uhash(0); + SHM->loaded = 1; + } + else{ + fill_uhash(1); + } } void checkhash(int h) diff --git a/util/userlist.c b/util/userlist.c index cecc3ee6..8c701478 100644 --- a/util/userlist.c +++ b/util/userlist.c @@ -6,7 +6,7 @@ SHM_t *SHM; int main(int argc, char **argv) { int i, shm, counter; - shm = shmget(SHM_KEY, USHM_SIZE, + shm = shmget(SHM_KEY, SHMSIZE, #ifdef USE_HUGETLB SHM_HUGETLB | #endif -- cgit v1.2.3