如何在OSX上检测安全模式
我有一些代码,如果用户没有以安全模式启动,我只想运行。 有没有办法使用我可以检测到的CoreFoundation或C标准API?
编辑:感谢我接受的答案,这是我的代码:
#include ... 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 }
您可以像这样使用sysctl
:
sysctl -n kern.safeboot
它在safe boot
模式下为1
,在正常模式下为0
。