Apache CGI進程顯然無法創建共享內存? shmget()將返回EACCES,權限被拒絕錯誤。任何人都知道我能如何克服這個問題?我在Linux(Fedora 17 w/3.9.10-100內核)和Apache 2.2.23上運行。這是一個封閉的系統,所以我不關心這可能導致的安全漏洞。作爲Apache CGI程序運行的C++程序無法通過shmget訪問共享內存
下面是一個最小的CGI程序:
#include <iostream>
#include <string.h>
#include <sys/shm.h>
#include <errno.h>
using namespace std;
int main()
{
cout << "Content-Type: text/plain" << endl << endl;
if(shmget(0x1234, 1000, IPC_CREAT | 0666) < 0) {
cout << "Error: " << strerror(errno) << endl;
} else {
cout << "Success!" << endl;
}
return 0;
}
這裏是最小的HTML:
<html>
<body>
<form action="/cgi-bin/sscce" method="post">
<input type="submit" value="Go" id="submit"/>
</form>
</body>
</html>
這裏是一個命令行的結果:
$ ./run
Content-Type: text/plain
Success!
$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x000root 666 1000 0
$ ipcrm -m 29917185
$
這裏是結果通過Apache運行:
Content-Type: text/plain
Error: Permission denied
它正在返回EACCES。其他CGI的東西工作得很好。所以,事情我想:
- 改變Apache的運行是相同的用戶在命令行中(沒有幫助)
- 「使用chmod +的」關於可執行以root權限運行(沒有幫助)
- 「setcap cap_ipc_owner + IEP」的可執行文件(和也的httpd可執行文件),因爲聯機幫助頁shmget的()表示,它需要CAP_IPC_OWNER能力或將返回EACCES(沒有幫助)
我有點在我束手無策。不知何故,Apache正在剝離CGI腳本(甚至以root身份運行)創建大量共享內存的能力?谷歌搜索出現了一些其他經歷過這個問題的人,但沒有解決方案。此外,如果我預先創建共享內存,則會發生同樣的情況...... shmget()僅在嘗試從具有0666權限的共享內存進行連接讀取時返回EACCES。任何想法?提前致謝。