C 程序运行为Apache CGI程序无法通过SHMGET访问共享存储器
C++ program running as Apache CGI program cannot access shared memory via shmget
apache CGI流程显然无法创建共享内存?shmget()将返回eacces,权限拒绝错误。有人知道我怎么能克服这个问题吗?我正在Linux(Fedora 17 W/3.9.10-100内核)和Apache 2.2.23上运行。这是在关闭的系统上,所以我真的不在乎这可能导致的安全孔。
这是一个最小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
0x00001234 29917185 root 666 1000 0
$ ipcrm -m 29917185
$
这是通过apache运行的结果:
Content-Type: text/plain
Error: Permission denied
它正在返回eacces。其他CGI的东西效果很好。所以,我尝试的事情:
- 将Apache更改为与命令行一样运行的用户(无帮助)
- " Chmod s"在可执行文件上以使用根本权限(无帮助)
- " setCap cap_ipc_owner iep"在可执行文件上(以及httpd operutable上),因为shmget()的manpage()表示它需要cap_ipc_owner功能,或者将返回eacces(无帮助)
我有点努力。不知何故,Apache正在剥夺CGI脚本(甚至作为根部运行)创建共享内存的一部分的能力吗?谷歌搜索出来的其他几个遇到了这个问题但没有解决方案的人。另外,如果我预先创建共享内存... shmget()返回eacces时,也会发生同样的事情。预先感谢。
好的,终于自己发现了答案。问题是Selinux。在/var/log/消息:
SELinux is preventing <executable> from using the sys_resource capability.
通过编辑/etc/sysconfig/selinux关闭SELINUX允许CGI进程使用SHMGET()成功。但是,我不知道关闭Selinux的全部后果。在我们的封闭系统上,我认为这没什么大不了的,但是对于其他情况,可能有一个较小的锤子解决方案。但这是头的一般方向。希望它有时会帮助某人。
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- C++,系统无法执行指定的程序
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 重载操作程序时出错>>用于类中的字符串 memebr
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 试图在visual studio上用C++创建一个桌面应用程序
- 模板元程序查找相似的连续类型名称
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 如何通过cpp程序运行shell脚本
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- IPC使用多个管道和分支进程来运行Python程序
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 基于boost的程序的静态链接——zlib问题
- 程序崩溃并显示"std::out_of_range"错误
- 在C应用程序中运行C++(带有STL)函数
- 使用mongocxx驱动程序时包含头文件问题
- C 程序运行为Apache CGI程序无法通过SHMGET访问共享存储器