postgres.git / summary / log / commit / refs

commit    c2b68b1f7d6de9e749d037a09c5875742e8e6250
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Fri May 29 21:02:58 2015 +0000
First released in: 9.5.0, 9.3.8, 9.4.3

    initdb -S should now have an explicit check that $PGDATA is valid.
    
    The fsync code from the backend essentially assumes that somebody's already
    validated PGDATA, at least to the extent of it being a readable directory.
    That's safe enough for initdb's normal code path too, but "initdb -S"
    doesn't have any other processing at all that touches the target directory.
    To have reasonable error-case behavior, add a pg_check_dir call.
    Per gripe from Peter E.


src/bin/initdb/initdb.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 3c35429045e..5217d9c7c3c 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -3650,10 +3650,19 @@ main(int argc, char *argv[]) exit(1); } - /* If we only need to fsync, just to it and exit */ + /* If we only need to fsync, just do it and exit */ if (sync_only) { setup_pgdata(); + + /* must check that directory is readable */ + if (pg_check_dir(pg_data) <= 0) + { + fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"), + progname, pg_data, strerror(errno)); + exit_nicely(); + } + fsync_pgdata(); return 0; } [parent: 35dd1b51f2ea]