can't sysctlbyname(kern.safeboot)

size_t len = sizeof(int);

int safeboot = 0;

int ret;

ret = sysctlbyname("kern.safeboot", &safeboot, &len, NULL, 0);


This code always seems to fail; I've tried UInt32 as well, it always returns an error code of 1. Is there a way to figure out if my kext is running in safeboot? I need it to behave differently.

Accepted Reply

For anyone else dealing with this, the workaround was to parse the boot args for -x:


char namep[16];

if (PE_parse_boot_argn("-x", namep, sizeof (namep)))

{

// safe boot

}


Thanks, DTS!

Replies

it looks like that err is EPERM; is there any other way to tell if I'm in safe boot from kpi?

So it's looking like there must be no way to do this with the KPI, as nobody's responded with anything... normally this is something I'd do from userland, but in safe boot mode, no launch daemons or launch agents starts for me to connect to. Is there any good, safe code example somewhere to demonstrate how to spawn a new process from kernel space? I know some applications like VirtualBox do this, but I've been trying to avoid it if necessary. I suspect the only way to tell (reliably) if I'm in safe boot is to spawn a user process from the kernel, then have it pull this var for me. Open to any other suggestions.

Is there any good, safe code example somewhere to demonstrate how to spawn a new process from kernel space?

There is no supported way to do that.

Getting back to the safe boot issue, I took a quick look into this earlier and couldn’t find any good options. If you want someone to dig deeper into this, my recommendation is that you open a DTS tech support incident.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Yeah, did open one a few days ago... not sure how long it typically takes to hear back, but I've heard they usually have pretty ingenous ideas / workarounds.

Can you post the follow-up number you got? [Or, if you don’t want that public, email it to me; my address is in my signature.]

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

For anyone else dealing with this, the workaround was to parse the boot args for -x:


char namep[16];

if (PE_parse_boot_argn("-x", namep, sizeof (namep)))

{

// safe boot

}


Thanks, DTS!