66 * copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
77 * licence: BSD
88 *
9- * $Header: /cvsroot/pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.2 2002/08/18 02:48:41 tgl Exp $
9+ * $Header: /cvsroot/pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.3 2002/08/21 22:24:34 petere Exp $
1010 */
1111#include "postgres.h"
1212
1515#include <sys/types.h>
1616#include <sys/stat.h>
1717#include <fcntl.h>
18+ #include <locale.h>
19+ #include <errno.h>
1820
1921#include "catalog/pg_control.h"
2022
23+ #define _ (x ) gettext((x))
24+
25+
26+ static void
27+ usage (const char * progname )
28+ {
29+ printf (_ ("%s displays PostgreSQL database cluster control information.\n" ), progname );
30+ printf (_ ("Usage:\n %s [DATADIR]\n\n" ), progname );
31+ printf (_ ("If not data directory is specified, the environment variable PGDATA\nis used.\n\n" ));
32+ printf (_ ("Report bugs to <pgsql-bugs@postgresql.org>.\n" ));
33+ }
34+
2135
2236static const char *
2337dbState (DBState state )
@@ -35,7 +49,7 @@ dbState(DBState state)
3549 case DB_IN_PRODUCTION :
3650 return "IN_PRODUCTION" ;
3751 }
38- return "unrecognized status code" ;
52+ return _ ( "unrecognized status code" ) ;
3953}
4054
4155
@@ -50,28 +64,56 @@ main(int argc, char *argv[])
5064 char pgctime_str [32 ];
5165 char ckpttime_str [32 ];
5266 char * strftime_fmt = "%c" ;
67+ char * progname ;
68+
69+ setlocale (LC_ALL , "" );
70+ #ifdef ENABLE_NLS
71+ bindtextdomain ("pg_controldata" , LOCALEDIR );
72+ textdomain ("pg_controldata" );
73+ #endif
74+
75+ if (!strrchr (argv [0 ], '/' ))
76+ progname = argv [0 ];
77+ else
78+ progname = strrchr (argv [0 ], '/' ) + 1 ;
79+
80+ if (argc > 1 )
81+ {
82+ if (strcmp (argv [1 ], "--help" ) == 0 || strcmp (argv [1 ], "-?" ) == 0 )
83+ {
84+ usage (progname );
85+ exit (0 );
86+ }
87+ if (strcmp (argv [1 ], "--version" ) == 0 || strcmp (argv [1 ], "-V" ) == 0 )
88+ {
89+ puts ("pg_controldata (PostgreSQL) " PG_VERSION );
90+ exit (0 );
91+ }
92+ }
5393
5494 if (argc > 1 )
5595 DataDir = argv [1 ];
5696 else
5797 DataDir = getenv ("PGDATA" );
5898 if (DataDir == NULL )
5999 {
60- fprintf (stderr , " no data directory specified\n" );
100+ fprintf (stderr , _ ( "%s: no data directory specified\n"), progname );
61101 exit (1 );
62102 }
63103
64104 snprintf (ControlFilePath , MAXPGPATH , "%s/global/pg_control" , DataDir );
65105
66106 if ((fd = open (ControlFilePath , O_RDONLY )) == -1 )
67107 {
68- perror ("Failed to open $PGDATA/global/pg_control for reading" );
108+ fprintf (stderr , _ ("%s: could not open file \"%s\" for reading (%s)\n" ),
109+ progname , ControlFilePath , strerror (errno ));
69110 exit (2 );
70111 }
71112
72113 if (read (fd , & ControlFile , sizeof (ControlFileData )) != sizeof (ControlFileData ))
73114 {
74- perror ("Failed to read $PGDATA/global/pg_control" );
115+ fprintf (stderr , _ ("%s: could not read file \"%s\" (%s)\n" ),
116+ progname , ControlFilePath , strerror (errno ));
75117 exit (2 );
76118 }
77119 close (fd );
@@ -84,9 +126,9 @@ main(int argc, char *argv[])
84126 FIN_CRC64 (crc );
85127
86128 if (!EQ_CRC64 (crc , ControlFile .crc ))
87- printf ("WARNING: Calculated CRC checksum does not match value stored in file.\n"
88- "Either the file is corrupt, or it has a different layout than this program\n"
89- "is expecting. The results below are untrustworthy.\n\n" );
129+ printf (_ ( "WARNING: Calculated CRC checksum does not match value stored in file.\n"
130+ "Either the file is corrupt, or it has a different layout than this program\n"
131+ "is expecting. The results below are untrustworthy.\n\n" ) );
90132
91133 /*
92134 * Use variable for format to suppress overly-anal-retentive gcc warning
@@ -97,56 +139,33 @@ main(int argc, char *argv[])
97139 strftime (ckpttime_str , sizeof (ckpttime_str ), strftime_fmt ,
98140 localtime (& (ControlFile .checkPointCopy .time )));
99141
100- printf ("pg_control version number: %u\n"
101- "Catalog version number: %u\n"
102- "Database state: %s\n"
103- "pg_control last modified: %s\n"
104- "Current log file id: %u\n"
105- "Next log file segment: %u\n"
106- "Latest checkpoint location: %X/%X\n"
107- "Prior checkpoint location: %X/%X\n"
108- "Latest checkpoint's REDO location: %X/%X\n"
109- "Latest checkpoint's UNDO location: %X/%X\n"
110- "Latest checkpoint's StartUpID: %u\n"
111- "Latest checkpoint's NextXID: %u\n"
112- "Latest checkpoint's NextOID: %u\n"
113- "Time of latest checkpoint: %s\n"
114- "Database block size: %u\n"
115- "Blocks per segment of large relation: %u\n"
116- "Maximum length of names: %u\n"
117- "Maximum number of function arguments: %u\n"
118- "Date/time type storage: %s\n"
119- "Maximum length of locale name: %u\n"
120- "LC_COLLATE: %s\n"
121- "LC_CTYPE: %s\n" ,
122-
123- ControlFile .pg_control_version ,
124- ControlFile .catalog_version_no ,
125- dbState (ControlFile .state ),
126- pgctime_str ,
127- ControlFile .logId ,
128- ControlFile .logSeg ,
129- ControlFile .checkPoint .xlogid ,
130- ControlFile .checkPoint .xrecoff ,
131- ControlFile .prevCheckPoint .xlogid ,
132- ControlFile .prevCheckPoint .xrecoff ,
133- ControlFile .checkPointCopy .redo .xlogid ,
134- ControlFile .checkPointCopy .redo .xrecoff ,
135- ControlFile .checkPointCopy .undo .xlogid ,
136- ControlFile .checkPointCopy .undo .xrecoff ,
137- ControlFile .checkPointCopy .ThisStartUpID ,
138- ControlFile .checkPointCopy .nextXid ,
139- ControlFile .checkPointCopy .nextOid ,
140- ckpttime_str ,
141- ControlFile .blcksz ,
142- ControlFile .relseg_size ,
143- ControlFile .nameDataLen ,
144- ControlFile .funcMaxArgs ,
145- (ControlFile .enableIntTimes ?
146- "64-bit integers" : "Floating point" ),
147- ControlFile .localeBuflen ,
148- ControlFile .lc_collate ,
149- ControlFile .lc_ctype );
150-
151- return (0 );
142+ printf (_ ("pg_control version number: %u\n" ), ControlFile .pg_control_version );
143+ printf (_ ("Catalog version number: %u\n" ), ControlFile .catalog_version_no );
144+ printf (_ ("Database cluster state: %s\n" ), dbState (ControlFile .state ));
145+ printf (_ ("pg_control last modified: %s\n" ), pgctime_str );
146+ printf (_ ("Current log file ID: %u\n" ), ControlFile .logId );
147+ printf (_ ("Next log file segment: %u\n" ), ControlFile .logSeg );
148+ printf (_ ("Latest checkpoint location: %X/%X\n" ),
149+ ControlFile .checkPoint .xlogid , ControlFile .checkPoint .xrecoff );
150+ printf (_ ("Prior checkpoint location: %X/%X\n" ),
151+ ControlFile .prevCheckPoint .xlogid , ControlFile .prevCheckPoint .xrecoff );
152+ printf (_ ("Latest checkpoint's REDO location: %X/%X\n" ),
153+ ControlFile .checkPointCopy .redo .xlogid , ControlFile .checkPointCopy .redo .xrecoff );
154+ printf (_ ("Latest checkpoint's UNDO location: %X/%X\n" ),
155+ ControlFile .checkPointCopy .undo .xlogid , ControlFile .checkPointCopy .undo .xrecoff );
156+ printf (_ ("Latest checkpoint's StartUpID: %u\n" ), ControlFile .checkPointCopy .ThisStartUpID );
157+ printf (_ ("Latest checkpoint's NextXID: %u\n" ), ControlFile .checkPointCopy .nextXid );
158+ printf (_ ("Latest checkpoint's NextOID: %u\n" ), ControlFile .checkPointCopy .nextOid );
159+ printf (_ ("Time of latest checkpoint: %s\n" ), ckpttime_str );
160+ printf (_ ("Database block size: %u\n" ), ControlFile .blcksz );
161+ printf (_ ("Blocks per segment of large relation: %u\n" ), ControlFile .relseg_size );
162+ printf (_ ("Maximum length of identifiers: %u\n" ), ControlFile .nameDataLen );
163+ printf (_ ("Maximum number of function arguments: %u\n" ), ControlFile .funcMaxArgs );
164+ printf (_ ("Date/time type storage: %s\n" ),
165+ (ControlFile .enableIntTimes ? _ ("64-bit integers" ) : _ ("Floating point" )));
166+ printf (_ ("Maximum length of locale name: %u\n" ), ControlFile .localeBuflen );
167+ printf (_ ("LC_COLLATE: %s\n" ), ControlFile .lc_collate );
168+ printf (_ ("LC_CTYPE: %s\n" ), ControlFile .lc_ctype );
169+
170+ return 0 ;
152171}
0 commit comments