C functions, arguments, and ssh oh my!
От | Joel Dudley |
---|---|
Тема | C functions, arguments, and ssh oh my! |
Дата | |
Msg-id | A04BDD2C264AD41181C000508BDCB72A4F2B8A@USAZDOLEXCH0 обсуждение исходный текст |
Ответы |
Re: C functions, arguments, and ssh oh my!
Re: C functions, arguments, and ssh oh my! Re: C functions, arguments, and ssh oh my! |
Список | pgsql-general |
Hello All, I am writing my first C function for postgres and failing miserably. my C function needs to get passed a username (char) , uid(int), and gid(int) and what it does with those is builds a command string for an external app that is called with system() and exits 0. I know this is strange and ugly but I need to trigger this external app when an insert is made into a user table. I am looking into the version 1 calling convention to get these arguments into my C function but I can't seem to match the types correctly. I am looking at SPI with triggers now but I don't know if that will work either. Am I barking up the wrong tree here? any comments are appreciated and I appreciate the time you have taken to read my post. Below is to cludgy poor code I have so far (it doesnt work of course) and I am halfway between converting to version 1 calling but I wanted to give you an idea of what I am trying to do. Thanks again. - Joel #include <stdlib.h> #include "postgres.h" #include "fmgr.h" /*int *ssh_exec(char *uname[FILENAME_MAX], char *uid[FILENAME_MAX], char *gid[FILENAME_MAX])*/ PG_FUNCTION_INFO_V1(ssh_exec); Datum ssh_exec(PG_FUNCTION_ARGS) { char sshcmd[255]; strncpy(sshcmd, "/usr/local/bin/plsshexec ", 255); strncat(sshcmd, *uname, 255); strncat(sshcmd, " ", 255); strncat(sshcmd, *uid, 255); strncat(sshcmd, " ", 255); strncat(sshcmd, *gid, 255); system(sshcmd); return 0; }
В списке pgsql-general по дате отправления: