undefined symbol in create new function

Started by Joel Dudleyabout 25 years ago3 messagesgeneral
Jump to latest
#1Joel Dudley
Joel.Dudley@DevelopOnline.com

Hello all,
I am back with my silly little snippet of code. When I try to create a
function with the following code compiled in to an .so:

#include <string.h>
#include <stdlib.h>
#include "postgres.h"
#include "fmgr.h"

PG_FUNCTION_INFO_V1(ssh_exec);

Datum
ssh_exec(PG_FUNCTION_ARGS)
{
char *uname = PG_GETARG_CHAR(0);
char *uid = PG_GETARG_CHAR(1);
char *gid = PG_GETARG_CHAR(2);
char sshcmd[255];

strncpy(sshcmd, "/usr/local/bin/plsshexec ", 255);
strncat(sshcmd, VARDATA(uname), VARSIZE(uname));
strncat(sshcmd, " ", 255);
strncat(sshcmd, VARDATA(uid), VARSIZE(uid));
strncat(sshcmd, " ", 255);
strncat(sshcmd, VARDATA(gid), VARSIZE(gid));
system(sshcmd);
return 0;

}

I get the following error:

undefined symbol PG_GETARG_CHAR

Is PG_GETARG_CHAR valid? I thought it was. maybe I should re-do it all with
PG_GETARG_TEXT. Thanks for reading my post.

- Joel

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Joel Dudley (#1)
Re: undefined symbol in create new function

Joel Dudley <Joel.Dudley@DevelopOnline.com> writes:

Is PG_GETARG_CHAR valid? I thought it was. maybe I should re-do it all with
PG_GETARG_TEXT. Thanks for reading my post.

Nope, neither one. See src/include/fmgr.h for the predefined GETARG
macros. You would also do well to read src/backend/utils/fmgr/README.

regards, tom lane

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#2)
Re: undefined symbol in create new function

Joel Dudley <Joel.Dudley@DevelopOnline.com> writes:

Thanks for your help. I had to clarify though, are you saying that it is
impossible to do what I am trying to do? Thank you for your time.

No, you just have to realize that Postgres string values are not
null-terminated and so you can't manipulate them with the usual C
library string functions that expect to work on null-terminated strings.
At least not unless you convert them to null-terminated form first.

Try studying some of the built-in text mashing functions. textcat()
and nearby routines in src/backend/utils/adt/varlena.c would be good
starting points.

regards, tom lane