1111 *
1212 *
1313 * IDENTIFICATION
14- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.145 2000/06/02 15:57:22 momjian Exp $
14+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.146 2000/06/04 01:44:31 petere Exp $
1515 *
1616 * NOTES
1717 *
3333 *
3434 *-------------------------------------------------------------------------
3535 */
36+ #include "postgres.h"
37+
3638#include <unistd.h>
3739#include <signal.h>
3840#include <sys/wait.h>
4648#include <time.h>
4749#include <sys/param.h>
4850
49- #include "postgres.h"
5051/* moved here to prevent double define */
5152#ifdef HAVE_NETDB_H
5253#include <netdb.h>
5354#endif
5455
55- #ifndef MAXHOSTNAMELEN
56- #define MAXHOSTNAMELEN 256
57- #endif
58-
5956#ifdef HAVE_LIMITS_H
6057#include <limits.h>
6158#else
7269#include "getopt.h"
7370#endif
7471
75- #ifndef HAVE_GETHOSTNAME
76- #include "port-protos.h"
77- #endif
78-
7972#include "commands/async.h"
8073#include "lib/dllist.h"
8174#include "libpq/auth.h"
@@ -191,8 +184,6 @@ static volatile bool got_SIGHUP = false;
191184/*
192185 * Default Values
193186 */
194- static char Execfile [MAXPGPATH ];
195-
196187static int ServerSock_INET = INVALID_SOCK ;/* stream socket server */
197188
198189#if !defined(__CYGWIN32__ )&& !defined(__QNX__ )
@@ -278,7 +269,7 @@ static void SignalChildren(SIGNAL_ARGS);
278269static int CountChildren (void );
279270static int
280271SetOptsFile (char * progname ,int port ,char * datadir ,
281- int assert ,int nbuf ,char * execfile ,
272+ int assert ,int nbuf ,
282273int debuglvl ,int netserver ,
283274#ifdef USE_SSL
284275int securenetserver ,
@@ -368,61 +359,17 @@ int
368359PostmasterMain (int argc ,char * argv [])
369360{
370361int opt ;
371- char * hostName ;
372362int status ;
373363int silentflag = 0 ;
374364bool DataDirOK ;/* We have a usable PGDATA value */
375- char hostbuf [MAXHOSTNAMELEN ];
376- int nonblank_argc ;
377365char original_extraoptions [MAXPGPATH ];
378366
379367* original_extraoptions = '\0' ;
380368
381- #ifndef HAVE_SETPROCTITLE
382- /*
383- * We need four params so we can display status. If we don't get
384- * them from the user, let's make them ourselves.
385- */
386- if (argc < 5 )
387- {
388- int i ;
389- char * new_argv [6 ];
390-
391- for (i = 0 ;i < argc ;i ++ )
392- new_argv [i ]= argv [i ];
393- for (;i < 5 ;i ++ )
394- new_argv [i ]= "" ;
395- new_argv [5 ]= NULL ;
396-
397- if (!Execfile [0 ]&& FindExec (Execfile ,argv [0 ],"postmaster" )< 0 )
398- {
399- fprintf (stderr ,"%s: could not find postmaster to execute...\n" ,
400- argv [0 ]);
401- exit (1 );
402- }
403- new_argv [0 ]= Execfile ;
404-
405- execv (new_argv [0 ],new_argv );
406-
407- /* How did we get here? Error! */
408- perror (new_argv [0 ]);
409- fprintf (stderr ,"PostmasterMain execv failed on %s\n" ,argv [0 ]);
410- exit (1 );
411- }
412- #endif
413-
414369progname = argv [0 ];
415370real_argv = argv ;
416371real_argc = argc ;
417372
418- /*
419- * don't process any dummy args we placed at the end for status
420- * display
421- */
422- for (nonblank_argc = argc ;nonblank_argc > 0 ;nonblank_argc -- )
423- if (argv [nonblank_argc - 1 ]!= NULL && argv [nonblank_argc - 1 ][0 ]!= '\0' )
424- break ;
425-
426373/*
427374 * for security, no dir or file created can be group or other
428375 * accessible
@@ -431,13 +378,6 @@ PostmasterMain(int argc, char *argv[])
431378
432379ResetAllOptions ();
433380
434- if (!(hostName = getenv ("PGHOST" )))
435- {
436- if (gethostname (hostbuf ,MAXHOSTNAMELEN )< 0 )
437- strcpy (hostbuf ,"localhost" );
438- hostName = hostbuf ;
439- }
440-
441381MyProcPid = getpid ();
442382DataDir = getenv ("PGDATA" );/* default value */
443383
@@ -455,7 +395,7 @@ PostmasterMain(int argc, char *argv[])
455395 * will occur.
456396 */
457397opterr = 1 ;
458- while ((opt = getopt (nonblank_argc ,argv ,"A:a:B:b:D:d:Film:MN:no:p:Ss-:" ))!= EOF )
398+ while ((opt = getopt (argc ,argv ,"A:a:B:b:D:d:Film:MN:no:p:Ss-:" ))!= EOF )
459399{
460400if (opt == 'D' )
461401DataDir = optarg ;
@@ -472,7 +412,7 @@ PostmasterMain(int argc, char *argv[])
472412ProcessConfigFile (PGC_POSTMASTER );
473413
474414IgnoreSystemIndexes (false);
475- while ((opt = getopt (nonblank_argc ,argv ,"A:a:B:b:D:d:Film:MN:no:p:Ss-:" ))!= EOF )
415+ while ((opt = getopt (argc ,argv ,"A:a:B:b:D:d:Film:MN:no:p:Ss-:" ))!= EOF )
476416{
477417switch (opt )
478418{
@@ -496,15 +436,7 @@ PostmasterMain(int argc, char *argv[])
496436NBuffers = atoi (optarg );
497437break ;
498438case 'b' :
499- /* Set the backend executable file to use. */
500- if (!ValidateBinary (optarg ))
501- StrNCpy (Execfile ,optarg ,MAXPGPATH );
502- else
503- {
504- fprintf (stderr ,"%s: invalid backend \"%s\"\n" ,
505- progname ,optarg );
506- exit (2 );
507- }
439+ /* Can no longer set the backend executable file to use. */
508440break ;
509441case 'D' :
510442/* already done above */
@@ -630,13 +562,6 @@ PostmasterMain(int argc, char *argv[])
630562exit (1 );
631563}
632564
633- if (!Execfile [0 ]&& FindExec (Execfile ,argv [0 ],"postgres" )< 0 )
634- {
635- fprintf (stderr ,"%s: could not find backend to execute...\n" ,
636- argv [0 ]);
637- exit (1 );
638- }
639-
640565#ifdef USE_SSL
641566if (!NetServer && SecureNetServer )
642567{
@@ -649,7 +574,7 @@ PostmasterMain(int argc, char *argv[])
649574
650575if (NetServer )
651576{
652- status = StreamServerPort (hostName , (unsigned short )PostPortName ,& ServerSock_INET );
577+ status = StreamServerPort (AF_INET , (unsigned short )PostPortName ,& ServerSock_INET );
653578if (status != STATUS_OK )
654579{
655580fprintf (stderr ,"%s: cannot create INET stream port\n" ,
@@ -659,7 +584,7 @@ PostmasterMain(int argc, char *argv[])
659584}
660585
661586#if !defined(__CYGWIN32__ )&& !defined(__QNX__ )
662- status = StreamServerPort (NULL , (unsigned short )PostPortName ,& ServerSock_UNIX );
587+ status = StreamServerPort (AF_UNIX , (unsigned short )PostPortName ,& ServerSock_UNIX );
663588if (status != STATUS_OK )
664589{
665590fprintf (stderr ,"%s: cannot create UNIX stream port\n" ,
@@ -696,7 +621,6 @@ PostmasterMain(int argc, char *argv[])
696621assert_enabled ,/* whether -A is specified
697622 * or not */
698623NBuffers ,/* -B: number of shared buffers */
699- Execfile ,/* -b: postgres executable file */
700624DebugLvl ,/* -d: debug level */
701625NetServer ,/* -i: accept connection from INET */
702626#ifdef USE_SSL
@@ -785,7 +709,6 @@ pmdaemonize(char *extraoptions)
785709assert_enabled ,/* whether -A is specified
786710 * or not */
787711NBuffers ,/* -B: number of shared buffers */
788- Execfile ,/* -b: postgres executable file */
789712DebugLvl ,/* -d: debug level */
790713NetServer ,/* -i: accept connection from INET */
791714#ifdef USE_SSL
@@ -1905,7 +1828,6 @@ DoBackend(Port *port)
19051828{
19061829char * av [ARGV_SIZE * 2 ];
19071830int ac = 0 ;
1908- char execbuf [MAXPGPATH ];
19091831char debugbuf [ARGV_SIZE ];
19101832char protobuf [ARGV_SIZE ];
19111833char dbbuf [ARGV_SIZE ];
@@ -1958,26 +1880,7 @@ DoBackend(Port *port)
19581880 * ----------------
19591881 */
19601882
1961- StrNCpy (execbuf ,Execfile ,MAXPGPATH );
1962- av [ac ++ ]= execbuf ;
1963-
1964- /*
1965- * We need to set our argv[0] to an absolute path name because some
1966- * OS's use this for dynamic loading, like BSDI. Without it, when we
1967- * change directories to the database dir, the dynamic loader can't
1968- * find the base executable and fails. Another advantage is that this
1969- * changes the 'ps' displayed process name on some platforms. It does
1970- * on BSDI. That's a big win.
1971- */
1972-
1973- #ifndef linux
1974-
1975- /*
1976- * This doesn't work on linux and overwrites the only valid pointer to
1977- * the argv buffer. See PS_INIT_STATUS macro.
1978- */
1979- real_argv [0 ]= Execfile ;
1980- #endif
1883+ av [ac ++ ]= "postgres" ;
19811884
19821885/*
19831886 * Pass the requested debugging level along to the backend. Level one
@@ -2229,7 +2132,6 @@ SSDataBase(bool startup)
22292132{
22302133char * av [ARGV_SIZE * 2 ];
22312134int ac = 0 ;
2232- char execbuf [MAXPGPATH ];
22332135char nbbuf [ARGV_SIZE ];
22342136char dbbuf [ARGV_SIZE ];
22352137
@@ -2244,8 +2146,7 @@ SSDataBase(bool startup)
22442146ServerSock_UNIX = INVALID_SOCK ;
22452147#endif
22462148
2247- StrNCpy (execbuf ,Execfile ,MAXPGPATH );
2248- av [ac ++ ]= execbuf ;
2149+ av [ac ++ ]= "postgres" ;
22492150
22502151av [ac ++ ]= "-d" ;
22512152
@@ -2294,7 +2195,7 @@ SSDataBase(bool startup)
22942195 */
22952196static int
22962197SetOptsFile (char * progname ,int port ,char * datadir ,
2297- int assert ,int nbuf ,char * execfile ,
2198+ int assert ,int nbuf ,
22982199int debuglvl ,int netserver ,
22992200#ifdef USE_SSL
23002201int securenetserver ,
@@ -2324,7 +2225,7 @@ SetOptsFile(char *progname, int port, char *datadir,
23242225strcat (opts ,buf );
23252226}
23262227
2327- snprintf (buf ,sizeof (buf ),"-B %d\n-b %s\n " ,nbuf , execfile );
2228+ snprintf (buf ,sizeof (buf ),"-B %d\n" ,nbuf );
23282229strcat (opts ,buf );
23292230
23302231if (debuglvl )