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

Commitb556e82

Browse files
committed
elog mop-up: bring some straggling fprintf(stderr)'s into the elog world.
1 parent606debf commitb556e82

File tree

18 files changed

+316
-382
lines changed

18 files changed

+316
-382
lines changed

‎src/backend/bootstrap/bootstrap.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.162 2003/07/22 23:30:37 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.163 2003/07/27 21:49:53 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -359,7 +359,7 @@ BootstrapMain(int argc, char *argv[])
359359
gettext("%s does not know where to find the database system data.\n"
360360
"You must specify the directory that contains the database system\n"
361361
"either by specifying the -D invocation option or by setting the\n"
362-
"PGDATA environment variable.\n\n"),
362+
"PGDATA environment variable.\n"),
363363
argv[0]);
364364
proc_exit(1);
365365
}
@@ -414,8 +414,7 @@ BootstrapMain(int argc, char *argv[])
414414
/*
415415
* Create lockfile for data directory.
416416
*/
417-
if (!CreateDataDirLockFile(DataDir, false))
418-
proc_exit(1);
417+
CreateDataDirLockFile(DataDir, false);
419418
}
420419

421420
SetProcessingMode(BootstrapProcessing);

‎src/backend/libpq/be-secure.c

Lines changed: 43 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.36 2003/07/22 19:00:10 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.37 2003/07/27 21:49:53 tgl Exp $
1515
*
1616
* Since the server static private key ($DataDir/server.key)
1717
* will normally be stored unencrypted so that the database
@@ -81,10 +81,6 @@
8181
#include<fcntl.h>
8282
#include<errno.h>
8383
#include<ctype.h>
84-
85-
#include"libpq/libpq.h"
86-
#include"miscadmin.h"
87-
8884
#include<sys/socket.h>
8985
#include<unistd.h>
9086
#include<netdb.h>
@@ -94,17 +90,13 @@
9490
#include<arpa/inet.h>
9591
#endif
9692

97-
#ifndefHAVE_STRDUP
98-
#include"strdup.h"
99-
#endif
100-
10193
#ifdefUSE_SSL
10294
#include<openssl/ssl.h>
10395
#include<openssl/dh.h>
10496
#endif
10597

106-
externvoidExitPostmaster(int);
107-
externvoidpostmaster_error(constchar*fmt,...);
98+
#include"libpq/libpq.h"
99+
#include"miscadmin.h"
108100

109101
#ifdefUSE_SSL
110102
staticDH*load_dh_file(intkeylength);
@@ -126,6 +118,7 @@ static const char *SSLerrmessage(void);
126118
*/
127119
#defineRENEGOTIATION_LIMIT (512 * 1024 * 1024)
128120
#defineCA_PATH NULL
121+
129122
staticSSL_CTX*SSL_context=NULL;
130123
#endif
131124

@@ -607,7 +600,7 @@ info_cb(const SSL *ssl, int type, int args)
607600
staticint
608601
initialize_SSL(void)
609602
{
610-
charfnbuf[2048];
603+
charfnbuf[MAXPGPATH];
611604
structstatbuf;
612605

613606
if (!SSL_context)
@@ -616,50 +609,43 @@ initialize_SSL(void)
616609
SSL_load_error_strings();
617610
SSL_context=SSL_CTX_new(SSLv23_method());
618611
if (!SSL_context)
619-
{
620-
postmaster_error("failed to create SSL context: %s",
621-
SSLerrmessage());
622-
ExitPostmaster(1);
623-
}
612+
ereport(FATAL,
613+
(errmsg("could not create SSL context: %s",
614+
SSLerrmessage())));
624615

625616
/*
626617
* Load and verify certificate and private key
627618
*/
628619
snprintf(fnbuf,sizeof(fnbuf),"%s/server.crt",DataDir);
629620
if (!SSL_CTX_use_certificate_file(SSL_context,fnbuf,SSL_FILETYPE_PEM))
630-
{
631-
postmaster_error("failed to load server certificate (%s): %s",
632-
fnbuf,SSLerrmessage());
633-
ExitPostmaster(1);
634-
}
621+
ereport(FATAL,
622+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
623+
errmsg("could not load server certificate file \"%s\": %s",
624+
fnbuf,SSLerrmessage())));
635625

