linux-sysprog · intermediate · ~15 min

Is the handler body safe?

Enforce the 'only set a flag' handler discipline.

Challenge

A handler op trace uses 's' (set a volatile sig_atomic_t flag — safe) and 'p' (call printf — unsafe). Implement int handler_is_safe(const char *ops) returning 1 only if every op is 's'.

Starter code

int handler_is_safe(const char *ops) {
    /* TODO */
    return 1;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.