[rrd-users] Re: stdout with mod_perl and rrdtool

Todd Caine todd_caine at eli.net
Fri Sep 8 18:16:34 MEST 2000


Hello,

  I've experienced this behavior as well.  It is definitely lame that you have to
create temporary files to make it work.  I've had to resort to the following code
in my handler to make this happen:

  $fh = new FileHandle "< $tmp_name";

  unless ($fh) {
    $r->log_error("Couldn't open temporary file $tmp_name: $!");
    return SERVER_ERROR;
  }

  $r->send_fd($fh);
  unlink $tmp_name;
  return OK;

I've been trying to find a way to make this more efficient.  I would really like
to be able to send the output of RRDs::graph('-', ...) to the client's file
descriptor without the use of creating and unlinking files.  The only response I
received after posting this problem to rrd-user, rrd-developers, and the mod_perl
mailing lists was from Doug MacEachern.  Here is the what Doug said:

On Wed, 2 Aug 2000, Todd Caine wrote:

> > STDOUT is where $r->print goes under mod_perl; you should be OK.
>
> The data that is printed out via $r->print is on the file descriptor that the
> http request is set up on.  If the HTTP request came in on file descriptor 3
> then $r->print('foo') prints to file descriptor 3; not stdout(file descriptor
> 1, on my system).

right, Perl STDOUT != C stdout

> The only way I can get part of gif to the browser was to do this:
>
> my $c = $r->connection;
> my $fd_num = $c->fileno(0);
> open(STDOUT, ">&$fd_num");
> RRDs::graph($args);
>
> But the data is incomplete.  Even when I autoflush the $fd_num.
> There has got to be a better way.....

see Apache::Magick in the eagle book or at modperl.com.  it's still ugly
since it writes to a tmpfile, but it works.  you can also modify your c
sources to redfine stdout-ish calls, Apache::Peek does something like that
for redirecting stderr to the client socket:

#define PerlIO request_rec
#define PerlIO_printf rprintf
#define PerlIO_vprintf(r,fmt,vlist) \
 vbprintf(r->connection->client, fmt, vlist)
#define PerlIO_stderr() perl_request_rec(NULL)
#define PerlIO_putc(r,c) rputc(c,r)
#define PerlIO_puts(r,s) rputs(s,r)


I don't know if this will help anyone, since most of us are using Perl instead of
C to write apache handlers.  Please let me know if you find a solution.  Thanks.

todd


Philip Molter wrote:

> On Fri, Sep 08, 2000 at 03:42:23PM +0300, Osmo Paananen wrote:
> :
> : Hi!
> :
> : I'm using rrdtool as perl shared module with mod_perl.
> :
> : It seems that if I supply "-" as the name of the output graph name
> : the data won't end up to the socket returned by apache.
> :
> : If I run the perl script as CGI then all works fine.
> :
> : If I run apache with -X flag, I get the PNG I wanted to
> : the window where I started the server.
> :
> : I'm not fully aware whose problem this is.  Should I blame apache, mod_perl
> : or rrdtool?
>
> Blame both mod_perl and rrdtool.  Don't blame Apache.  It's an
> innocent bystander.  My details may be a bit sketchy, but the gist
> of it is this:
>
> mod_perl reopens STDOUT on an anonymous file descriptor (if you
> look at a truss of a mod_perl-httpd process, you'll notice that
> what's being sent to your web browser is usually on fd 6, 7, etc.).
> The perl rrd functions use the rrd c functions/libraries to do
> their work, and it appears they're printing directly to fd 1, which
> as we all know, is what STDOUT /should/ be.
>
> There's two fixes.  One, remap file descriptor 1 to mod_perl's
> STDOUT fd in your perl script (more trouble, IMO).  Two, print the
> image to a temporary file, open it, print it, close it, unlink it
> (less trouble, IMO).  We use the second option in the office and
> it works quite well.
>
> * Philip Molter
> * DataFoundry.net
> * http://www.datafoundry.net/
> * philip at datafoundry.net
>
> --
> Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
> Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
> Archive     http://www.ee.ethz.ch/~slist/rrd-users
> WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi

--
--------------------------------------------------------------

 <!-- Todd Caine - tcaine at eli.net
  Software Engineer
  Electric Lightwave, Inc.
  4400 NE 77th Avenue
  Vancouver, WA 98662
  Direct Dial: (360) 816-4344  //-->

--------------------------------------------------------------



--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list