636626
snprintf(fnbuf,sizeof(fnbuf),"%s/server.key",DataDir);
637-
if (lstat(fnbuf,&buf)==-1)
638-
{
639-
postmaster_error("failed to stat private key file (%s): %s",
640-
fnbuf,strerror(errno));
641-
ExitPostmaster(1);
642-
}
643-
if (!S_ISREG(buf.st_mode)|| (buf.st_mode&0077)||
627+
if (stat(fnbuf,&buf)==-1)
628+
ereport(FATAL,
629+
(errcode_for_file_access(),
630+
errmsg("could not access private key file \"%s\": %m",
631+
fnbuf)));
632+
if (!S_ISREG(buf.st_mode)|| (buf.st_mode& (S_IRWXG |S_IRWXO))||
644633
buf.st_uid!=getuid())
645-
{
646-
postmaster_error("bad permissions on private key file (%s)\n"
647-
"File must be owned by the proper user and must have no permissions for\n"
648-
"\"group\" or \"other\".",fnbuf);
649-
ExitPostmaster(1);
650-
}
634+
ereport(FATAL,
635+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
636+
errmsg("unsafe permissions on private key file \"%s\"",
637+
fnbuf),
638+
errdetail("File must be owned by the database user and must have no permissions for \"group\" or \"other\".")));
639+
651640
if (!SSL_CTX_use_PrivateKey_file(SSL_context,fnbuf,SSL_FILETYPE_PEM))
652-
{
653-
postmaster_error("failed to load private key file (%s): %s",
654-
fnbuf,SSLerrmessage());
655-
ExitPostmaster(1);
656-
}
641+
ereport(FATAL,
642+
(errmsg("could not load private key file \"%s\": %s",
643+
fnbuf,SSLerrmessage())));
644+
657645
if (!SSL_CTX_check_private_key(SSL_context))
658-
{
659-
postmaster_error("check of private key failed: %s",
660-
SSLerrmessage());
661-
ExitPostmaster(1);
662-
}
646+
ereport(FATAL,
647+
(errmsg("check of private key failed: %s",
648+
SSLerrmessage())));
663649
}
664650

665651
/* set up empheral DH keys */
@@ -668,25 +654,22 @@ initialize_SSL(void)
668654

669655
/* setup the allowed cipher list */
670656
if (SSL_CTX_set_cipher_list(SSL_context,"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH")!=1)
671-
{
672-
postmaster_error("unable to set the cipher list (no valid ciphers available)");
673-
ExitPostmaster(1);
674-
}
657+
elog(FATAL,"could not set the cipher list (no valid ciphers available)");
675658

676659
/* accept client certificates, but don't require them. */
677-
snprintf(fnbuf,sizeoffnbuf,"%s/root.crt",DataDir);
660+
snprintf(fnbuf,sizeof(fnbuf),"%s/root.crt",DataDir);
678661
if (!SSL_CTX_load_verify_locations(SSL_context,fnbuf,CA_PATH))
679662
{
663+
/* Not fatal - we do not require client certificates */
664+
ereport(LOG,
665+
(errmsg("could not load root cert file \"%s\": %s",
666+
fnbuf,SSLerrmessage()),
667+
errdetail("Will not verify client certificates.")));
680668
return0;
681-
#ifdefNOT_USED
682-
/* CLIENT CERTIFICATES NOT REQUIRED bjm 2002-09-26 */
683-
postmaster_error("could not read root cert file (%s): %s",
684-
fnbuf,SSLerrmessage());
685-
ExitPostmaster(1);
686-
#endif
687669
}
688670
SSL_CTX_set_verify(SSL_context,
689-
SSL_VERIFY_PEER |SSL_VERIFY_CLIENT_ONCE,verify_cb);
671+
SSL_VERIFY_PEER |SSL_VERIFY_CLIENT_ONCE,
672+
verify_cb);
690673

691674
return0;
692675
}
@@ -716,7 +699,7 @@ open_server_SSL(Port *port)
716699
{
717700
ereport(COMMERROR,
718701
(errcode(ERRCODE_PROTOCOL_VIOLATION),
719-
errmsg("failed to initialize SSL connection: %s",
702+
errmsg("could not initialize SSL connection: %s",
720703
SSLerrmessage())));
721704
close_SSL(port);
722705
return-1;
@@ -739,7 +722,8 @@ open_server_SSL(Port *port)
739722
NID_commonName,port->peer_cn,sizeof(port->peer_cn));
740723
port->peer_cn[sizeof(port->peer_cn)-1]='\0';
741724
}
742-
elog(DEBUG2,"secure connection from \"%s\"",port->peer_cn);
725+
ereport(DEBUG2,
726+
(errmsg("secure connection from \"%s\"",port->peer_cn)));
743727

744728
/* set up debugging/info callback */
745729
SSL_CTX_set_info_callback(SSL_context,info_cb);

‎src/backend/libpq/pqcomm.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
3131
* Portions Copyright (c) 1994, Regents of the University of California
3232
*
33-
*$Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.160 2003/07/24 00:02:53 tgl Exp $
33+
*$Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.161 2003/07/27 21:49:53 tgl Exp $
3434
*
3535
*-------------------------------------------------------------------------
3636
*/
@@ -389,8 +389,7 @@ Lock_AF_UNIX(unsigned short portNumber, char *unixSocketName)
389389
/*
390390
* Grab an interlock file associated with the socket file.
391391
*/
392-
if (!CreateSocketLockFile(sock_path, true))
393-
returnSTATUS_ERROR;
392+
CreateSocketLockFile(sock_path, true);
394393

395394
/*
396395
* Once we have the interlock, we can safely delete any pre-existing

‎src/backend/main/main.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.58 2003/07/04 16:41:21 tgl Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.59 2003/07/27 21:49:53 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -81,7 +81,8 @@ main(int argc, char *argv[])
8181
#if defined(__alpha)
8282
if (setsysinfo(SSI_NVPAIRS,buffer,1, (caddr_t)NULL,
8383
(unsigned long)NULL)<0)
84-
fprintf(stderr,gettext("%s: setsysinfo failed: %s\n"),argv[0],strerror(errno));
84+
fprintf(stderr,gettext("%s: setsysinfo failed: %s\n"),
85+
argv[0],strerror(errno));
8586
#endif
8687
#endif/* NOFIXADE || NOPRINTADE */
8788

