#define frr_with_privs(privs) \ for (struct zebra_privs_t *_once = NULL, \ *_privs __attribute__( \ (unused, cleanup(_zprivs_lower))) = \ _zprivs_raise(privs, __func__); \ _once == NULL; _once = (void *)1)
frr_with_privs(privs) { ... whatever ... break; /* exit block, drop privileges */ return; /* return, drop privileges */ }
https://github.com/libguestfs/nbdkit/blob/e58d28d65bfea3af36...
You end up with code like this:
It's so useful to be able to be sure the lock is released on all return paths. Also because it's scope-level you can scope your locks tightly to where they are needed.