agora inbox for postgres@postgres.berkeley.edu  
help / color / mirror / Atom feed
From: Paul M. Aoki <aoki@cs.berkeley.edu>
To: N B Idris <Norbik.B.Idris@cm.cf.ac.uk>
Cc: postgres@postgres.Berkeley.EDU
Subject: Re: C functions
Date: Thu, 25 Aug 94 12:29:21 -0700
Message-ID: <199408251929.MAA25215@faerie.CS.Berkeley.EDU> (raw)
In-Reply-To: <9408251850.AA07744@diamond.cm.cf.ac.uk>

N B Idris <Norbik.B.Idris@cm.cf.ac.uk> 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
  aoki@CS.Berkeley.EDU  |  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 "postgres-request@postgres.Berkeley.EDU"

   If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
   a human will deal with it.  DO NOT post to the "postgres" mailing list.
==============================================================================



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: postgres@postgres.berkeley.edu
  Cc: aoki@cs.berkeley.edu, Norbik.B.Idris@cm.cf.ac.uk
  Subject: Re: C functions
  In-Reply-To: <199408251929.MAA25215@faerie.CS.Berkeley.EDU>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox