centos7 cgi 挂载文件系统失败,求教!
本帖最后由 yaoyefengyun 于 2015-08-06 15:36 编辑kvm虚拟机、cenots7、virtio磁盘
使用yum安装系统自带httpd
手动挂载正常,手动执行自己写的程序挂载也正常,但通过cgi执行挂载时失败。
程序加了s权限,设置了uid,关闭了selinux,不知道是不是需要修改httpd配置文件。
具体代码如下:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/mount.h>
int main(int argc, char **argv)
{
uid_t uid;
gid_t gid;
printf("Content-Type: text/plain\n\n");
if (argc != 4) {
printf("usage: mymount <filesystem> <mounted> <type>\n");
exit(EXIT_FAILURE);
}
if (setuid(0) == -1) {
printf("%s\n", strerror(errno));
exit(EXIT_FAILURE);
}
if (setgid(0) == -1) {
printf("%s\n", strerror(errno));
exit(EXIT_FAILURE);
}
uid = getuid();
gid = getgid();
printf("uid: %d, gid: %d\n", uid, gid);
printf("mount(%s, %s, %s, 0, NULL)\n", argv, argv, argv);
if (mount(argv, argv, argv, 0, NULL) == -1) {
printf("%s\n", strerror(errno));
exit(EXIT_FAILURE);
}
return 0;
}
重启系统后,通过浏览器第一次执行 .../mymount?/dev/vdf1+/mnt/vdf1+xfs 结果:
uid: 0, gid: 0
mount(/dev/vdf1, /mnt/vdf1, xfs, 0, NULL)
再次执行则出现如下结果:
uid: 0, gid: 0
mount(/dev/vdf1, /mnt/vdf1, xfs, 0, NULL)
Device or resource busy
再刷新网页结果相同
但这时,手动执行该程序,却能成功挂载。这一般来说是什么原因造成的啊? yaoyefengyun 发表于 2015-08-06 15:34 static/image/common/back.gif
kvm虚拟机、cenots7、virtio磁盘
使用yum安装系统自带httpd
先umount,再mount啊 我尝试过了,umount时提示:umount: /dev/mapper/p0-volume3: not mounted,这样的信息;
这时候手动mount却能够挂载上,手动执行自己写的这个程序也可以,但就是通过网页(cgi)来执行就会出现:mount: Device or resource busy;
感觉像是没有权限,或者httpd配置文件没配置正确?
回复 2# 流氓无产者
服务器对/mnt/vdf1没有权限回复 1# yaoyefengyun
搞定了,是systemd造成的,将/usr/lib/systemd/system/httpd.service中 PrivateTmp=true 注释掉或者改为false即可。
页:
[1]