summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--include/pttstruct.h6
-rw-r--r--mbbsd/cache.c2
-rwxr-xr-xsample/pttbbs.sh1
-rw-r--r--util/uhash_loader.c50
-rw-r--r--util/userlist.c2
5 files changed, 36 insertions, 25 deletions
diff --git a/include/pttstruct.h b/include/pttstruct.h
index ec740c2c..045de383 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -577,6 +577,12 @@ typedef struct {
#endif
} SHM_t;
+#ifdef USE_HUGETLB // 4MB aligned
+# define SHMSIZE (sizeof(SHM_t)/(1048576*4)+1)*1048576*4
+#else
+# define SHMSIZE (sizeof(SHM_t))
+#endif
+
typedef struct {
unsigned char oldlen; /* previous line length */
unsigned char len; /* current length of line */
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index d32d7f15..8ad9f2e8 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -68,7 +68,7 @@ attach_shm(int shmkey, int shmsize)
void
attach_SHM(void)
{
- SHM = attach_shm(SHM_KEY, sizeof(SHM_t));
+ 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"
diff --git a/sample/pttbbs.sh b/sample/pttbbs.sh
index 2aa200cb..d8b87f6b 100755
--- a/sample/pttbbs.sh
+++ b/sample/pttbbs.sh
@@ -6,6 +6,7 @@
case "$1" in
start)
# 初始化 shared-memory, 載入 uhash, utmpsortd, timed(if necessary)
+ # 如果使用 USE_HUGETLB 的話請用 root 跑 shmctl init
/usr/bin/su -fm bbs -c '/home/bbs/bin/shmctl init'
# 寄信至站外
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