Subject: Re: C functions

From: [email-masked] (Paul M. Aoki)
Date: Thu, 25 Aug 94 12:29:21 -0700

N B Idris <[email-masked]> writes:
> In writing a user defined C function which is callable via a define
> function command, can we have within the C function :
> 	a) Basic I/O functions such as scanf/printf?

sure, but the input/output are generally connected to /dev/null.

(think about it.  the backend server is running on some machine X.
your frontend program is (in general) running on some machine Y..)

if you need a message printed to the user process, include
"utils/log.h" and do something like:
	elog(NOTICE, "hello world from server process %d", getpid());

you can also redirect the standard output of the backends to a file or
tty using the backend's -o option, which can be set using the
postmaster's -o option, using something like:
	postmaster -o '-o /dev/ttyp2'

> 	b) System calls eg. system("shelltool routine2");
> 	   where parameter "routine2" is another executable program to be 
> 	   invoked within the new shelltool called?

first, system(3) starts /bin/sh.  if either "shelltool" or "routine2"
is not in the default path then the call won't work.

so now, just for the sake of argument, say you use:
	system("/bin/shelltool /what/ever/the/path/is/routine2");
the old suntools routines would only work on the local machine and
would require a bunch of stupid environment variables (like WINDOWID)
to be set.  if the "postgres" user that started the postmaster did not
have the right environment (i.e., it was not started by you during
this login session), then shelltool can't start.  (remember, *you*
aren't starting up the backend process with your shell as the parent
process.  the "postgres" user is, and in fact, the postmaster started
by some random person during some random login session is the parent
process.  hence the environment will not generally be right.  fixing
this is specific to your user environment..)

now, say you use X11.  the server is running as "postgres" on machine
X. you are running as you on machine Y.  if X != Y, and you are using
xhost(1), then you will have a problem.  if you are using XAUTHORITY,
you have a bigger problem.

btw, both of these issues (i.e., correct search paths for subprocesses
and correct environments/permissions for window system processes) are
completely orthogonal from postgres.  any server (postgres, ftpd)
started by some daemon process (postmaster, inetd) would face the same
issues.  your local system gurus would probably be more help than
anyone on this mailing list..
--
  Paul M. Aoki          |  University of California at Berkeley
  [email-masked]  |  Dept. of EECS, Computer Science Division (#1776) 
                        |  Berkeley, CA 94720-1776

==============================================================================
   To add/remove yourself to/from the POSTGRES mailing list: send mail with 
   the subject line ADD or DEL to "[email-masked]"

   If this fails, send mail to "[email-masked]" and
   a human will deal with it.  DO NOT post to the "postgres" mailing list.
==============================================================================