Please make ctx->discard a bool, not an int.
You can initialize it like this:
ctx->discard = strcmp(ctx->directory, DEVNULL) == 0;
Why do you change the mode to create directory to 0711 from 0700?
You have a cuddled "else" in the last hunk. Please uncuddle.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services