netatalk  4.6.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
faultinject.c File Reference

Fault-injection framework for the afpdtest unit harness. More...

#include "faultinject.h"
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

Functions

void fault_inject_reset (void)
int faultinject_open_works (const char *scratch_path)
 Is the LD_PRELOAD open() interposer active on this platform?

Variables

struct fault_inject fi

Detailed Description

Fault-injection framework for the afpdtest unit harness.

One source, two roles selected by -DFAULTINJECT_PRELOAD:

  • Linked into the afpdtest executable (no define): provides the fi control block and fault_inject_reset(). A test arms a failure on fi right before the operation under test and disarms it right after.
  • Built as libfaultinject.so (-DFAULTINJECT_PRELOAD) and loaded via LD_PRELOAD: interposes open/close/fcntl/fchdir at dynamic-symbol resolution, so calls made INSIDE libatalk.so (ad_open/ad_close/ad_lock/…) are intercepted — which a link-time –wrap on the executable cannot reach, because libatalk is a shared library. The interposer references the fi block exported by the executable (export_dynamic), forwarding to the real libc symbol via dlsym(RTLD_NEXT) unless a failure is armed.

Trigger model (countdown + errno): the per-call "armed" flag enables interception; "fail_after" = N lets the next N armed calls succeed and fails call N+1 once, with the per-call "errno". Because LD_PRELOAD interposition is global, the armed flag MUST be set only around the operation under test (and cleared with fault_inject_reset()), or unrelated infrastructure calls get hit.

Interception is not reliable on every platform (notably macOS's two-level namespace ignores plain symbol preloads); the self-test probes whether it works and dependent tests skip when it does not.

Function Documentation

◆ fault_inject_reset()

void fault_inject_reset ( void )

◆ faultinject_open_works()

int faultinject_open_works ( const char * scratch_path)

Is the LD_PRELOAD open() interposer active on this platform?

Arms a one-shot open() failure and probes it against the given scratch path. Returns 1 if the injected failure fired (interception works), 0 otherwise (e.g. macOS two-level namespace, or the preload was not loaded). Leaves fi reset. Injection-dependent tests should gate on this and return TEST_SKIP when it is 0, so coverage stays honest per platform.

Variable Documentation

◆ fi

struct fault_inject fi