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

Commit 02b1a7f

Browse files
committed
Clean up some confusion about where and how to set whereToSendOutput.
We will no longer try to send elog messages to the client before we have initialized backend libpq (oops); however, reporting bogus commandline switches via elog does work now (not irrelevant, because of PGOPTIONS). Fix problem with inappropriate sending of checkpoint-process messages to stderr.
1 parent 6b9f940 commit 02b1a7f

File tree

10 files changed

+69
-53
lines changed

10 files changed

+69
-53
lines changed

src/backend/catalog/pg_proc.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.58 2001/08/23 00:49:46 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.59 2001/09/08 01:10:19 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -53,8 +53,7 @@ ProcedureCreate(char *procedureName,
5353
int32 perbyte_cpu,
5454
int32 percall_cpu,
5555
int32 outin_ratio,
56-
List *argList,
57-
CommandDest dest)
56+
List *argList)
5857
{
5958
int i;
6059
Relation rel;

src/backend/commands/async.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.79 2001/06/17 22:27:15 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.80 2001/09/08 01:10:20 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -85,7 +85,6 @@
8585
#include "libpq/libpq.h"
8686
#include "libpq/pqformat.h"
8787
#include "miscadmin.h"
88-
#include "tcop/dest.h"
8988
#include "tcop/tcopprot.h"
9089
#include "utils/fmgroids.h"
9190
#include "utils/ps_status.h"
@@ -94,7 +93,7 @@
9493

9594
/* stuff that we really ought not be touching directly :-( */
9695
extern TransactionState CurrentTransactionState;
97-
extern CommandDest whereToSendOutput;
96+
9897

9998
/*
10099
* State for outbound notifies consists of a list of all relnames NOTIFYed

src/backend/commands/define.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.59 2001/09/06 02:07:42 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.60 2001/09/08 01:10:20 tgl Exp $
1414
*
1515
* DESCRIPTION
1616
* The "DefineFoo" routines take the parse tree and pick out the
@@ -50,7 +50,6 @@
5050
#include "miscadmin.h"
5151
#include "optimizer/cost.h"
5252
#include "parser/parse_expr.h"
53-
#include "tcop/dest.h"
5453
#include "utils/builtins.h"
5554
#include "utils/syscache.h"
5655

@@ -212,10 +211,9 @@ interpret_AS_clause(const char *languageName, const List *as,
212211
/*
213212
* CreateFunction
214213
* Execute a CREATE FUNCTION utility statement.
215-
*
216214
*/
217215
void
218-
CreateFunction(ProcedureStmt *stmt, CommandDest dest)
216+
CreateFunction(ProcedureStmt *stmt)
219217
{
220218
char *probin_str;
221219

@@ -338,8 +336,7 @@ CreateFunction(ProcedureStmt *stmt, CommandDest dest)
338336
perbyte_cpu,
339337
percall_cpu,
340338
outin_ratio,
341-
stmt->argTypes,
342-
dest);
339+
stmt->argTypes);
343340
}
344341

345342

src/backend/libpq/pqsignal.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.22 2001/09/07 16:12:48 wieck Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.23 2001/09/08 01:10:20 tgl Exp $
1313
*
1414
* NOTES
1515
* This shouldn't be in libpq, but the monitor and some other
@@ -46,12 +46,15 @@
4646

4747

4848
/*
49-
* Initialize BlockSig and UnBlockSig.
49+
* Initialize BlockSig, UnBlockSig, and AuthBlockSig.
5050
*
5151
* BlockSig is the set of signals to block when we are trying to block
5252
* signals. This includes all signals we normally expect to get, but NOT
5353
* signals that should never be turned off.
5454
*
55+
* AuthBlockSig is the set of signals to block during authentication;
56+
* it's essentially BlockSig minus SIGTERM and SIGQUIT.
57+
*
5558
* UnBlockSig is the set of signals to block when we don't want to block
5659
* signals (is this ever nonzero??)
5760
*/

src/backend/postmaster/postmaster.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.240 2001/09/07 16:12:48 wieck Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.241 2001/09/08 01:10:20 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -687,6 +687,15 @@ PostmasterMain(int argc, char *argv[])
687687
pqsignal(SIGTTIN, SIG_IGN); /* ignored */
688688
pqsignal(SIGTTOU, SIG_IGN); /* ignored */
689689

690+
/*
691+
* Reset whereToSendOutput from Debug (its starting state) to None.
692+
* This prevents elog from sending messages to stderr unless the
693+
* syslog/stderr switch permits. We don't do this until the postmaster
694+
* is fully launched, since startup failures may as well be reported
695+
* to stderr.
696+
*/
697+
whereToSendOutput = None;
698+
690699
/*
691700
* Initialize and startup the statistics collector process
692701
*/
@@ -1932,8 +1941,6 @@ DoBackend(Port *port)
19321941
/* Reset MyProcPid to new backend's pid */
19331942
MyProcPid = getpid();
19341943

