initdb -S should now have an explicit check that $PGDATA is valid.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 29 May 2015 21:02:58 +0000 (17:02 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 29 May 2015 21:02:58 +0000 (17:02 -0400)
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

index 6a73e9688bc069d5e7688a6a235dc8e29f4665be..feeff9e864f4a94c25ad6e156a939afd67811c55 100644 (file)
@@ -3564,10 +3564,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;
        }