【发布时间】:2016-01-13 19:53:56
【问题描述】:
以下代码生成核心转储文件:
#include <iostream>
#include <string>
#include <pwd.h>
#include <grp.h>
#include <sys/resource.h>
int main() {
int b = 0;
int a = 140/b;
return 0;
}
输出:Floating point exception (core dumped)
Coredump 生成在/opt/cores
$ ls -al /opt/cores
total 188
drwxrwxrwx 2 root root 4096 Jan 13 16:46 .
drwxr-xr-x 28 root root 4096 Jan 12 11:57 ..
-rw------- 1 root root 344064 Jan 13 16:46 core.prueba.6776.8
但是,这不会生成核心转储文件:
#include <iostream>
#include <string>
#include <pwd.h>
#include <grp.h>
#include <sys/resource.h>
int main() {
std::string usr = "nobody";
std::string grp = "oinstall";
group* gp = getgrnam(grp.data());
passwd* user = getpwnam(usr.data());
if (gp && user && setgid(gp->gr_gid) == 0 && setuid(user->pw_uid) == 0) {
std::cout << "changed!" << std::endl;
} else {
std::cout << "not changed =(" << std::endl;
}
struct rlimit rlim;
rlim.rlim_cur = RLIM_INFINITY;
rlim.rlim_max = RLIM_INFINITY;
if (setrlimit(RLIMIT_CORE, &rlim) != 0) {
std::cout << "setrlimit error" << std::endl;
}
getrlimit(RLIMIT_CORE, &rlim);
std::cout << "rlim_cur: " << (int)rlim.rlim_cur <<", rlim_max: " << (int)rlim.rlim_max << std::endl;
int b = 0;
int a = 140/b;
return 0;
}
输出:
changed!
rlim_cur: -1, rlim_max: -1
Floating point exception
我已经用更改的用户运行了第一段代码,它生成了 coredump 文件,因此该目录具有正确的权限。问题是当我在代码中更改用户时。有什么线索吗?
这发生在 Linux(CentOS 6、CentOS 7、RHEL 6)上。
在 Solaris 中工作正常。
【问题讨论】:
-
是的,我在问题 (777) 中显示了权限。也许与此有关:stackoverflow.com/questions/17204782/…
标签: core