C Extension woes
От
Tim Hawes
Тема
C Extension woes
Дата
Msg-id
48A2BCD0.3030105@novadine.com
Список
Дерево обсуждения
C Extension woes Tim Hawes <thawes@novadine.com>
Re: C Extension woes Jan Urbański <j.urbanski@students.mimuw.edu.pl>
Re: C Extension woes Andrew Chernow <ac@esilo.com>
Re: C Extension woes Tom Lane <tgl@sss.pgh.pa.us>
Re: C Extension woes Tim Hawes <thawes@novadine.com>
Re: C Extension woes Jan Urbański <j.urbanski@students.mimuw.edu.pl>
Re: C Extension woes Tim Hawes <thawes@novadine.com>
Hello all,
I am trying to write an extension in C that returns a simple environment
variable. The code compiles without any complaint or warning, and it
loads fine into the database, however, when I run the function, I get
disconnected from the server.
Here is my C code:
#include
#include
PG_MODULE_MAGIC;
#include
#include
PG_FUNCTION_INFO_V1(pl_masterkey);
text * pl_masterkey(PG_FUNCTION_ARGS)
{ char *e_var = getenv("PGMASTERKEY"); size_t length = VARSIZE(e_var) - VARHDRSZ;
text * mkey = (text *) palloc(length); VARATT_SIZEP(mkey) = length; memcpy(VARDATA(mkey), e_var, length);
return mkey;
}
And here is the SQL I use to create the function in PostgreSQL:
CREATE FUNCTION pl_masterkey() RETURNS text AS 'pl_masterkey', 'pl_masterkey' LANGUAGE C STRICT;
And the results:
select pl_masterkey();
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.
!>
Thanks ahead of time for any and all help.
В списке pgsql-hackers по дате отправления