Index: initdb.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/initdb/initdb.c,v
retrieving revision 1.110
diff -c -r1.110 initdb.c
*** initdb.c	18 Feb 2006 16:15:23 -0000	1.110
--- initdb.c	22 Feb 2006 02:21:59 -0000
***************
*** 2450,2455 ****
--- 2450,2460 ----
  								 * environment */
  	char		bin_dir[MAXPGPATH];
  	char	   *pg_data_native;
+ 
+ #ifdef WIN32
+ 	char      *orig_pgdata = NULL;
+ #endif
+ 
  	static const char *subdirs[] = {
  		"global",
  		"pg_xlog",
***************
*** 2560,2565 ****
--- 2565,2573 ----
  	if (optind < argc)
  	{
  		pg_data = xstrdup(argv[optind]);
+ #ifdef WIN32
+ 		orig_pgdata = xstrdup(pg_data);
+ #endif
  		optind++;
  	}
  
***************
*** 2648,2660 ****
      {
          PROCESS_INFORMATION pi;
          char *cmdline;
!         
          ZeroMemory(&pi, sizeof(pi));
  
!         cmdline = pg_malloc(strlen(GetCommandLine()) + 19);
          strcpy(cmdline, GetCommandLine());
!         strcat(cmdline, " --restrictedexec");
          
          if (!CreateRestrictedProcess(cmdline, &pi))
          {
              fprintf(stderr,"Failed to re-exec with restricted token: %lu.\n", GetLastError());
--- 2656,2687 ----
      {
          PROCESS_INFORMATION pi;
          char *cmdline;
! 
          ZeroMemory(&pi, sizeof(pi));
  
!         cmdline = pg_malloc(strlen(GetCommandLine()) + 20);
          strcpy(cmdline, GetCommandLine());
! 
! 		if (orig_pgdata  != NULL)
! 		{
! 			/* find the LAST occurrence of the data arg on the command line */
! 			char *data_arg;
! 			char *next_pos;
! 			size_t orig_len = strlen(orig_pgdata);
! 
! 			data_arg=strstr(cmdline,orig_pgdata);
! 			while ((next_pos=strstr(data_arg+1,orig_pgdata)) != NULL)
! 				data_arg = next_pos;
! 			/* wipe it out so we can add the extra arg */
! 			*data_arg = '\0';
! 		}
! 		
!         strcat(cmdline, " --restrictedexec ");
          
+ 		/* put back original arg if we wiped it out above */
+ 		if (orig_pgdata  != NULL)
+ 			strcat(cmdline,orig_pgdata);
+ 
          if (!CreateRestrictedProcess(cmdline, &pi))
          {
              fprintf(stderr,"Failed to re-exec with restricted token: %lu.\n", GetLastError());
