Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbf80f41

Browse files
author
Bryan Henderson
committed
Add utils directory for cross-subsystem tools to keep make files from having
to be sleazy and reach into other subsystems' directories. First entry inthis directory is the PG_VERSION file interface, which must be used by thebackend and also the pg_version program (which is used by initdb).
1 parent6f708e4 commitbf80f41

File tree

4 files changed

+183
-1
lines changed

4 files changed

+183
-1
lines changed

‎src/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
#
99
# IDENTIFICATION
10-
# $Header: /cvsroot/pgsql/src/Makefile,v 1.9 1996/10/21 06:56:55 bryanh Exp $
10+
# $Header: /cvsroot/pgsql/src/Makefile,v 1.10 1996/11/11 13:51:20 bryanh Exp $
1111
#
1212
# NOTES
1313
#objdir- location of the objects and generated files (eg. obj)
@@ -31,6 +31,7 @@ XARGS = xargs
3131
you can build Postgres.;\
3232
false;\
3333
fi
34+
$(MAKE) -C utils$@
3435
$(MAKE) -C backend$@
3536
$(MAKE) -C libpq$@
3637
ifeq ($(HAVE_Cplusplus), true)

‎src/utils/Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#-------------------------------------------------------------------------
2+
#
3+
# Makefile--
4+
# Makefile for utils
5+
#
6+
# IDENTIFICATION
7+
# $Header: /cvsroot/pgsql/src/utils/Attic/Makefile,v 1.1 1996/11/11 13:51:55 bryanh Exp $
8+
#
9+
#-------------------------------------------------------------------------
10+
11+
SRCDIR = ..
12+
include ../Makefile.global
13+
14+
INCLUDE_OPT = -I../include
15+
16+
CFLAGS+=$(INCLUDE_OPT)
17+
18+
all: version.o
19+
20+
dependdep:
21+
$(CC) -MM$(INCLUDE_OPT)*.c>depend
22+
23+
clean:
24+
rm -f version.o
25+
26+
ifeq (depend,$(wildcard depend))
27+
include depend
28+
endif
29+

‎src/utils/README

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
The utils directory contains components that are used by multiple subsystems
2+
in the Postgres source tree. We don't want subsystems reaching into other
3+
subsystems' directories and messing with the modularity of the system, so
4+
we gather any cross-subsystem utilities here.
5+
6+
In particular, programs that form an interface between subsystems go here.

