Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ed7a17d

Browse files
committed
Remove unneeded stat calls.
1 parent 75c6c2b commit ed7a17d

File tree

4 files changed

+35
-52
lines changed

4 files changed

+35
-52
lines changed

src/backend/libpq/hba.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.18 1997/08/18 02:14:37 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.19 1997/08/27 03:48:31 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414
#include <stdio.h>
1515
#include <string.h>
1616
#include <errno.h>
1717
#include <pwd.h>
18-
#include <sys/stat.h>
18+
#include <sys/types.h>
19+
#include <fcntl.h>
1920
#include <sys/socket.h>
20-
#include <sys/types.h> /* needed by in.h on Ultrix */
2121
#include <netinet/in.h>
2222
#include <arpa/inet.h>
2323
#include <unistd.h>
@@ -299,8 +299,7 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
299299
system.
300300
301301
---------------------------------------------------------------------------*/
302-
int rc;
303-
struct stat statbuf;
302+
int fd;
304303

305304
FILE *file; /* The config file we have to read */
306305

@@ -315,9 +314,9 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
315314
strlen(OLD_CONF_FILE)+2)*sizeof(char));
316315
sprintf(old_conf_file, "%s/%s", DataDir, OLD_CONF_FILE);
317316

318-
rc = stat(old_conf_file, &statbuf);
319-
if (rc == 0) {
317+
if ((fd = open(old_conf_file,O_RDONLY,0)) != -1) {
320318
/* Old config file exists. Tell this guy he needs to upgrade. */
319+
close(fd);
321320
sprintf(PQerrormsg,
322321
"A file exists by the name used for host-based authentication "
323322
"in prior releases of Postgres (%s). The name and format of "

src/backend/utils/init/findbe.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.4 1997/08/12 20:16:12 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.5 1997/08/27 03:48:38 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
1313
#include <stdio.h>
1414
#include <grp.h>
1515
#include <pwd.h>
1616
#include <string.h>
17-
#include <sys/stat.h>
1817
#include <sys/types.h>
18+
#include <sys/stat.h>
1919
#include <unistd.h>
2020

2121
#include "postgres.h"

src/backend/utils/init/postinit.c

+7-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.11 1997/08/19 21:35:50 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.12 1997/08/27 03:48:39 momjian Exp $
1111
*
1212
* NOTES
1313
* InitPostgres() is the function called from PostgresMain
@@ -30,7 +30,6 @@
3030
#include <stdio.h>
3131
#include <string.h>
3232
#include <sys/file.h>
33-
#include <sys/stat.h>
3433
#include <sys/types.h>
3534
#include <math.h>
3635
#include <unistd.h>
@@ -79,15 +78,6 @@ static void InitUserid(void);
7978

8079
static IPCKey PostgresIpcKey;
8180

82-
83-
#ifndef private
84-
#ifndef EBUG
85-
#define private static
86-
#else /* !defined(EBUG) */
87-
#define private
88-
#endif /* !defined(EBUG) */
89-
#endif /* !defined(private) */
90-
9181
/* ----------------------------------------------------------------
9282
* InitPostgres support
9383
* ----------------------------------------------------------------
@@ -141,7 +131,7 @@ InitMyDatabaseId()
141131
sprintf(dbfname, "%s%cpg_database", DataDir, SEP_CHAR);
142132
fileflags = O_RDONLY;
143133

144-
if ((dbfd = open(dbfname, O_RDONLY, 0666)) < 0)
134+
if ((dbfd = open(dbfname, O_RDONLY, 0)) < 0)
145135
elog(FATAL, "Cannot open %s", dbfname);
146136

147137
pfree(dbfname);
@@ -261,24 +251,25 @@ static void
261251
DoChdirAndInitDatabaseNameAndPath(char *name) {
262252
char *reason;
263253
/* Failure reason returned by some function. NULL if no failure */
264-
struct stat statbuf;
254+
int fd;
265255
char errormsg[1000];
266256

267-
if (stat(DataDir, &statbuf) < 0)
257+
if ((fd = open(DataDir, O_RDONLY,0)) == -1)
268258
sprintf(errormsg, "Database system does not exist. "
269259
"PGDATA directory '%s' not found. Normally, you "
270260
"create a database system by running initdb.",
271261
DataDir);
272262
else {
273263
char myPath[MAXPGPATH]; /* DatabasePath points here! */
274264

265+
close(fd);
275266
if (strlen(DataDir) + strlen(name) + 10 > sizeof(myPath))
276267
sprintf(errormsg, "Internal error in postinit.c: database "
277268
"pathname exceeds maximum allowable length.");
278269
else {
279270
sprintf(myPath, "%s/base/%s", DataDir, name);
280271

281-
if (stat(myPath, &statbuf) < 0)
272+
if ((fd = open(myPath, O_RDONLY,0)) == -1)
282273
sprintf(errormsg,
283274
"Database '%s' does not exist. "
284275
"(We know this because the directory '%s' "
@@ -288,6 +279,7 @@ DoChdirAndInitDatabaseNameAndPath(char *name) {
288279
"of '%s/base/'.",
289280
name, myPath, DataDir);
290281
else {
282+
close(fd);
291283
ValidatePgVersion(DataDir, &reason);
292284
if (reason != NULL)
293285
sprintf(errormsg,

src/utils/version.c

+20-28
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/utils/Attic/version.c,v 1.5 1997/07/28 00:57:08 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/utils/Attic/version.c,v 1.6 1997/08/27 03:48:50 momjian Exp $
1111
*
1212
* NOTES
1313
* XXX eventually, should be able to handle version identifiers
@@ -63,42 +63,34 @@ ValidatePgVersion(const char *path, char **reason_p) {
6363
int fd;
6464
char version[4];
6565
char full_path[MAXPGPATH+1];
66-
struct stat statbuf;
6766

6867
PathSetVersionFilePath(path, full_path);
6968

70-
if (stat(full_path, &statbuf) < 0) {
69+
if ((fd = open(full_path, O_RDONLY,0)) == -1) {
7170
*reason_p = malloc(200);
72-
sprintf(*reason_p, "File '%s' does not exist.", full_path);
71+
sprintf(*reason_p, "File '%s' does not exist or no read permission.", full_path);
7372
} else {
74-
fd = open(full_path, O_RDONLY, 0);
75-
if (fd < 0) {
73+
if (read(fd, version, 4) < 4 ||
74+
!isascii(version[0]) || !isdigit(version[0]) ||
75+
version[1] != '.' ||
76+
!isascii(version[2]) || !isdigit(version[2]) ||
77+
version[3] != '\n') {
78+
7679
*reason_p = malloc(200);
77-
sprintf(*reason_p, "Unable to open file '%s'. Errno = %s (%d).",
78-
full_path, strerror(errno), errno);
80+
sprintf(*reason_p, "File '%s' does not have a valid format "
81+
"for a PG_VERSION file.", full_path);
7982
} else {
80-
if (read(fd, version, 4) < 4 ||
81-
!isascii(version[0]) || !isdigit(version[0]) ||
82-
version[1] != '.' ||
83-
!isascii(version[2]) || !isdigit(version[2]) ||
84-
version[3] != '\n') {
85-
83+
if (version[2] != '0' + PG_VERSION ||
84+
version[0] != '0' + PG_RELEASE) {
8685
*reason_p = malloc(200);
87-
sprintf(*reason_p, "File '%s' does not have a valid format "
88-
"for a PG_VERSION file.", full_path);
89-
} else {
90-
if (version[2] != '0' + PG_VERSION ||
91-
version[0] != '0' + PG_RELEASE) {
92-
*reason_p = malloc(200);
93-
sprintf(*reason_p,
94-
"Version number in file '%s' should be %d.%d, "
95-
"not %c.%c.",
96-
full_path,
97-
PG_RELEASE, PG_VERSION, version[0], version[2]);
98-
} else *reason_p = NULL;
99-
}
100-
close(fd);
86+
sprintf(*reason_p,
87+
"Version number in file '%s' should be %d.%d, "
88+
"not %c.%c.",
89+
full_path,
90+
PG_RELEASE, PG_VERSION, version[0], version[2]);
91+
} else *reason_p = NULL;
10192
}
93+
close(fd);
10294
}
10395
}
10496

0 commit comments

Comments
 (0)