On 12/11/07, Raymond Wan <[EMAIL PROTECTED]> wrote:
>
> Hi Xicheng,
>
> Xicheng Jia wrote:
> > On 12/11/07, Raymond Wan <[EMAIL PROTECTED]> wrote:
> >
> >> Hi all,
> >>
> >> I'm writing a Mason component which I want it to call another Perl
> >> script and not return from it.  That is, say I have component A:
> >>
> >>
> > in the webpage: http://perl.apache.org/docs/1.0/guide/performance.html
> >
> > search "Starting a Long Running External Program"
> >
> > There is a complete example for your case and the surrounding
> > materials are very informative. guess the leftove for you is just
> > porting them to mod_perl2..:) not a Mason problem though..
> >
> > Xicheng
> >
> >
>
> Thank you for your reply!   I forgot to mention that I did read that web
> page since the old posting that I cited [below] also has a link to it.
> However, I couldn't quite understand it and I wasn't sure how to port it
> to mod_perl2.
>
> Also, I didn't know that it wasn't a Mason problem and despite having
> worked with Mason for a few months, I still can't explain where modperl2
> ends and Mason begins.  i.e., I can install Mason and write components,
> but I couldn't write a paragraph explaining to a Mason-newbie when I
> should be looking at Mason documentation and when I should search
> modperl docs.  Very strange...I know.  Anyway, it seems I was wrong this
> time; sorry!!
>
> Ray

By reading that link, I suppose you can do something (in comp A) like:

<%once>
  use POSIX 'setsid';
  use Apache::SubProcess;
</%once>

<%init>
  $ENV{'PATH'} = '/bin:/usr/bin';
  delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

  $r->content_type("text/html");

  $SIG{CHLD} = 'IGNORE';

  $m->comp("B.mas");

  defined (my $kid = fork) or die "Cannot fork: $!\n";
  if ($kid) {
      # your normal Mason process goes here(parent, or itself)
      $m->comp("D.mas");
  } else {
      # external process goes here(child)
      $r->cleanup_for_exec(); # untie the socket
      chdir '/'                or die "Can't chdir to /: $!";
      open STDIN, '/dev/null'  or die "Can't read /dev/null: $!";
      open STDOUT, '>/dev/null'
          or die "Can't write to /dev/null: $!";
      open STDERR, '>&STDOUT'  or die "Can't dup stdout: $!";
      setsid or die "Can't start a new session: $!";

      exec "/path/to/C.pl" or die "Cannot execute exec: $!";
  }

</%init>
(untested)

You need to do some research to find a mod_perl2 equivalent to
Apache::SubProcess for the method $r->cleanup_for_exec to untie the
socket though.

"Advanced Programming in Unix Enviroment" chapter 8,9 contain much
useful infomation for you to read that link.

Also be caution when using fork under mod_perl enviroment, only do it
when you have to... read the section "Forking and Executing
Subprocesses from mod_perl" in that link.

Regards,
Xicheng

-------------------------------------------------------------------------
SF.Net email is sponsored by: 
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to