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

Commit92d1cc8

Browse files
committed
Issue psql connection warnings on connection start and via \c, per
observation by David Fetter.
1 parent6b797c8 commit92d1cc8

File tree

3 files changed

+113
-127
lines changed

3 files changed

+113
-127
lines changed

‎src/bin/psql/command.c

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.191 2008/06/26 01:35:45 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.192 2008/07/01 00:08:18 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -29,6 +29,9 @@
2929
#include<sys/types.h>/* for umask() */
3030
#include<sys/stat.h>/* for stat() */
3131
#endif
32+
#ifdefUSE_SSL
33+
#include<openssl/ssl.h>
34+
#endif
3235

3336
#include"portability/instr_time.h"
3437

@@ -57,6 +60,15 @@ static bool do_edit(const char *filename_arg, PQExpBuffer query_buf);
5760
staticbooldo_connect(char*dbname,char*user,char*host,char*port);
5861
staticbooldo_shell(constchar*command);
5962

63+
#ifdefUSE_SSL
64+
staticvoidprintSSLInfo(void);
65+
#endif
66+
67+
#ifdefWIN32
68+
staticvoidcheckWin32Codepage(void);
69+
#endif
70+
71+
6072

6173
/*----------
6274
* HandleSlashCmds:
@@ -1185,6 +1197,7 @@ do_connect(char *dbname, char *user, char *host, char *port)
11851197
* Replace the old connection with the new one, and update
11861198
* connection-dependent variables.
11871199
*/
1200+
connection_warnings();
11881201
PQsetNoticeProcessor(n_conn,NoticeProcessor,NULL);
11891202
pset.db=n_conn;
11901203
SyncVariables();
@@ -1212,6 +1225,100 @@ do_connect(char *dbname, char *user, char *host, char *port)
12121225
}
12131226

12141227

1228+
void
1229+
connection_warnings(void)
1230+
{
1231+
if (!pset.quiet&& !pset.notty)
1232+
{
1233+
intclient_ver=parse_version(PG_VERSION);
1234+
1235+
if (pset.sversion!=client_ver)
1236+
{
1237+
constchar*server_version;
1238+
charserver_ver_str[16];
1239+
1240+
/* Try to get full text form, might include "devel" etc */
1241+
server_version=PQparameterStatus(pset.db,"server_version");
1242+
if (!server_version)
1243+
{
1244+
snprintf(server_ver_str,sizeof(server_ver_str),
1245+
"%d.%d.%d",
1246+
pset.sversion /10000,
1247+
(pset.sversion /100) %100,
1248+
pset.sversion %100);
1249+
server_version=server_ver_str;
1250+
}
1251+
1252+
printf(_("%s (%s, server %s)\n"),
1253+
pset.progname,PG_VERSION,server_version);
1254+
}
1255+
else
1256+
printf("%s (%s)\n",pset.progname,PG_VERSION);
1257+
1258+
if (pset.sversion /100!=client_ver /100)
1259+
printf(_("WARNING: %s version %d.%d, server version %d.%d.\n"
1260+
" Some psql features might not work.\n"),
1261+
pset.progname,client_ver /10000, (client_ver /100) %100,
1262+
pset.sversion /10000, (pset.sversion /100) %100);
1263+
1264+
#ifdefWIN32
1265+
checkWin32Codepage();
1266+
#endif
1267+
#ifdefUSE_SSL
1268+
printSSLInfo();
1269+
#endif
1270+
}
1271+
}
1272+
1273+
1274+
/*
1275+
* printSSLInfo
1276+
*
1277+
* Prints information about the current SSL connection, if SSL is in use
1278+
*/
1279+
#ifdefUSE_SSL
1280+
staticvoid
1281+
printSSLInfo(void)
1282+
{
1283+
intsslbits=-1;
1284+
SSL*ssl;
1285+
1286+
ssl=PQgetssl(pset.db);
1287+
if (!ssl)
1288+
return;/* no SSL */
1289+
1290+
SSL_get_cipher_bits(ssl,&sslbits);
1291+
printf(_("SSL connection (cipher: %s, bits: %i)\n"),
1292+
SSL_get_cipher(ssl),sslbits);
1293+
}
1294+
#endif
1295+
1296+
1297+
/*
1298+
* checkWin32Codepage
1299+
*
1300+
* Prints a warning when win32 console codepage differs from Windows codepage
1301+
*/
1302+
#ifdefWIN32
1303+
staticvoid
1304+
checkWin32Codepage(void)
1305+
{
1306+
unsignedintwincp,
1307+
concp;
1308+
1309+
wincp=GetACP();
1310+
concp=GetConsoleCP();
1311+
if (wincp!=concp)
1312+
{
1313+
printf(_("WARNING: Console code page (%u) differs from Windows code page (%u)\n"
1314+
" 8-bit characters might not work correctly. See psql reference\n"
1315+
" page \"Notes for Windows users\" for details.\n"),
1316+
concp,wincp);
1317+
}
1318+
}
1319+
#endif
1320+
1321+
12151322
/*
12161323
* SyncVariables
12171324
*

‎src/bin/psql/command.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.h,v 1.30 2008/01/0119:45:55 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.h,v 1.31 2008/07/0100:08:18 momjian Exp $
77
*/
88
#ifndefCOMMAND_H
99
#defineCOMMAND_H
@@ -34,6 +34,8 @@ extern bool do_pset(const char *param,
3434
printQueryOpt*popt,
3535
boolquiet);
3636

