Here's our usage:
https://github.com/FRRouting/frr/blob/master/lib/privs.h#L14... #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)
This gives us a block construct that guarantees elevated privileges are dropped when the block is done:
frr_with_privs(privs) {
... whatever ...
break; /* exit block, drop privileges */
return; /* return, drop privileges */
}