‎src/utils/version.c

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* version.c--
4+
* Routines to handle Postgres version number.
5+
*
6+
* Copyright (c) 1994, Regents of the University of California
7+
*
8+
*
9+
* IDENTIFICATION
10+
* $Header: /cvsroot/pgsql/src/utils/Attic/version.c,v 1.1 1996/11/11 13:51:57 bryanh Exp $
11+
*
12+
* NOTES
13+
*XXX eventually, should be able to handle version identifiers
14+
*of length != 4.
15+
*
16+
* STANDALONE CODE - do not use error routines as this code is linked with
17+
* stuff that does not cinterface.a
18+
*-------------------------------------------------------------------------
19+
*/
20+
#include<sys/file.h>
21+
#include<sys/types.h>
22+
#include<sys/stat.h>
23+
#include<ctype.h>
24+
#include<string.h>
25+
#include<stdio.h>
26+
#include<unistd.h>
27+
28+
#include"postgres.h"
29+
30+
#include"storage/fd.h"/* for O_ */
31+
32+
#include"version.h"
33+
34+
35+
staticvoid
36+
PathSetVersionFilePath(constchar*path,char*filepathbuf) {
37+
/*----------------------------------------------------------------------------
38+
PathSetVersionFilePath
39+
40+
Destructively change "filepathbuf" to contain the concatenation of "path"
41+
and the name of the version file name.
42+
----------------------------------------------------------------------------*/
43+
if (strlen(path)> (MAXPGPATH-sizeof(PG_VERFILE)-1))
44+
*filepathbuf='\0';
45+
else
46+
sprintf(filepathbuf,"%s%c%s",path,SEP_CHAR,PG_VERFILE);
47+
}
48+
49+
50+
51+
void
52+
ValidatePgVersion(constchar*path,char**reason_p) {
53+
/*----------------------------------------------------------------------------
54+
Determine whether the PG_VERSION file in directory <path> indicates
55+
a data version compatible with the version of this program.
56+
57+
If compatible, return <*reason_p> == NULL. Otherwise, malloc space,
58+
fill it with a text string explaining how it isn't compatible (or why
59+
we can't tell), and return a pointer to that space as <*reason_p>.
60+
-----------------------------------------------------------------------------*/
61+
intfd;
62+
charversion[4];
63+
charfull_path[MAXPGPATH+1];
64+
#ifndefWIN32
65+
structstatstatbuf;
66+
#else
67+
struct_statstatbuf;
68+
#endif
69+
PathSetVersionFilePath(path,full_path);
70+
71+
if (stat(full_path,&statbuf)<0) {
72+
*reason_p=malloc(200);
73+
sprintf(*reason_p,"File '%s' does not exist.",full_path);
74+
}else {
75+
fd=open(full_path,O_RDONLY,0);
76+
if (fd<0) {
77+
*reason_p=malloc(200);
78+
sprintf(*reason_p,"Unable to open file '%s'. Errno = %s (%d).",
79+
full_path,strerror(errno),errno);
80+
}else {
81+
if (read(fd,version,4)<4||
82+
!isascii(version[0])|| !isdigit(version[0])||
83+
version[1]!='.'||
84+
!isascii(version[2])|| !isdigit(version[2])||
85+
version[3]!='\n') {
86+
87+
*reason_p=malloc(200);
88+
sprintf(*reason_p,"File '%s' does not have a valid format "
89+
"for a PG_VERSION file.",full_path);
90+
}else {
91+
if (version[2]!='0'+PG_VERSION||
92+
version[0]!='0'+PG_RELEASE) {
93+
*reason_p=malloc(200);
94+
sprintf(*reason_p,
95+
"Version number in file '%s' should be %d.%d, "
96+
"not %c.%c.",
97+
full_path,
98+
PG_RELEASE,PG_VERSION,version[0],version[2]);
99+
}else*reason_p=NULL;
100+
}
101+
close(fd);
102+
}
103+
}
104+
}
105+
106+
107+
108+
void
109+
SetPgVersion(constchar*path,char**reason_p) {
110+
/*---------------------------------------------------------------------------
111+
Create the PG_VERSION file in the directory <path>.
112+
113+
If we fail, allocate storage, fill it with a text string explaining why,
114+
and return a pointer to that storage as <*reason_p>. If we succeed,
115+
return *reason_p = NULL.
116+
---------------------------------------------------------------------------*/
117+
intfd;
118+
charversion[4];
119+
charfull_path[MAXPGPATH+1];
120+
121+
PathSetVersionFilePath(path,full_path);
122+
123+
fd=open(full_path,O_WRONLY|O_CREAT|O_EXCL,0666);
124+
if (fd<0) {
125+
*reason_p=malloc(100+strlen(full_path));
126+
sprintf(*reason_p,
127+
"Unable to create file '%s', errno from open(): %s (%d).",
128+
full_path,strerror(errno),errno);
129+
}else {
130+
intrc;/* return code from some function we call */
131+
132+
version[0]='0'+PG_RELEASE;
133+
version[1]='.';
134+
version[2]='0'+PG_VERSION;
135+
version[3]='\n';
136+
rc=write(fd,version,4);
137+
if (rc!=4) {
138+
*reason_p=malloc(100+strlen(full_path));
139+
sprintf(*reason_p,
140+
"Failed to write to file '%s', after it was already "
141+
"open. Errno from write(): %s (%d)",
142+
full_path,strerror(errno),errno);
143+
}else*reason_p=NULL;
144+
close(fd);
145+
}
146+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp