File access problem access(), stat()

From: vishal saberwal <vishalsaberwal(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: File access problem access(), stat()
Date: 2005-12-12 23:34:21
Message-ID: 3e74dc250512121534l626360e3te19ba7117449d972@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hi all,

I have read through the fmgr's readme but havent been able to solve my
problem with accessing the file.
I gave the permissions: [root(at)localhost /]# chmod 777-r /ResourceFS" and
have made sure the file i am trying to access does exist.

I am not sure where i am going wrong.

/*
gcc -Wall -I /root/postgresql-7.4.5/src/include -shared
-Wl,-soname,resource_test.so.1 -o resource_test.so resource_test.c
*/

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "/usr/include/pgsql/server/postgres.h"
#include "/usr/include/pgsql/server/fmgr.h"
#include "/usr/include/pgsql/server/libpq/pqformat.h"

Datum file_check(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(file_check);

Datum file_check(PG_FUNCTION_ARGS)
{
char *filecmd = (char*) PG_GETARG_VARCHAR_P(0);

int filelength=0;
struct stat stat_buf;

if(!access(filecmd,R_OK))
{
stat(filecmd, &stat_buf );
filelength=stat_buf.st_size;
}
return filelength;
}

xy_db=# create or replace function file_check(varchar) returns varchar as
xy_db-# '/root/resource_test.so','file_check' language 'c';
CREATE FUNCTION
k2_db=# select file_check('/ResourceFS/IconFS/Alarm/My.gif');
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
!> \q

thanks,
vish

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-12-12 23:47:15 Re: File access problem access(), stat()
Previous Message Tom Lane 2005-12-12 23:26:37 Re: Excessive vacuum times