我有一些代码,如果用户没有以安全模式启动,我只想运行。有没有办法使用我可以检测到的CoreFoundation或C标准API?
编辑:感谢我接受的答案,这是我的代码:#include <sys/sysctl.h>
...
int safeBoot;
int mib_name[2] = { CTL_KERN, KERN_SAFEBOOT };
size_t length = sizeof(safeBoot);
if (!sysctl(mib_name, 2, &safeBoot, &length, NULL, 0)) {
if (safeBoot == 1) {
// We are in safe mode
} else {
// Normal mode. Continue…
}
} else {
// Couldn't find safe boot information
}
答案 0 :(得分:6)
您可以像这样使用sysctl
:
sysctl -n kern.safeboot
在1
模式下会safe boot
,在正常模式下会0
。