]> granicus.if.org Git - postgresql/blob - src/backend/main/main.c
Make pgsql compile on FreeBSD-alpha.
[postgresql] / src / backend / main / main.c
1 /*-------------------------------------------------------------------------
2  *
3  * main.c
4  *        Stub main() routine for the postgres backend.
5  *
6  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *        $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.34 2000/11/16 05:51:00 momjian Exp $
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16
17 #include <pwd.h>
18 #include <unistd.h>
19
20 #if defined(__alpha) && !defined(linux) && !defined(__FreeBSD__)
21 #include <sys/sysinfo.h>
22 #include "machine/hal_sysinfo.h"
23 #define ASSEMBLER
24 #include <sys/proc.h>
25 #undef ASSEMBLER
26 #endif
27
28 #ifdef USE_LOCALE
29 #include <locale.h>
30 #endif
31 #include "miscadmin.h"
32 #include "bootstrap/bootstrap.h"
33 #include "tcop/tcopprot.h"
34
35 #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\
38 a possible system security compromise. See the INSTALL file for\n\
39 more information on how to properly start the postmaster.\n\n"
40
41 int
42 main(int argc, char *argv[])
43 {
44         int                     len;
45
46 #if defined(__alpha)
47 #ifdef NOFIXADE
48         int                     buffer[] = {SSIN_UACPROC, UAC_SIGBUS};
49
50 #endif   /* NOFIXADE */
51 #ifdef NOPRINTADE
52         int                     buffer[] = {SSIN_UACPROC, UAC_NOPRINT};
53
54 #endif   /* NOPRINTADE */
55 #endif
56
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 #if defined(NOFIXADE) || defined(NOPRINTADE)
64
65         /*
66          * Must be first so that the bootstrap code calls it, too. (Only
67          * needed on some RISC architectures.)
68          */
69
70 #if defined(ultrix4)
71         syscall(SYS_sysmips, MIPS_FIXADE, 0, NULL, NULL, NULL);
72 #endif
73
74 #if defined(__alpha)
75         if (setsysinfo(SSI_NVPAIRS, buffer, 1, (caddr_t) NULL,
76                                    (unsigned long) NULL) < 0)
77                 elog(NOTICE, "setsysinfo failed: %d\n", errno);
78 #endif
79
80 #endif   /* NOFIXADE || NOPRINTADE */
81
82         /*
83          * use one executable for both postgres and postmaster, invoke one or
84          * the other depending on the name of the executable
85          */
86         len = strlen(argv[0]);
87
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  */
93 #ifndef __BEOS__
94 if (!geteuid())
95         {
96                 fprintf(stderr, "%s", NOROOTEXEC);
97                 exit(1);
98         }
99 #endif /* __BEOS__ */
100
101 #ifdef __BEOS__
102         /* Specific beos actions on startup */
103         beos_startup(argc,argv);
104 #endif
105
106
107         if (len >= 10 && !strcmp(argv[0] + len - 10, "postmaster"))
108                 exit(PostmasterMain(argc, argv));
109
110         /*
111          * if the first argument is "-boot", then invoke the backend in
112          * bootstrap mode
113          */
114         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
118         {
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));
128         }
129 }