1935-
whereToSendOutput = Remote; /* XXX probably doesn't belong here */
1936-
19371944
/*
19381945
* We arrange for a simple exit(0) if we receive SIGTERM or SIGQUIT
19391946
* during any client authentication related communication. Otherwise
@@ -1955,6 +1962,10 @@ DoBackend(Port *port)
19551962

19561963
ClientAuthentication(MyProcPort); /* might not return, if failure */
19571964

1965+
/*
1966+
* Done with authentication. Prevent SIGTERM/SIGQUIT again until
1967+
* backend startup is complete.
1968+
*/
19581969
PG_SETMASK(&BlockSig);
19591970

19601971
/*

src/backend/tcop/postgres.c

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.231 2001/09/07 16:12:48 wieck Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.232 2001/09/08 01:10:20 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -85,6 +85,7 @@ bool ShowPortNumber;
8585

8686
bool Log_connections = false;
8787

88+
/* Note: whereToSendOutput is initialized for the bootstrap/standalone case */
8889
CommandDest whereToSendOutput = Debug;
8990

9091
static bool dontExecute = false;
@@ -536,7 +537,7 @@ pg_plan_query(Query *querytree)
536537

537538
if (Show_planner_stats)
538539
{
539-
fprintf(stderr, "PLANNER STATISTICS\n");
540+
fprintf(StatFp, "PLANNER STATISTICS\n");
540541
ShowUsage();
541542
}
542543

@@ -813,7 +814,7 @@ pg_exec_query_string(char *query_string, /* string to execute */
813814

814815
if (Show_executor_stats)
815816
{
816-
fprintf(stderr, "EXECUTOR STATISTICS\n");
817+
fprintf(StatFp, "EXECUTOR STATISTICS\n");
817818
ShowUsage();
818819
}
819820
}
@@ -910,9 +911,9 @@ quickdie(SIGNAL_ARGS)
910911
PG_SETMASK(&BlockSig);
911912
elog(NOTICE, "Message from PostgreSQL backend:"
912913
"\n\tThe Postmaster has informed me that some other backend"
913-
"\tdied abnormally and possibly corrupted shared memory."
914+
"\n\tdied abnormally and possibly corrupted shared memory."
914915
"\n\tI have rolled back the current transaction and am"
915-
"\tgoing to terminate your database system connection and exit."
916+
"\n\tgoing to terminate your database system connection and exit."
916917
"\n\tPlease reconnect to the database system and repeat your query.");
917918

