summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-03-09 10:54:02 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-03-09 10:54:02 +0800
commita9ab0dab6e86c98cfb4fb80db1ba56d51a3c0daa (patch)
tree4d0298cfc9f25284f9a4ab923cae423b40366563 /util
parent085c9a93cf63c5511f28005deb06f8ba25c8b667 (diff)
downloadpttbbs-a9ab0dab6e86c98cfb4fb80db1ba56d51a3c0daa.tar
pttbbs-a9ab0dab6e86c98cfb4fb80db1ba56d51a3c0daa.tar.gz
pttbbs-a9ab0dab6e86c98cfb4fb80db1ba56d51a3c0daa.tar.bz2
pttbbs-a9ab0dab6e86c98cfb4fb80db1ba56d51a3c0daa.tar.lz
pttbbs-a9ab0dab6e86c98cfb4fb80db1ba56d51a3c0daa.tar.xz
pttbbs-a9ab0dab6e86c98cfb4fb80db1ba56d51a3c0daa.tar.zst
pttbbs-a9ab0dab6e86c98cfb4fb80db1ba56d51a3c0daa.zip
fix alignment and permission problems when USE_HUGETLB.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2583 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util')
-rw-r--r--util/uhash_loader.c50
-rw-r--r--util/userlist.c2
2 files changed, 28 insertions, 24 deletions
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