Re: [HACKERS] Odd problem with read_pg_options ...

Bruce Momjian <maillist@candle.pha.pa.us>

From: Bruce Momjian <maillist@candle.pha.pa.us>
To: dz@cs.unitn.it (Massimo Dal Zotto)
Cc: hackers@postgreSQL.org, scrappy@hub.org
Date: 1998-10-16T06:05:28Z
Lists: pgsql-hackers
> The problem is that read_pg_options needs DataDir to read its file but
> DataDir is set after read_pg_options if postgres is called interactively.
> If postgres is forked by postgres DataDir is read from the PGDATA enviromnent
> variable set by the postmaster and this explains while the bug disappears.
> I have written this patch but I don't like it. Any better idea?

I have applied it.  You can improve it later, if you wish.

> 
> *** src/backend/utils/init/globals.c.orig	Thu Oct 15 00:13:03 1998
> --- src/backend/utils/init/globals.c	Thu Oct 15 00:13:07 1998
> ***************
> *** 46,52 ****
>   struct Port *MyProcPort;
>   long		MyCancelKey;
>   
> ! char	   *DataDir;
>   
>    /*
>     * The PGDATA directory user says to use, or defaults to via environment
> --- 46,52 ----
>   struct Port *MyProcPort;
>   long		MyCancelKey;
>   
> ! char	   *DataDir = NULL;
>   
>    /*
>     * The PGDATA directory user says to use, or defaults to via environment
> *** src/backend/utils/misc/trace.c.orig	Thu Sep  3 09:00:39 1998
> --- src/backend/utils/misc/trace.c	Thu Oct 15 00:18:49 1998
> ***************
> *** 343,348 ****
> --- 343,353 ----
>   	char	   *s,
>   			   *p;
>   
> + 	if (!DataDir) {
> + 	    fprintf(stderr, "read_pg_options: DataDir not defined\n");
> + 	    return;
> + 	}
> + 
>   	sprintf(buffer, "%s/%s", DataDir, "pg_options");
>   	if ((fd = open(buffer, O_RDONLY)) < 0)
>   		return;
> *** src/backend/tcop/postgres.c.orig	Tue Sep  1 09:01:27 1998
> --- src/backend/tcop/postgres.c	Thu Oct 15 00:23:24 1998
> ***************
> *** 1049,1055 ****
> --- 1049,1061 ----
>   				break;
>   
>   			case 'D':			/* PGDATA directory */
> + 			        if (!DataDir) {
> + 				    DataDir = optarg;
> + 				    /* must be done after DataDir is defined */
> + 				    read_pg_options(0);
> + 				}
>   				DataDir = optarg;
> + 				break;
>   
>   			case 'd':			/* debug level */
>   				flagQ = false;
> 
> -- 
> Massimo Dal Zotto
> 
> +----------------------------------------------------------------------+
> |  Massimo Dal Zotto                email:  dz@cs.unitn.it             |
> |  Via Marconi, 141                 phone:  ++39-461-534251            |
> |  38057 Pergine Valsugana (TN)     www:  http://www.cs.unitn.it/~dz/  |
> |  Italy                            pgp:  finger dz@tango.cs.unitn.it  |
> +----------------------------------------------------------------------+
> 
> 


-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026