MCPcopy Create free account
hub / github.com/apache/cloudberry / checkDataDir

Function checkDataDir

src/backend/utils/init/miscinit.c:319–406  ·  view source on GitHub ↗

* Validate the proposed data directory. * * Also initialize file and directory create modes and mode mask. */

Source from the content-addressed store, hash-verified

317 * Also initialize file and directory create modes and mode mask.
318 */
319void
320checkDataDir(void)
321{
322 struct stat stat_buf;
323
324 Assert(DataDir);
325
326 if (stat(DataDir, &stat_buf) != 0)
327 {
328 if (errno == ENOENT)
329 ereport(FATAL,
330 (errcode_for_file_access(),
331 errmsg("data directory \"%s\" does not exist",
332 DataDir)));
333 else
334 ereport(FATAL,
335 (errcode_for_file_access(),
336 errmsg("could not read permissions of directory \"%s\": %m",
337 DataDir)));
338 }
339
340 /* eventual chdir would fail anyway, but let's test ... */
341 if (!S_ISDIR(stat_buf.st_mode))
342 ereport(FATAL,
343 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
344 errmsg("specified data directory \"%s\" is not a directory",
345 DataDir)));
346
347 /*
348 * Check that the directory belongs to my userid; if not, reject.
349 *
350 * This check is an essential part of the interlock that prevents two
351 * postmasters from starting in the same directory (see CreateLockFile()).
352 * Do not remove or weaken it.
353 *
354 * XXX can we safely enable this check on Windows?
355 */
356#if !defined(WIN32) && !defined(__CYGWIN__)
357 if (stat_buf.st_uid != geteuid())
358 ereport(FATAL,
359 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
360 errmsg("data directory \"%s\" has wrong ownership",
361 DataDir),
362 errhint("The server must be started by the user that owns the data directory.")));
363#endif
364
365 /*
366 * Check if the directory has correct permissions. If not, reject.
367 *
368 * Only two possible modes are allowed, 0700 and 0750. The latter mode
369 * indicates that group read/execute should be allowed on all newly
370 * created files and directories.
371 *
372 * XXX temporarily suppress check when on Windows, because there may not
373 * be proper support for Unix-y file permissions. Need to think of a
374 * reasonable check to apply on Windows.
375 */
376#if !defined(WIN32) && !defined(__CYGWIN__)

Callers 4

PostgresMainFunction · 0.85
PostmasterMainFunction · 0.85
SubPostmasterMainFunction · 0.85
AuxiliaryProcessMainFunction · 0.85

Calls 8

ValidatePgVersionFunction · 0.85
statClass · 0.70
errcode_for_file_accessFunction · 0.50
errmsgFunction · 0.50
errcodeFunction · 0.50
errhintFunction · 0.50
errdetailFunction · 0.50

Tested by

no test coverage detected