提交 04f4e10c 编写于 作者: T Tom Lane

Use symbolic names not octal constants for file permission flags.

Purely cosmetic patch to make our coding standards more consistent ---
we were doing symbolic some places and octal other places.  This patch
fixes all C-coded uses of mkdir, chmod, and umask.  There might be some
other calls I missed.  Inconsistency noted while researching tablespace
directory permissions issue.
上级 244407a7
......@@ -3451,7 +3451,7 @@ ValidateXLOGDirectoryStructure(void)
{
ereport(LOG,
(errmsg("creating missing WAL directory \"%s\"", path)));
if (mkdir(path, 0700) < 0)
if (mkdir(path, S_IRWXU) < 0)
ereport(FATAL,
(errmsg("could not create missing directory \"%s\": %m",
path)));
......
......@@ -1269,7 +1269,7 @@ DoCopyTo(CopyState cstate)
(errcode(ERRCODE_INVALID_NAME),
errmsg("relative path not allowed for COPY to file")));
oumask = umask((mode_t) 022);
oumask = umask(S_IWGRP | S_IWOTH);
cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
umask(oumask);
......
......@@ -552,7 +552,7 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
* Attempt to coerce target directory to safe permissions. If this fails,
* it doesn't exist or has the wrong owner.
*/
if (chmod(location, 0700) != 0)
if (chmod(location, S_IRWXU) != 0)
{
if (errno == ENOENT)
ereport(ERROR,
......
......@@ -399,7 +399,7 @@ lo_import_internal(text *filename, Oid lobjOid)
* open the file to be read in
*/
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
fd = PathNameOpenFile(fnamebuf, O_RDONLY | PG_BINARY, 0666);
fd = PathNameOpenFile(fnamebuf, O_RDONLY | PG_BINARY, S_IRWXU);
if (fd < 0)
ereport(ERROR,
(errcode_for_file_access(),
......@@ -474,8 +474,9 @@ lo_export(PG_FUNCTION_ARGS)
* world-writable export files doesn't seem wise.
*/
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
oumask = umask((mode_t) 0022);
fd = PathNameOpenFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY, 0666);
oumask = umask(S_IWGRP | S_IWOTH);
fd = PathNameOpenFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
umask(oumask);
if (fd < 0)
ereport(ERROR,
......
......@@ -494,7 +494,7 @@ PostmasterMain(int argc, char *argv[])
/*
* for security, no dir or file created can be group or other accessible
*/
umask((mode_t) 0077);
umask(S_IRWXG | S_IRWXO);
/*
* Fire up essential subsystems: memory management
......@@ -1274,7 +1274,7 @@ pmdaemonize(void)
progname, DEVNULL, strerror(errno));
ExitPostmaster(1);
}
pmlog = open(pmlogname, O_CREAT | O_WRONLY | O_APPEND, 0600);
pmlog = open(pmlogname, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR);
if (pmlog < 0)
{
write_stderr("%s: could not open log file \"%s/%s\": %s\n",
......
......@@ -73,7 +73,7 @@ int Log_RotationSize = 10 * 1024;
char *Log_directory = NULL;
char *Log_filename = NULL;
bool Log_truncate_on_rotation = false;
int Log_file_mode = 0600;
int Log_file_mode = S_IRUSR | S_IWUSR;
/*
* Globally visible state (used by elog.c)
......@@ -511,7 +511,7 @@ SysLogger_Start(void)
/*
* Create log directory if not present; ignore errors
*/
mkdir(Log_directory, 0700);
mkdir(Log_directory, S_IRWXU);
/*
* The initial logfile is created right in the postmaster, to verify that
......@@ -1020,7 +1020,7 @@ logfile_open(const char *filename, const char *mode, bool allow_errors)
* Note we do not let Log_file_mode disable IWUSR, since we certainly
* want to be able to write the files ourselves.
*/
oumask = umask((mode_t) ((~(Log_file_mode | S_IWUSR)) & 0777));
oumask = umask((mode_t) ((~(Log_file_mode | S_IWUSR)) & (S_IRWXU | S_IRWXG | S_IRWXO)));
fh = fopen(filename, mode);
umask(oumask);
......
......@@ -56,7 +56,7 @@ copydir(char *fromdir, char *todir, bool recurse)
char fromfile[MAXPGPATH];
char tofile[MAXPGPATH];
if (mkdir(todir, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
if (mkdir(todir, S_IRWXU) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not create directory \"%s\": %m", todir)));
......
......@@ -126,8 +126,8 @@ proc_exit(int code)
else
snprintf(gprofDirName, 32, "gprof/%d", (int) getpid());
mkdir("gprof", 0777);
mkdir(gprofDirName, 0777);
mkdir("gprof", S_IRWXU | S_IRWXG | S_IRWXO);
mkdir(gprofDirName, S_IRWXU | S_IRWXG | S_IRWXO);
chdir(gprofDirName);
}
#endif
......
......@@ -870,7 +870,7 @@ mkdatadir(const char *subdir)
else
strcpy(path, pg_data);
if (mkdir_p(path, 0700) == 0)
if (mkdir_p(path, S_IRWXU) == 0)
return true;
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
......@@ -1166,7 +1166,7 @@ setup_config(void)
snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data);
writefile(path, conflines);
chmod(path, 0600);
chmod(path, S_IRUSR | S_IWUSR);
free(conflines);
......@@ -1237,7 +1237,7 @@ setup_config(void)
snprintf(path, sizeof(path), "%s/pg_hba.conf", pg_data);
writefile(path, conflines);
chmod(path, 0600);
chmod(path, S_IRUSR | S_IWUSR);
free(conflines);
......@@ -1248,7 +1248,7 @@ setup_config(void)
snprintf(path, sizeof(path), "%s/pg_ident.conf", pg_data);
writefile(path, conflines);
chmod(path, 0600);
chmod(path, S_IRUSR | S_IWUSR);
free(conflines);
......@@ -2904,7 +2904,7 @@ main(int argc, char *argv[])
printf("\n");
umask(077);
umask(S_IRWXG | S_IRWXO);
/*
* now we are starting to do real work, trap signals so we can clean up
......@@ -2951,7 +2951,7 @@ main(int argc, char *argv[])
pg_data);
fflush(stdout);
if (chmod(pg_data, 0700) != 0)
if (chmod(pg_data, S_IRWXU) != 0)
{
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
progname, pg_data, strerror(errno));
......@@ -3004,7 +3004,7 @@ main(int argc, char *argv[])
xlog_dir);
fflush(stdout);
if (mkdir_p(xlog_dir, 0700) != 0)
if (mkdir_p(xlog_dir, S_IRWXU) != 0)
{
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
progname, xlog_dir, strerror(errno));
......@@ -3021,7 +3021,7 @@ main(int argc, char *argv[])
xlog_dir);
fflush(stdout);
if (chmod(xlog_dir, 0700) != 0)
if (chmod(xlog_dir, S_IRWXU) != 0)
{
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
progname, xlog_dir, strerror(errno));
......
......@@ -1769,7 +1769,7 @@ main(int argc, char **argv)
*/
argv0 = argv[0];
umask(077);
umask(S_IRWXG | S_IRWXO);
/* support --help and --version even if invoked as root */
if (argc > 1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册