37+
externvoidconnection_warnings(void);
38+
3739
externvoidSyncVariables(void);
3840

3941
externvoidUnsyncVariables(void);

‎src/bin/psql/startup.c

Lines changed: 2 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
*
44
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.148 2008/05/16 17:17:00 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.149 2008/07/01 00:08:18 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99

1010
#include<sys/types.h>
11-
#ifdefUSE_SSL
12-
#include<openssl/ssl.h>
13-
#endif
1411

1512
#ifndefWIN32
1613
#include<unistd.h>
@@ -78,22 +75,13 @@ struct adhoc_opts
7875
boolsingle_txn;
7976
};
8077

81-
staticintparse_version(constchar*versionString);
8278
staticvoidparse_psql_options(intargc,char*argv[],
8379
structadhoc_opts*options);
8480
staticvoidprocess_psqlrc(char*argv0);
8581
staticvoidprocess_psqlrc_file(char*filename);
8682
staticvoidshowVersion(void);
8783
staticvoidEstablishVariableSpace(void);
8884

89-
#ifdefUSE_SSL
90-
staticvoidprintSSLInfo(void);
91-
#endif
92-
93-
#ifdefWIN32
94-
staticvoidcheckWin32Codepage(void);
95-
#endif
96-
9785
/*
9886
*
9987
* main
@@ -296,49 +284,9 @@ main(int argc, char *argv[])
296284
if (!options.no_psqlrc)
297285
process_psqlrc(argv[0]);
298286

287+
connection_warnings();
299288
if (!pset.quiet&& !pset.notty)
300-
{
301-
intclient_ver=parse_version(PG_VERSION);
302-
303-
if (pset.sversion!=client_ver)
304-
{
305-
constchar*server_version;
306-
charserver_ver_str[16];
307-
308-
/* Try to get full text form, might include "devel" etc */
309-
server_version=PQparameterStatus(pset.db,"server_version");
310-
if (!server_version)
311-
{
312-
snprintf(server_ver_str,sizeof(server_ver_str),
313-
"%d.%d.%d",
314-
pset.sversion /10000,
315-
(pset.sversion /100) %100,
316-
pset.sversion %100);
317-
server_version=server_ver_str;
318-
}
319-
320-
printf(_("%s (%s, server %s)\n"),
321-
pset.progname,PG_VERSION,server_version);
322-
}
323-
else
324-
printf("%s (%s)\n",pset.progname,PG_VERSION);
325-
326-
if (pset.sversion /100!=client_ver /100)
327-
printf(_("WARNING: %s version %d.%d, server version %d.%d.\n"
328-
" Some psql features might not work.\n"),
329-
pset.progname,client_ver /10000, (client_ver /100) %100,
330-
pset.sversion /10000, (pset.sversion /100) %100);
331-
332-
#ifdefWIN32
333-
checkWin32Codepage();
334-
#endif
335-
#ifdefUSE_SSL
336-
printSSLInfo();
337-
#endif
338-
339289
printf(_("Type \"help\" for help.\n\n"));
340-
}
341-
342290
if (!pset.notty)
343291
initializeInput(options.no_readline ?0 :1);
344292
if (options.action_string)/* -f - was used */
@@ -357,29 +305,6 @@ main(int argc, char *argv[])
357305
}
358306

359307

360-
/*
361-
* Convert a version string into a number.
362-
*/
363-
staticint
364-
parse_version(constchar*versionString)
365-
{
366-
intcnt;
367-
intvmaj,
368-
vmin,
369-
vrev;
370-
371-
cnt=sscanf(versionString,"%d.%d.%d",&vmaj,&vmin,&vrev);
372-
373-
if (cnt<2)
374-
return-1;
375-
376-
if (cnt==2)
377-
vrev=0;
378-
379-
return (100*vmaj+vmin)*100+vrev;
380-
}
381-
382-
383308
/*
384309
* Parse command line options
385310
*/
@@ -683,54 +608,6 @@ showVersion(void)
683608

684609

685610

686-
/*
687-
* printSSLInfo
688-
*
689-
* Prints information about the current SSL connection, if SSL is in use
690-
*/
691-
#ifdefUSE_SSL
692-
staticvoid
693-
printSSLInfo(void)
694-
{
695-
intsslbits=-1;
696-
SSL*ssl;
697-
698-
ssl=PQgetssl(pset.db);
699-
if (!ssl)
700-
return;/* no SSL */
701-
702-
SSL_get_cipher_bits(ssl,&sslbits);
703-
printf(_("SSL connection (cipher: %s, bits: %i)\n"),
704-
SSL_get_cipher(ssl),sslbits);
705-
}
706-
#endif
707-
708-
709-
/*
710-
* checkWin32Codepage
711-
*
712-
* Prints a warning when win32 console codepage differs from Windows codepage
713-
*/
714-
#ifdefWIN32
715-
staticvoid
716-
checkWin32Codepage(void)
717-
{
718-
unsignedintwincp,
719-
concp;
720-
721-
wincp=GetACP();
722-
concp=GetConsoleCP();
723-
if (wincp!=concp)
724-
{
725-
printf(_("WARNING: Console code page (%u) differs from Windows code page (%u)\n"
726-
" 8-bit characters might not work correctly. See psql reference\n"
727-
" page \"Notes for Windows users\" for details.\n"),
728-
concp,wincp);
729-
}
730-
}
731-
#endif
732-
733-
734611
/*
735612
* Assign hooks for psql variables.
736613
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp