Re: [PATCHES] psql \i handling ~ in specified file name

2004-01-09 Thread Bruce Momjian
Zach Irmen wrote:
 
 Bruce Momjian wrote:
  Yes, seems like that will be required.  Please use my attached version
  to make the adjustments.
 
 Ok. Adjustments made.  All psql commands should be handled.
 
  Zach Irmen wrote:
   And finally, I was wondering if arguments with leading pipes
   (e.g. |~/file) should  also get substituted.
 
  Yep, that too.
 
 Actually, I found out that popen calls seem to handle the tilde fine as
 this was already working on my FreeBSD box without
 substitution. I'm not sure if this is true for all Unix systems in
 general, but I won't bother putting that in unless it turns out
 to be needed.

Oh, yea, | should work fine because it uses the shell.  pipe manual
page says:

 The popen() function ``opens'' a process by creating an IPC connection,
 forking, and invoking the shell.

and

 The command argument is a pointer to a null-terminated string containing
 a shell command line.  This command is passed to /bin/sh using the -c
 flag; interpretation, if any, is performed by the shell.

so we are find with pipe already.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


Re: [PATCHES] psql \i handling ~ in specified file name

2004-01-09 Thread Bruce Momjian

Patch applied.  Thanks.

---

Zach Irmen wrote:
 
 Bruce Momjian wrote:
  Yes, seems like that will be required.  Please use my attached version
  to make the adjustments.
 
 Ok. Adjustments made.  All psql commands should be handled.
 
  Zach Irmen wrote:
   And finally, I was wondering if arguments with leading pipes
   (e.g. |~/file) should  also get substituted.
 
  Yep, that too.
 
 Actually, I found out that popen calls seem to handle the tilde fine as
 this was already working on my FreeBSD box without
 substitution. I'm not sure if this is true for all Unix systems in
 general, but I won't bother putting that in unless it turns out
 to be needed.
 
 Index: command.c
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/command.c,v
 retrieving revision 1.108
 diff -c -r1.108 command.c
 *** command.c 1 Dec 2003 22:21:54 -   1.108
 --- command.c 9 Jan 2004 06:51:55 -
 ***
 *** 413,418 
 --- 413,419 
   else
   {
   fname = scan_option(string, OT_NORMAL, NULL, true);
 + expand_tilde(fname);
   status = do_edit(fname, query_buf) ? CMD_NEWEDIT : CMD_ERROR;
   free(fname);
   }
 ***
 *** 494,500 
 --- 495,504 
   if (!fname)
   pset.gfname = NULL;
   else
 + {
 + expand_tilde(fname);
   pset.gfname = xstrdup(fname);
 + }
   free(fname);
   status = CMD_SEND;
   }
 ***
 *** 531,536 
 --- 535,541 
   }
   else
   {
 + expand_tilde(fname);
   success = (process_file(fname) == EXIT_SUCCESS);
   free(fname);
   }
 ***
 *** 561,567 
 --- 566,575 
   success = false;
   }
   else
 + {
 + expand_tilde(opt2);
   success = do_lo_export(opt1, opt2);
 + }
   }
 
   else if (strcmp(cmd + 3, import) == 0)
 ***
 *** 572,578 
 --- 580,589 
   success = false;
   }
   else
 + {
 + expand_tilde(opt1);
   success = do_lo_import(opt1, opt2);
 + }
   }
 
   else if (strcmp(cmd + 3, list) == 0)
 ***
 *** 602,607 
 --- 613,619 
   {
   char   *fname = scan_option(string, OT_FILEPIPE, NULL, true);
 
 + expand_tilde(fname);
   success = setQFout(fname);
   free(fname);
   }
 ***
 *** 653,658 
 --- 665,671 
   {
   char   *fname = scan_option(string, OT_NORMAL, NULL, true);
 
 + expand_tilde(fname);
   success = saveHistory(fname ? fname : /dev/tty);
 
   if (success  !quiet  fname)
 ***
 *** 771,776 
 --- 784,790 
   else
   {
   fname = scan_option(string, OT_FILEPIPE, NULL, true);
 + expand_tilde(fname);
 
   if (!fname)
   {
 Index: common.c
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/common.c,v
 retrieving revision 1.78
 diff -c -r1.78 common.c
 *** common.c  29 Nov 2003 19:52:06 -  1.78
 --- common.c  9 Jan 2004 06:51:56 -
 ***
 *** 814,816 
 --- 814,878 
   else
   return PQuser(pset.db);
   }
 +
 +
 + /* expand_tilde
 +  *
 +  * substitute '~' with HOME or '~username' with username's home dir
 +  *
 +  */
 + char *
 + expand_tilde(char **filename)
 + {
 + if (!filename || !(*filename))
 + return NULL;
 +
 + /* MSDOS uses tilde for short versions of long file names, so skip it. */
 + #ifndef WIN32
 +
 + /* try tilde expansion */
 + if (**filename == '~')
 + {
 + char   *fn;
 + char   *home;
 + charoldp,
 +*p;
 + struct passwd *pw;
 +
 + fn = *filename;
 + home = NULL;
 +
 + p = fn + 1;
 + while (*p != '/'  *p != '\0')
 + p++;
 +
 + oldp = *p;
 + *p = '\0';
 +
 + if (*(fn + 1) == '\0')
 + home = getenv(HOME);
 + else if ((pw = getpwnam(fn + 1)) != NULL)
 + home = 

Re: [PATCHES] psql error in \? output on \w line

2004-01-09 Thread Bruce Momjian

Patch applied.  Thanks.

---

Zach Irmen wrote:
 As far as I can tell, the file argument for \w is required;
 this contradicts what \? says for it (namely that it's optional).
 A patch follows to fix this if it really is an error and not my
 misunderstanding.
 
 Zach Irmen
 
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/help.c,v
 retrieving revision 1.84
 diff -c -r1.84 help.c
 *** help.c  1 Dec 2003 22:34:48 -   1.84
 --- help.c  8 Jan 2004 03:02:10 -
 ***
 *** 195,201 
 fprintf(output, _(  \\p show the contents of the query 
 buffer\n));
 fprintf(output, _(  \\r reset (clear) the query buffer\n));
 fprintf(output, _(  \\s [FILE]  display history or save it to file\n));
 !   fprintf(output, _(  \\w [FILE]  write query buffer to file\n));
 fprintf(output, \n);
 
 fprintf(output, _(Input/Output\n));
 --- 195,201 
 fprintf(output, _(  \\p show the contents of the query 
 buffer\n));
 fprintf(output, _(  \\r reset (clear) the query buffer\n));
 fprintf(output, _(  \\s [FILE]  display history or save it to file\n));
 !   fprintf(output, _(  \\w FILEwrite query buffer to file\n));
 fprintf(output, \n);
 
 fprintf(output, _(Input/Output\n));
 
 ---(end of broadcast)---
 TIP 8: explain analyze is your friend
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [PATCHES] fork/exec patch: CreateProcess calls for Win32

2004-01-09 Thread Bruce Momjian

Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

---


Claudio Natoli wrote:
 
 For application to HEAD, pending community review.
 
 Drops in the CreateProcess calls for Win32 (essentially wrapping up the
 fork/exec portion of the port), and fixes a handful of whitespace issues
 (that no doubt I'm to blame for; my apologies) in the source base.
 
 Cheers,
 Claudio
 
 --- 
 Certain disclaimers and policies apply to all email sent from Memetrics.
 For the full text of these disclaimers and policies see 
 a
 href=http://www.memetrics.com/emailpolicy.html;http://www.memetrics.com/em
 ailpolicy.html/a
   
 

[ Attachment, skipping... ]

 
 ---(end of broadcast)---
 TIP 7: don't forget to increase your free space map settings

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


Re: [PATCHES] fork/exec patch: pre-CreateProcess finalization

2004-01-09 Thread Bruce Momjian
Tom Lane wrote:
 Jan Wieck [EMAIL PROTECTED] writes:
  Something after 2003/11/20 enhanced the query cancel handling. Namely, 
  CVS tip now responds to a query cancel with a postmaster restart 
  canceling all queries. Could the fork/exec stuff be responsible for this?
 
 Whoever changed this:
 
 status = ProcessStartupPacket(port, false);
 
 if (status != STATUS_OK)
 return 0;/* cancel request processed, or error */
 
 to this:
 
 status = ProcessStartupPacket(port, false);
 
 if (status != STATUS_OK)
 {
 ereport(LOG,
 (errmsg(connection startup failed)));
 proc_exit(status);
 }
 
 is responsible.  May we have an explanation of the thought process,
 if any?

Claudio specified the attached fix, which I have applied.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [PATCHES] fork/exec patch: pre-CreateProcess finalization

2004-01-09 Thread Bruce Momjian
Tom Lane wrote:
 Jan Wieck [EMAIL PROTECTED] writes:
  Something after 2003/11/20 enhanced the query cancel handling. Namely, 
  CVS tip now responds to a query cancel with a postmaster restart 
  canceling all queries. Could the fork/exec stuff be responsible for this?
 
 Whoever changed this:
 
 status = ProcessStartupPacket(port, false);
 
 if (status != STATUS_OK)
 return 0;/* cancel request processed, or error */
 
 to this:
 
 status = ProcessStartupPacket(port, false);
 
 if (status != STATUS_OK)
 {
 ereport(LOG,
 (errmsg(connection startup failed)));
 proc_exit(status);
 }
 
 is responsible.  May we have an explanation of the thought process,
 if any?

Claudio specified the attached fix, which I have applied (this time).

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: src/backend/postmaster/postmaster.c
===
RCS file: /cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v
retrieving revision 1.355
diff -c -c -r1.355 postmaster.c
*** src/backend/postmaster/postmaster.c 7 Jan 2004 18:56:27 -   1.355
--- src/backend/postmaster/postmaster.c 9 Jan 2004 23:08:01 -
***
*** 2450,2456 
{
ereport(LOG,
(errmsg(connection startup failed)));
!   proc_exit(status);
}
  
/*
--- 2450,2456 
{
ereport(LOG,
(errmsg(connection startup failed)));
!   proc_exit(0);
}
  
/*

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [PATCHES] fork/exec patch: pre-CreateProcess finalization

2004-01-09 Thread Bruce Momjian

Done and attached.

---

Tom Lane wrote:
 Bruce Momjian [EMAIL PROTECTED] writes:
  Claudio specified the attached fix, which I have applied (this time).
 
 The ereport must vanish back into its black hole, also.
 ProcessStartupPacket has already issued any appropriate log message.
 
  *** 2450,2456 
  {
  ereport(LOG,
  (errmsg(connection startup failed)));
  !   proc_exit(status);
  }
   
  /*
  --- 2450,2456 
  {
  ereport(LOG,
  (errmsg(connection startup failed)));
  !   proc_exit(0);
  }
   
  /*
 
   regards, tom lane
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: src/backend/postmaster/postmaster.c
===
RCS file: /cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v
retrieving revision 1.356
diff -c -c -r1.356 postmaster.c
*** src/backend/postmaster/postmaster.c 9 Jan 2004 23:11:39 -   1.356
--- src/backend/postmaster/postmaster.c 9 Jan 2004 23:25:36 -
***
*** 2447,2457 
status = ProcessStartupPacket(port, false);
  
if (status != STATUS_OK)
-   {
-   ereport(LOG,
-   (errmsg(connection startup failed)));
proc_exit(0);
-   }
  
/*
 * Now that we have the user and database name, we can set the process
--- 2447,2453 

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


[PATCHES] pg_ctl starting postmaster

2004-01-09 Thread Bruce Momjian
When pg_ctl is used to start the postmaster without the -w flag, it says

postmaster successfully started

when in fact it should be postmaster starting because it hasn't
started yet, or at least isn't accepting connections yet.  A wait for
start says:

waiting for postmaster to start...done
postmaster successfully started

which is accurate.

This applied patch makes that adjustment and a similar one for stop. 
Someone complained about this a few months ago.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: src/bin/pg_ctl/pg_ctl.sh
===
RCS file: /cvsroot/pgsql-server/src/bin/pg_ctl/pg_ctl.sh,v
retrieving revision 1.37
diff -c -c -r1.37 pg_ctl.sh
*** src/bin/pg_ctl/pg_ctl.sh29 Nov 2003 19:52:04 -  1.37
--- src/bin/pg_ctl/pg_ctl.sh10 Jan 2004 02:53:35 -
***
*** 299,305 
if [ $op = reload ];then
$silence_echo echo postmaster successfully signaled
else
!   $silence_echo echo postmaster successfully shut down
fi
  
  else # ! -f $PIDFILE
--- 299,309 
if [ $op = reload ];then
$silence_echo echo postmaster successfully signaled
else
!   if [ $wait = yes ];then
!   $silence_echo echo postmaster successfully shut down
!   else
!   $silence_echo echo postmaster shutting down
!   fi
fi
  
  else # ! -f $PIDFILE
***
*** 399,406 
fi
done
$silence_echo echo done
  fi
- $silence_echo echo postmaster successfully started
  fi # start or restart
  
  exit 0
--- 403,412 
fi
done
$silence_echo echo done
+   $silence_echo echo postmaster successfully started
+ else
+   $silence_echo echo postmaster starting
  fi
  fi # start or restart
  
  exit 0

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html