Обсуждение: cant write to file within call handler interface

Поиск
Список
Период
Сортировка

cant write to file within call handler interface

От
Sibtay Abbas
Дата:
hello

i am not able to write to file until the pl call
handler interface. this is the template which i am
following

PG_FUNCTION_INFO_V1(my_call_handler);

Datum
my_call_handler(PG_FUNCTION_ARGS)
{...my code...
int fd = open("filename",O_WRONLY);write(fd,buffer,strlen(buffer) + 1);
//fsync(fd).......i tried this as well but                   did'nt work

}


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Re: cant write to file within call handler interface

От
Michael Fuhr
Дата:
On Tue, Dec 14, 2004 at 10:31:41AM -0800, Sibtay Abbas wrote:

> i am not able to write to file until the pl call
> handler interface.

What are you expecting to happen and what actually does happen?
Saying only "it doesn't work" doesn't give us much to go on.

> this is the template which i am following
> 
> PG_FUNCTION_INFO_V1(my_call_handler);
> 
> Datum
> my_call_handler(PG_FUNCTION_ARGS)
> {
>     ...my code...
> 
>     int fd = open("filename",O_WRONLY);
>     write(fd,buffer,strlen(buffer) + 1);
> 
>     //fsync(fd).......i tried this as well but           
>          did'nt work
> 
> }

A simple but complete example would be helpful so we can see
everything you're doing; the parts of the code that you don't show
could be relevant to the problem.  Reducing the problem to the
smallest possible example can also help you find where the mistake
is by eliminating where it isn't.

You show no error checking.  Check the return value of all functions
that can fail and use ereport() or elog() to report any failures.
You also don't show where buffer comes from, so we don't know if
its contents are a problem or not.  And is "filename" the actual
name in your code?  Where are you expecting that file to be?

Some programming mistakes can be spotted by the compiler.  Turn on
as many compiler warnings as you can.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


Re: cant write to file within call handler interface

От
Tom Lane
Дата:
Sibtay Abbas <sibtay_abbas@yahoo.com> writes:
> i am not able to write to file until the pl call
> handler interface. this is the template which i am
> following

> PG_FUNCTION_INFO_V1(my_call_handler);

> Datum
> my_call_handler(PG_FUNCTION_ARGS)
> {
>     ...my code...

>     int fd = open("filename",O_WRONLY);
>     write(fd,buffer,strlen(buffer) + 1);

Perhaps a little bit of checking for error returns would reveal the
problem.  Other theories are (a) you forgot to close the file so no
write occurred; (b) the file was written but not where you think because
the filename is relative to the backend's working directory.
        regards, tom lane