/* DF-0181 — host-side deadlock probe.
 *
 * Run AFTER the trigger.  Tries an unrelated sysctl read; if the
 * SYSCTL_XLOCK has been leaked (LK_EXCLUSIVE on every CPU held), this
 * blocks forever.  We arm a 5 s alarm and exit 99 on timeout.
 */
#include <sys/types.h>
#include <sys/sysctl.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>

static volatile sig_atomic_t alarmed;
static void on_alarm(int s){ alarmed = 1; }

int
main(void)
{
    signal(SIGALRM, on_alarm);
    alarm(5);
    int mib[2] = { CTL_KERN, KERN_OSRELEASE };
    char buf[64];
    size_t len = sizeof buf;
    int r = sysctl(mib, 2, buf, &len, NULL, 0);
    if (alarmed) _exit(99);
    if (r == 0) {
        printf("DF-0181 probe: sysctl read OK (kern.osreldate=%s)\n", buf);
        return 0;
    }
    perror("sysctl");
    return 1;
}
