如何在OSX上检测安全模式

Ale*_*ski 7 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
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*ell 6

你可以sysctl像这样使用:

sysctl -n kern.safeboot
Run Code Online (Sandbox Code Playgroud)

1safe boot模式下和0正常模式下给出.