918919
/*
@@ -968,6 +969,10 @@ die(SIGNAL_ARGS)
968969
/*
969970
* Shutdown signal from postmaster during client authentication.
970971
* Simply exit(0).
972+
*
973+
* XXX: possible future improvement: try to send a message indicating
974+
* why we are disconnecting. Problem is to be sure we don't block while
975+
* doing so nor mess up the authentication message exchange.
971976
*/
972977
void
973978
authdie(SIGNAL_ARGS)
@@ -1163,6 +1168,16 @@ PostgresMain(int argc, char *argv[],
11631168

11641169
SetProcessingMode(InitProcessing);
11651170

1171+
/*
1172+
* If under postmaster, initialize libpq and enable reporting of
1173+
* elog errors to the client.
1174+
*/
1175+
if (IsUnderPostmaster)
1176+
{
1177+
pq_init(); /* initialize libpq at backend startup */
1178+
whereToSendOutput = Remote; /* now safe to elog to client */
1179+
}
1180+
11661181
/*
11671182
* Set default values for command-line options.
11681183
*/
@@ -1209,7 +1224,7 @@ PostgresMain(int argc, char *argv[],
12091224
#ifdef USE_ASSERT_CHECKING
12101225
SetConfigOption("debug_assertions", optarg, ctx, true);
12111226
#else
1212-
fprintf(stderr, "Assert checking is not compiled in\n");
1227+
elog(NOTICE, "Assert checking is not compiled in");
12131228
#endif
12141229
break;
12151230

@@ -1439,7 +1454,7 @@ PostgresMain(int argc, char *argv[],
14391454
*/
14401455
if (XfuncMode != 0)
14411456
{
1442-
fprintf(stderr, "only one -x flag is allowed\n");
1457+
elog(NOTICE, "only one -x flag is allowed");
14431458
errs++;
14441459
break;
14451460
}
@@ -1457,7 +1472,7 @@ PostgresMain(int argc, char *argv[],
14571472
XfuncMode = XFUNC_WAIT;
14581473
else
14591474
{
1460-
fprintf(stderr, "use -x {off,nor,nopull,nopm,pullall,wait}\n");
1475+
elog(NOTICE, "use -x {off,nor,nopull,nopm,pullall,wait}");
14611476
errs++;
14621477
}
14631478
#endif
@@ -1492,14 +1507,11 @@ PostgresMain(int argc, char *argv[],
14921507

14931508
/*
14941509
* Post-processing for command line options.
1495-
*
1496-
* XXX It'd be nice if libpq were already running here, so we could do
1497-
* elog(NOTICE) instead of just writing on stderr...
14981510
*/
14991511
if (Show_query_stats &&
15001512
(Show_parser_stats || Show_planner_stats || Show_executor_stats))
15011513
{
1502-
fprintf(stderr, "Query statistics are disabled because parser, planner, or executor statistics are on.\n");
1514+
elog(NOTICE, "Query statistics are disabled because parser, planner, or executor statistics are on.");
15031515
SetConfigOption("show_query_stats", "false", ctx, true);
15041516
}
15051517

@@ -1508,9 +1520,9 @@ PostgresMain(int argc, char *argv[],
15081520
if (!potential_DataDir)
15091521
{
15101522
fprintf(stderr, "%s does not know where to find the database system "
1511-
"data. You must specify the directory that contains the "
1512-
"database system either by specifying the -D invocation "
1513-
"option or by setting the PGDATA environment variable.\n\n",
1523+
"data. You must specify the directory that contains the "
1524+
"database system either by specifying the -D invocation "
1525+
"option or by setting the PGDATA environment variable.\n\n",
15141526
argv[0]);
15151527
proc_exit(1);
15161528
}
@@ -1578,27 +1590,28 @@ PostgresMain(int argc, char *argv[],
15781590
/* noninteractive case: nothing should be left after switches */
15791591
if (errs || argc != optind || DBName == NULL)
15801592
{
1581-
fprintf(stderr, "%s: invalid command line arguments\nTry -? for help.\n", argv[0]);
1593+
elog(NOTICE, "%s: invalid command line arguments\nTry -? for help.",
1594+
argv[0]);
15821595
proc_exit(0); /* not 1, that causes system-wide
15831596
* restart... */
15841597
}
1585-
pq_init(); /* initialize libpq at backend startup */
15861598
BaseInit();
15871599
}
15881600
else
15891601
{
15901602
/* interactive case: database name can be last arg on command line */
15911603
if (errs || argc - optind > 1)
15921604
{
1593-
fprintf(stderr, "%s: invalid command line arguments\nTry -? for help.\n", argv[0]);
1605+
elog(NOTICE, "%s: invalid command line arguments\nTry -? for help.",
1606+
argv[0]);
15941607
proc_exit(1);
15951608
}
15961609
else if (argc - optind == 1)
15971610
DBName = argv[optind];
15981611
else if ((DBName = username) == NULL)
15991612
{
1600-
fprintf(stderr, "%s: user name undefined and no database specified\n",
1601-
argv[0]);
1613+
elog(NOTICE, "%s: user name undefined and no database specified\n",
1614+
argv[0]);
16021615
proc_exit(1);
16031616
}
16041617

@@ -1723,7 +1736,7 @@ PostgresMain(int argc, char *argv[],
17231736
if (!IsUnderPostmaster)
17241737
{
17251738
puts("\nPOSTGRES backend interactive interface ");
1726-
puts("$Revision: 1.231 $ $Date: 2001/09/07 16:12:48 $\n");
1739+
puts("$Revision: 1.232 $ $Date: 2001/09/08 01:10:20 $\n");
17271740
}
17281741

17291742
/*

src/backend/tcop/utility.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.116 2001/08/21 16:36:04 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.117 2001/09/08 01:10:20 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -525,7 +525,7 @@ ProcessUtility(Node *parsetree,
525525
case T_ProcedureStmt: /* CREATE FUNCTION */
526526
set_ps_display(commandTag = "CREATE");
527527

528-
CreateFunction((ProcedureStmt *) parsetree, dest); /* everything */
528+
CreateFunction((ProcedureStmt *) parsetree);
529529
break;
530530

531531
case T_IndexStmt: /* CREATE INDEX */

src/backend/utils/adt/sets.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.37 2001/03/22 03:59:54 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.38 2001/09/08 01:10:20 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -26,8 +26,6 @@
2626
#include "utils/sets.h"
2727
#include "utils/syscache.h"
2828

29-
extern CommandDest whereToSendOutput; /* defined in tcop/postgres.c */
30-
3129

3230
/*
3331
* SetDefine - converts query string defining set to an oid
@@ -65,8 +63,7 @@ SetDefine(char *querystr, char *typename)
6563
0, /* perbyte_cpu */
6664
0, /* percall_cpu */
6765
100, /* outin_ratio */
68-
NIL, /* argList */
69-
whereToSendOutput);
66+
NIL); /* argList */
7067

7168
/*
7269
* Since we're still inside this command of the transaction, we can't

0 commit comments

Comments
 (0)