Unix Technical Forum

psql -f doesn't complain about directories

This is a discussion on psql -f doesn't complain about directories within the pgsql Hackers forums, part of the PostgreSQL category; --> Letting psql execute a script file that is really a directory doesn't complain at all: $ psql -f /tmp ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-15-2008, 10:33 PM
Peter Eisentraut
 
Posts: n/a
Default psql -f doesn't complain about directories

Letting psql execute a script file that is really a directory doesn't complain
at all:

$ psql -f /tmp

Should we do some kind of stat() before opening the file and abort if it's a
directory?

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-15-2008, 10:33 PM
Alvaro Herrera
 
Posts: n/a
Default Re: psql -f doesn't complain about directories

Peter Eisentraut wrote:
> Letting psql execute a script file that is really a directory doesn't complain
> at all:
>
> $ psql -f /tmp
>
> Should we do some kind of stat() before opening the file and abort if it's a
> directory?


Actually anything other than a plain file, right? (Do we really want to
be able to psql -f a_pipe?)

--
Alvaro Herrera Developer, http://www.PostgreSQL.org/
Essentially, you're proposing Kevlar shoes as a solution for the problem
that you want to walk around carrying a loaded gun aimed at your foot.
(Tom Lane)

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-15-2008, 10:33 PM
Andrew Dunstan
 
Posts: n/a
Default Re: psql -f doesn't complain about directories



Alvaro Herrera wrote:
> Peter Eisentraut wrote:
>
>> Letting psql execute a script file that is really a directory doesn't complain
>> at all:
>>
>> $ psql -f /tmp
>>
>> Should we do some kind of stat() before opening the file and abort if it's a
>> directory?
>>

>
> Actually anything other than a plain file, right? (Do we really want to
> be able to psql -f a_pipe?)
>


I don't see why not.

cheers

andrew

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

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-15-2008, 10:33 PM
Martijn van Oosterhout
 
Posts: n/a
Default Re: psql -f doesn't complain about directories

On Wed, Nov 14, 2007 at 05:15:20PM -0300, Alvaro Herrera wrote:
> > Should we do some kind of stat() before opening the file and abort if it's a
> > directory?

>
> Actually anything other than a plain file, right? (Do we really want to
> be able to psql -f a_pipe?)


Sure, why not. To be honest I think that psql shouldn't be ignoring the
EISDIR error the kernel is returning.

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> Those who make peaceful revolution impossible will make violent revolution inevitable.
> -- John F Kennedy


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFHO1hdIB7bNG8LQkwRAmvHAKCBuRblr2cj4gP5mURmgv W7SzbdIgCeOzSV
zA2KmSf8nkkGwvSSrfzM+L0=
=zeV7
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-15-2008, 10:33 PM
Zdenek Kotala
 
Posts: n/a
Default Re: psql -f doesn't complain about directories

Martijn van Oosterhout wrote:
> On Wed, Nov 14, 2007 at 05:15:20PM -0300, Alvaro Herrera wrote:
>>> Should we do some kind of stat() before opening the file and abort if it's a
>>> directory?

>> Actually anything other than a plain file, right? (Do we really want to
>> be able to psql -f a_pipe?)

>
> Sure, why not. To be honest I think that psql shouldn't be ignoring the
> EISDIR error the kernel is returning.


But it works when you open directory in read-only mode. See posix
definition:

[EISDIR]
The named file is a directory and oflag includes O_WRONLY or O_RDWR.


Zdenek

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-15-2008, 10:33 PM
Zdenek Kotala
 
Posts: n/a
Default Re: psql -f doesn't complain about directories

Alvaro Herrera wrote:
> Peter Eisentraut wrote:
>> Letting psql execute a script file that is really a directory doesn't complain
>> at all:
>>
>> $ psql -f /tmp
>>
>> Should we do some kind of stat() before opening the file and abort if it's a
>> directory?

>
> Actually anything other than a plain file, right? (Do we really want to
> be able to psql -f a_pipe?)
>


What's about symlink to regular file/pipe?


Zdenek

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-15-2008, 10:33 PM
Martijn van Oosterhout
 
Posts: n/a
Default Re: psql -f doesn't complain about directories

On Wed, Nov 14, 2007 at 09:33:17PM +0100, Zdenek Kotala wrote:
> >Sure, why not. To be honest I think that psql shouldn't be ignoring the
> >EISDIR error the kernel is returning.

>
> But it works when you open directory in read-only mode. See posix
> definition:
>
> [EISDIR]
> The named file is a directory and oflag includes O_WRONLY or O_RDWR.


$ strace psql -f /tmp
<snip>
open("/tmp", O_RDONLY|O_LARGEFILE) = 4
<snip>
read(4, 0xb7f1b000, 4096) = -1 EISDIR (Is a directory)

Which is subsequently ignored. I'm hoping it doesn't ignore other
errors, like EIO or EPIPE,

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> Those who make peaceful revolution impossible will make violent revolution inevitable.
> -- John F Kennedy


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFHO2TcIB7bNG8LQkwRAhSnAJ9BPrysgeDs9HvQjE7q1G ZE1avHVACfQ+hf
QtHlAYy8xbtTE7UMJshruaI=
=zaGL
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-15-2008, 10:33 PM
Peter Eisentraut
 
Posts: n/a
Default Re: psql -f doesn't complain about directories

Martijn van Oosterhout wrote:
> To be honest I think that psql shouldn't be ignoring the
> EISDIR error the kernel is returning.


We use fopen(), which doesn't appear to pass that on.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-15-2008, 10:33 PM
Martijn van Oosterhout
 
Posts: n/a
Default Re: psql -f doesn't complain about directories

On Wed, Nov 14, 2007 at 10:25:23PM +0100, Peter Eisentraut wrote:
> Martijn van Oosterhout wrote:
> > To be honest I think that psql shouldn't be ignoring the
> > EISDIR error the kernel is returning.

>
> We use fopen(), which doesn't appear to pass that on.


It's not the fopen that fails, it's the fgets that returns NULL. We
don't subsequently check if that's due to an I/O error or EISDIR or if
it's an end-of-file.

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> Those who make peaceful revolution impossible will make violent revolution inevitable.
> -- John F Kennedy


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFHO2u8IB7bNG8LQkwRApXJAJ0ZNrJ1ObBaAv6z55IsNY yozuDHugCfVTSG
kIxyuHYwromenEYrKLRQ9eE=
=B1We
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-15-2008, 10:33 PM
David Fetter
 
Posts: n/a
Default Re: psql -f doesn't complain about directories

On Wed, Nov 14, 2007 at 05:15:20PM -0300, Alvaro Herrera wrote:
> Peter Eisentraut wrote:
> > Letting psql execute a script file that is really a directory
> > doesn't complain at all:
> >
> > $ psql -f /tmp
> >
> > Should we do some kind of stat() before opening the file and abort
> > if it's a directory?

>
> Actually anything other than a plain file, right? (Do we really
> want to be able to psql -f a_pipe?)


Yes, I have seen people use just this technique.

Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:42 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com