@@ -170,12 +171,12 @@ main(int argc, char *argv[])
170171
*/
171172
if (geteuid()==0)
172173
{
173-
fprintf(stderr,gettext(
174-
"\"root\" execution of the PostgreSQL server is not permitted.\n\n"
175-
"The server must be started under an unprivileged user id to prevent\n"
176-
"apossible system security compromise. See the documentation for\n"
177-
"more information on how to properly start the server.\n\n"
178-
));
174+
fprintf(stderr,
175+
gettext("\"root\" execution of the PostgreSQL server is not permitted.\n"
176+
"The server must be started under an unprivileged user id to prevent\n"
177+
"possible system security compromise. See the documentation for\n"
178+
"more information on how to properly start the server.\n"
179+
));
179180
exit(1);
180181
}
181182
#endif/* !__BEOS__ */
@@ -191,7 +192,8 @@ main(int argc, char *argv[])
191192
*/
192193
if (getuid()!=geteuid())
193194
{
194-
fprintf(stderr,gettext("%s: real and effective user ids must match\n"),
195+
fprintf(stderr,
196+
gettext("%s: real and effective user ids must match\n"),
195197
argv[0]);
196198
exit(1);
197199
}
@@ -236,7 +238,7 @@ main(int argc, char *argv[])
236238
pw=getpwuid(geteuid());
237239
if (pw==NULL)
238240
{
239-
fprintf(stderr,gettext("%s: invalidcurrent euid %d\n"),
241+
fprintf(stderr,gettext("%s: invalideffective uid: %d\n"),
240242
new_argv[0], (int)geteuid());
241243
exit(1);
242244
}
@@ -249,7 +251,8 @@ main(int argc, char *argv[])
249251
pw_name_persist=malloc(namesize);
250252
if (!GetUserName(pw_name_persist,&namesize))
251253
{
252-
fprintf(stderr,"%s: GetUserName failed\n",argv[0]);
254+
fprintf(stderr,gettext("%s: GetUserName failed\n"),
255+
new_argv[0]);
253256
exit(1);
254257
}
255258
}

‎src/backend/port/ipc_test.c

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*
2323
* IDENTIFICATION
24-
* $Header: /cvsroot/pgsql/src/backend/port/ipc_test.c,v 1.6 2003/07/22 23:30:39 tgl Exp $
24+
* $Header: /cvsroot/pgsql/src/backend/port/ipc_test.c,v 1.7 2003/07/27 21:49:54 tgl Exp $
2525
*
2626
*-------------------------------------------------------------------------
2727
*/
@@ -46,6 +46,8 @@ volatile bool ImmediateInterruptOK = false;
4646
volatileuint32InterruptHoldoffCount=0;
4747
volatileuint32CritSectionCount=0;
4848

49+
constboolExecBackend= false;
50+
4951
boolIsUnderPostmaster= false;
5052

5153
intMaxBackends=DEF_MAXBACKENDS;
@@ -128,14 +130,60 @@ ExceptionalCondition(char *conditionName,
128130
return0;
129131
}
130132

133+
134+
135+
bool
136+
errstart(intelevel,constchar*filename,intlineno,
137+
constchar*funcname)
138+
{
139+
return (elevel >=ERROR);
140+
}
141+
131142
void
132-
elog(intlev,constchar*fmt,...)
143+
errfinish(intdummy,...)
133144
{
134-
if (lev >=ERROR)
135-
{
136-
fprintf(stderr,"elog(%s)\n",fmt);
137-
abort();
138-
}
145+
proc_exit(1);
146+
}
147+
148+
void
149+
elog_finish(intelevel,constchar*fmt, ...)
150+
{
151+
fprintf(stderr,"ERROR: %s\n",fmt);
152+
proc_exit(1);
153+
}
154+
155+
int
156+
errcode(intsqlerrcode)
157+
{
158+
return0;/* return value does not matter */
159+
}
160+
161+
int
162+
errmsg(constchar*fmt, ...)
163+
{
164+
fprintf(stderr,"ERROR: %s\n",fmt);
165+
return0;/* return value does not matter */
166+
}
167+
168+
int
169+
errmsg_internal(constchar*fmt, ...)
170+
{
171+
fprintf(stderr,"ERROR: %s\n",fmt);
172+
return0;/* return value does not matter */
173+
}
174+
175+
int
176+
errdetail(constchar*fmt, ...)
177+
{
178+
fprintf(stderr,"DETAIL: %s\n",fmt);
179+
return0;/* return value does not matter */
180+
}
181+
182+
int
183+
errhint(constchar*fmt, ...)
184+
{
185+
fprintf(stderr,"HINT: %s\n",fmt);
186+
return0;/* return value does not matter */
139187
}
140188

141189

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp