linux-sysprog · intermediate · ~15 min

Does the handler auto-restart syscalls?

Test a flag bit in the sigaction flags word.

Challenge

sigaction's sa_flags word controls handler behaviour; the SA_RESTART bit makes interrupted slow syscalls resume instead of failing with EINTR. Test for it.

Task

Implement int restarts_syscalls(int flags) that returns 1 if the SA_RESTART bit is set in flags, else 0.

Input

  • flags: an sa_flags value (bitmask).

Output

1 if SA_RESTART is set, else 0.

Example

restarts_syscalls(SA_RESTART)   ->   1
restarts_syscalls(0)            ->   0

Input format

flags: an sa_flags bitmask.

Output format

1 if the SA_RESTART bit is set, else 0.

Starter code

#include <signal.h>

int restarts_syscalls(int flags) {
    /* TODO */
    return 0;
}

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