psql 'none' as a HISTFILE special case
If readline is used by psql, a history file is automatically used.
This patch adds the special file name 'none', which if set as the
HISTFILE parameter, will cause psql not to use the history file.
- Martin -
Attachments:
psql_allow_none_as_HISTFILE.diffapplication/octet-stream; name=psql_allow_none_as_HISTFILE.diffDownload
*** ./doc/src/sgml/ref/psql-ref.sgml.orig Mon Aug 21 19:20:36 2006
--- ./doc/src/sgml/ref/psql-ref.sgml Mon Aug 21 19:25:04 2006
***************
*** 2041,2046 ****
--- 2041,2055 ----
<application>psql</application> to maintain a separate history for
each database.
</para>
+ <para>
+ The special file name <filename>none</filename> will prevent
+ the use of the history file. That is, putting
+ <programlisting>
+ \set HISTFILE none
+ </programlisting>
+ in <filename>~/.psqlrc</filename> will cause
+ <application>psql</application> not to use a history file.
+ </para>
<note>
<para>
This feature was shamelessly plagiarized from
*** ./src/bin/psql/input.c.orig Mon Aug 21 19:20:36 2006
--- ./src/bin/psql/input.c Mon Aug 21 19:25:04 2006
***************
*** 308,315 ****
}
else
{
! psql_history = pg_strdup(GetVariable(pset.vars, "HISTFILE"));
! expand_tilde(&psql_history);
}
if (psql_history)
--- 308,320 ----
}
else
{
! if (strcmp(GetVariable(pset.vars, "HISTFILE"), "none") == 0) {
! /* user doesnt want a HISTFILE */
! psql_history = NULL;
! } else {
! psql_history = pg_strdup(GetVariable(pset.vars, "HISTFILE"));
! expand_tilde(&psql_history);
! }
}
if (psql_history)
On Mon, 2006-08-21 at 19:27 +0300, Martin Atukunda wrote:
If readline is used by psql, a history file is automatically used.
This patch adds the special file name 'none', which if set as the
HISTFILE parameter, will cause psql not to use the history file.
I think it would be cleaner to use a separate \set variable to control
whether a history file is written, rather than needlessly overloading
the meaning of HISTFILE.
-Neil
Neil Conway <neilc@samurai.com> writes:
On Mon, 2006-08-21 at 19:27 +0300, Martin Atukunda wrote:
If readline is used by psql, a history file is automatically used.
This patch adds the special file name 'none', which if set as the
HISTFILE parameter, will cause psql not to use the history file.
I think it would be cleaner to use a separate \set variable to control
whether a history file is written, rather than needlessly overloading
the meaning of HISTFILE.
Why is this useful at all? There's already the -n (don't use readline)
switch.
regards, tom lane
Tom Lane wrote:
Neil Conway <neilc@samurai.com> writes:
On Mon, 2006-08-21 at 19:27 +0300, Martin Atukunda wrote:
If readline is used by psql, a history file is automatically used.
This patch adds the special file name 'none', which if set as the
HISTFILE parameter, will cause psql not to use the history file.I think it would be cleaner to use a separate \set variable to control
whether a history file is written, rather than needlessly overloading
the meaning of HISTFILE.Why is this useful at all? There's already the -n (don't use readline)
switch.
Seems he wants readline without history, perhaps for security. Doesn't
setting HISTFILE to /dev/null work?
--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com
+ If your life is a hard drive, Christ can be your backup. +
On 8/21/06, Bruce Momjian <bruce@momjian.us> wrote:
Tom Lane wrote:
Neil Conway <neilc@samurai.com> writes:
On Mon, 2006-08-21 at 19:27 +0300, Martin Atukunda wrote:
If readline is used by psql, a history file is automatically used.
This patch adds the special file name 'none', which if set as the
HISTFILE parameter, will cause psql not to use the history file.I think it would be cleaner to use a separate \set variable to control
whether a history file is written, rather than needlessly overloading
the meaning of HISTFILE.Why is this useful at all? There's already the -n (don't use readline)
switch.Seems he wants readline without history, perhaps for security. Doesn't
setting HISTFILE to /dev/null work?
hmm, setting HISTFILE to /dev/null doesn't work on my MacOSX here. so
I whipped up this patch.
- Martin -
Am Freitag, 25. August 2006 17:03 schrieb Martin Atukunda:
hmm, setting HISTFILE to /dev/null doesn't work on my MacOSX here.
Please elaborate on "doesn't work".
--
Peter Eisentraut
http://developer.postgresql.org/~petere/
On 8/25/06, Peter Eisentraut <peter_e@gmx.net> wrote:
Am Freitag, 25. August 2006 17:03 schrieb Martin Atukunda:
hmm, setting HISTFILE to /dev/null doesn't work on my MacOSX here.
Please elaborate on "doesn't work".
without any .psqlrc file I get the following error when quitting a psql session:
could not save history to file "/Users/matlads/.psql_history": Invalid argument
When I set HISTFILE to /dev/null I get the following:
could not save history to file "/dev/null": Operation not permitted
- Martin -
"Martin Atukunda" <matlads@gmail.com> writes:
On 8/25/06, Peter Eisentraut <peter_e@gmx.net> wrote:
Please elaborate on "doesn't work".
without any .psqlrc file I get the following error when quitting a psql session:
could not save history to file "/Users/matlads/.psql_history": Invalid argument
That is fixed in CVS HEAD. The current coding looks like:
/*
* return value of write_history is not standardized across GNU
* readline and libedit. Therefore, check for errno becoming set
* to see if the write failed.
*/
errno = 0;
(void) write_history(fname);
if (errno == 0)
return true;
psql_error("could not save history to file \"%s\": %s\n",
fname, strerror(errno));
When I set HISTFILE to /dev/null I get the following:
could not save history to file "/dev/null": Operation not permitted
Hm. ktrace shows this happening:
23279 psql CALL open(0x302d70,0x601,0x1b6)
23279 psql NAMI "/dev/null"
23279 psql RET open 3
23279 psql CALL fchmod(0x3,0x180)
23279 psql RET fchmod -1 errno 1 Operation not permitted
23279 psql CALL close(0x3)
23279 psql RET close 0
23279 psql CALL write(0x2,0xbffff180,0x44)
23279 psql GIO fd 2 wrote 68 bytes
"could not save history to file "/dev/null": Operation not permitted
"
23279 psql RET write 68/0x44
23279 psql CALL exit(0)
There's probably no way to get Apple's libedit to not try the fchmod,
so what do we want to do here? Maybe special-case the string
"/dev/null"?
regards, tom lane
On 8/25/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
When I set HISTFILE to /dev/null I get the following:
could not save history to file "/dev/null": Operation not permittedHm. ktrace shows this happening:
23279 psql CALL open(0x302d70,0x601,0x1b6)
23279 psql NAMI "/dev/null"
23279 psql RET open 3
23279 psql CALL fchmod(0x3,0x180)
23279 psql RET fchmod -1 errno 1 Operation not permitted
23279 psql CALL close(0x3)
23279 psql RET close 0
23279 psql CALL write(0x2,0xbffff180,0x44)
23279 psql GIO fd 2 wrote 68 bytes
"could not save history to file "/dev/null": Operation not permitted
"
23279 psql RET write 68/0x44
23279 psql CALL exit(0)There's probably no way to get Apple's libedit to not try the fchmod,
so what do we want to do here? Maybe special-case the string
"/dev/null"?
If this is OK, I can up with a patch that special cases /dev/null as a
HISTFILE if libedit is found.
- Martin -
"Martin Atukunda" <matlads@gmail.com> writes:
On 8/25/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
There's probably no way to get Apple's libedit to not try the fchmod,
so what do we want to do here? Maybe special-case the string
"/dev/null"?
If this is OK, I can up with a patch that special cases /dev/null as a
HISTFILE if libedit is found.
I was thinking of basically a one-liner addition to write_history
to skip the whole thing if strcmp(fname, DEVNULL) == 0. Should be
reasonably inoffensive on anyone's machine.
regards, tom lane
On 8/25/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
"Martin Atukunda" <matlads@gmail.com> writes:
On 8/25/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
There's probably no way to get Apple's libedit to not try the fchmod,
so what do we want to do here? Maybe special-case the string
"/dev/null"?If this is OK, I can up with a patch that special cases /dev/null as a
HISTFILE if libedit is found.I was thinking of basically a one-liner addition to write_history
to skip the whole thing if strcmp(fname, DEVNULL) == 0. Should be
reasonably inoffensive on anyone's machine.
I guess you meant saveHistory instead of write_history here. :)
something like the attached diff
- Martin -
Attachments:
special_case_DEVNULL.diffapplication/octet-stream; name=special_case_DEVNULL.diffDownload
*** ./bin/psql/input.c.orig Fri Aug 25 20:30:55 2006
--- ./bin/psql/input.c Fri Aug 25 21:00:32 2006
***************
*** 342,347 ****
--- 342,351 ----
#ifdef USE_READLINE
if (useHistory && fname)
{
+ /* if fname was set to /dev/null just skip */
+ if (strcmp(fname, DEVNULL) == 0)
+ return true;
+
if (encodeFlag)
encode_history();