main.c 2.57 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * main.c
4
 *	  Stub main() routine for the postgres backend.
5 6 7 8 9
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
10
 *	  $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.24 1999/07/13 20:12:46 momjian Exp $
11 12 13
 *
 *-------------------------------------------------------------------------
 */
14
#include <stdio.h>
15
#include <string.h>
16
#include <unistd.h>
17

18
#if defined(__alpha__) && !defined(linux)
19 20 21 22 23 24
#include <sys/sysinfo.h>
#include <machine/hal_sysinfo.h>
#define ASSEMBLER
#include <sys/proc.h>
#undef ASSEMBLER
#endif
25
#include "postgres.h"
26 27
#ifdef USE_LOCALE
#include <locale.h>
28
#endif
29
#include "miscadmin.h"
30
#include "bootstrap/bootstrap.h"/* for BootstrapMain() */
31 32
#include "tcop/tcopprot.h"		/* for PostgresMain() */

33
#define NOROOTEXEC "\
34 35 36 37
\n\"root\" execution of the PostgreSQL backend is not permitted.\n\n\
The backend must be started under it's own userid to prevent\n\
a possible system security compromise. See the INSTALL file for\n\
more information on how to properly start the postmaster.\n\n"
38

39 40 41
int
main(int argc, char *argv[])
{
42
	int			len;
43

44
#if defined(__alpha__)
45 46 47
#ifdef NOFIXADE
	int			buffer[] = {SSIN_UACPROC, UAC_SIGBUS};

48
#endif	 /* NOFIXADE */
49 50 51
#ifdef NOPRINTADE
	int			buffer[] = {SSIN_UACPROC, UAC_NOPRINT};

52
#endif	 /* NOPRINTADE */
53 54
#endif

55
#ifdef USE_LOCALE
56
	setlocale(LC_CTYPE, "");	/* take locale information from an
57
								 * environment */
58 59
	setlocale(LC_COLLATE, "");
	setlocale(LC_MONETARY, "");
60
#endif
61
#if defined(NOFIXADE) || defined(NOPRINTADE)
62

63 64 65 66
	/*
	 * Must be first so that the bootstrap code calls it, too. (Only
	 * needed on some RISC architectures.)
	 */
67 68

#if defined(ultrix4)
69
	syscall(SYS_sysmips, MIPS_FIXADE, 0, NULL, NULL, NULL);
70 71
#endif

72
#if defined(__alpha__)
73
	if (setsysinfo(SSI_NVPAIRS, buffer, 1, (caddr_t) NULL,
74
				   (unsigned long) NULL) < 0)
75
		elog(NOTICE, "setsysinfo failed: %d\n", errno);
76
#endif
77

78
#endif	 /* NOFIXADE || NOPRINTADE */
79 80 81 82 83 84 85 86 87 88 89 90

	/*
	 * use one executable for both postgres and postmaster, invoke one or
	 * the other depending on the name of the executable
	 */
	len = strlen(argv[0]);

	if (!geteuid())
	{
		fprintf(stderr, "%s", NOROOTEXEC);
		exit(1);
	}
91

92 93
	if (len >= 10 && !strcmp(argv[0] + len - 10, "postmaster"))
		exit(PostmasterMain(argc, argv));
94

95 96 97 98 99 100 101 102
	/*
	 * if the first argument is "-boot", then invoke the backend in
	 * bootstrap mode
	 */
	if (argc > 1 && strcmp(argv[1], "-boot") == 0)
		exit(BootstrapMain(argc - 1, argv + 1));		/* remove the -boot arg
														 * from the command line */
	else
103
		exit(PostgresMain(argc, argv, argc, argv));
104
}