1
1
/*-------------------------------------------------------------------------
2
2
*
3
3
* main.c
4
- * Stub main() routine for the postgres backend.
4
+ * Stub main() routine for the postgres executable.
5
+ *
6
+ * This does some essential startup tasks for any incarnation of postgres
7
+ * (postmaster, standalone backend, or standalone bootstrap mode) and then
8
+ * dispatches to the proper FooMain() routine for the incarnation.
9
+ *
5
10
*
6
11
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
7
12
* Portions Copyright (c) 1994, Regents of the University of California
8
13
*
9
14
*
10
15
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.34 2000/11/16 05:51:00 momjian Exp $
16
+ * $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.35 2000/11/25 03:45:47 tgl Exp $
12
17
*
13
18
*-------------------------------------------------------------------------
14
19
*/
15
20
#include "postgres.h"
16
21
17
22
#include <pwd.h>
18
23
#include <unistd.h>
24
+ #ifdef USE_LOCALE
25
+ #include <locale.h>
26
+ #endif
19
27
20
28
#if defined(__alpha ) && !defined(linux ) && !defined(__FreeBSD__ )
21
29
#include <sys/sysinfo.h>
25
33
#undef ASSEMBLER
26
34
#endif
27
35
28
- #ifdef USE_LOCALE
29
- #include <locale.h>
30
- #endif
31
36
#include "miscadmin.h"
32
37
#include "bootstrap/bootstrap.h"
33
38
#include "tcop/tcopprot.h"
34
39
40
+
35
41
#define NOROOTEXEC "\
36
- \n\"root\" execution of the PostgreSQL backend is not permitted.\n\n\
37
- The backend must be started under its own userid to prevent\n\
42
+ \n\"root\" execution of the PostgreSQL server is not permitted.\n\n\
43
+ The server must be started under an unprivileged userid to prevent\n\
38
44
a possible system security compromise. See the INSTALL file for\n\
39
- more information on how to properly start the postmaster.\n\n"
45
+ more information on how to properly start the server.\n\n"
46
+
40
47
41
48
int
42
49
main (int argc , char * argv [])
43
50
{
44
51
int len ;
52
+ struct passwd * pw ;
53
+
54
+ /*
55
+ * Place platform-specific startup hacks here. This is the right
56
+ * place to put code that must be executed early in launch of either
57
+ * a postmaster, a standalone backend, or a standalone bootstrap run.
58
+ * Note that this code will NOT be executed when a backend or
59
+ * sub-bootstrap run is forked by the postmaster.
60
+ *
61
+ * XXX The need for code here is proof that the platform in question
62
+ * is too brain-dead to provide a standard C execution environment
63
+ * without help. Avoid adding more here, if you can.
64
+ */
45
65
46
66
#if defined(__alpha )
47
67
#ifdef NOFIXADE
@@ -52,78 +72,89 @@ main(int argc, char *argv[])
52
72
int buffer [] = {SSIN_UACPROC , UAC_NOPRINT };
53
73
54
74
#endif /* NOPRINTADE */
55
- #endif
75
+ #endif /* __alpha */
56
76
57
- #ifdef USE_LOCALE
58
- setlocale (LC_CTYPE , "" ); /* take locale information from an
59
- * environment */
60
- setlocale (LC_COLLATE , "" );
61
- setlocale (LC_MONETARY , "" );
62
- #endif
63
77
#if defined(NOFIXADE ) || defined(NOPRINTADE )
64
78
65
- /*
66
- * Must be first so that the bootstrap code calls it, too. (Only
67
- * needed on some RISC architectures.)
68
- */
69
-
70
79
#if defined(ultrix4 )
71
80
syscall (SYS_sysmips , MIPS_FIXADE , 0 , NULL , NULL , NULL );
72
81
#endif
73
82
74
83
#if defined(__alpha )
75
84
if (setsysinfo (SSI_NVPAIRS , buffer , 1 , (caddr_t ) NULL ,
76
85
(unsigned long ) NULL ) < 0 )
77
- elog ( NOTICE , "setsysinfo failed: %d\n" , errno );
86
+ fprintf ( stderr , "setsysinfo failed: %d\n" , errno );
78
87
#endif
79
88
80
89
#endif /* NOFIXADE || NOPRINTADE */
81
90
91
+ #ifdef __BEOS__
92
+ /* BeOS-specific actions on startup */
93
+ beos_startup (argc ,argv );
94
+ #endif
95
+
82
96
/*
83
- * use one executable for both postgres and postmaster, invoke one or
84
- * the other depending on the name of the executable
97
+ * Not-quite-so-platform-specific startup environment checks.
98
+ * Still best to minimize these.
85
99
*/
86
- len = strlen (argv [0 ]);
87
100
88
- /* OK this is going to seem weird, but BeOS is presently basically
89
- * a single user system. There is work going on, but at present it'll
90
- * say that every user is uid 0, i.e. root. We'll inhibit this check
91
- * until Be get the system working with multiple users!!
92
- */
101
+ /*
102
+ * Make sure we are not running as root.
103
+ *
104
+ * BeOS currently runs everything as root :-(, so this check must
105
+ * be temporarily disabled there...
106
+ */
93
107
#ifndef __BEOS__
94
- if (! geteuid ())
108
+ if (geteuid () == 0 )
95
109
{
96
110
fprintf (stderr , "%s" , NOROOTEXEC );
97
111
exit (1 );
98
112
}
99
113
#endif /* __BEOS__ */
100
114
101
- #ifdef __BEOS__
102
- /* Specific beos actions on startup */
103
- beos_startup (argc ,argv );
115
+ /*
116
+ * Set up locale information from environment, in only the categories
117
+ * needed by Postgres; leave other categories set to default "C".
118
+ * (Note that CTYPE and COLLATE will be overridden later from pg_control
119
+ * if we are in an already-initialized database. We set them here so
120
+ * that they will be available to fill pg_control during initdb.)
121
+ */
122
+ #ifdef USE_LOCALE
123
+ setlocale (LC_CTYPE , "" );
124
+ setlocale (LC_COLLATE , "" );
125
+ setlocale (LC_MONETARY , "" );
104
126
#endif
105
127
128
+ /*
129
+ * Now dispatch to one of PostmasterMain, PostgresMain, or BootstrapMain
130
+ * depending on the program name (and possibly first argument) we
131
+ * were called with. The lack of consistency here is historical.
132
+ */
133
+ len = strlen (argv [0 ]);
106
134
107
- if (len >= 10 && !strcmp (argv [0 ] + len - 10 , "postmaster" ))
135
+ if (len >= 10 && strcmp (argv [0 ] + len - 10 , "postmaster" ) == 0 )
136
+ {
137
+ /* Called as "postmaster" */
108
138
exit (PostmasterMain (argc , argv ));
139
+ }
109
140
110
141
/*
111
- * if the first argument is "-boot", then invoke the backend in
112
- * bootstrap mode
142
+ * If the first argument is "-boot", then invoke bootstrap mode.
143
+ * Note we remove "-boot" from the arguments passed on to BootstrapMain.
113
144
*/
114
145
if (argc > 1 && strcmp (argv [1 ], "-boot" ) == 0 )
115
- exit (BootstrapMain (argc - 1 , argv + 1 )); /* remove the -boot arg
116
- * from the command line */
117
- else
146
+ exit (BootstrapMain (argc - 1 , argv + 1 ));
147
+
148
+ /*
149
+ * Otherwise we're a standalone backend. Invoke PostgresMain,
150
+ * specifying current userid as the "authenticated" Postgres user name.
151
+ */
152
+ pw = getpwuid (geteuid ());
153
+ if (pw == NULL )
118
154
{
119
- struct passwd * pw ;
120
-
121
- pw = getpwuid (geteuid ());
122
- if (!pw )
123
- {
124
- fprintf (stderr , "%s: invalid current euid" , argv [0 ]);
125
- exit (1 );
126
- }
127
- exit (PostgresMain (argc , argv , argc , argv , pw -> pw_name ));
155
+ fprintf (stderr , "%s: invalid current euid" , argv [0 ]);
156
+ exit (1 );
128
157
}
158
+
159
+ exit (PostgresMain (argc , argv , argc , argv , pw -> pw_name ));
129
160
}
0 commit comments