如何在OSX上检测安全模式

时间:2014-07-23 17:45:12

标签: c macos

我有一些代码,如果用户没有以安全模式启动,我只想运行。有没有办法使用我可以检测到的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
}

1 个答案:

答案 0 :(得分:6)

您可以像这样使用sysctl

sysctl -n kern.safeboot

1模式下会safe boot,在正常模式下会0