0

I have perl script which gets spawned from a cgi page and becomes a daemon process running on its own. If there is a die called from any module it is using, the script is getting called although it has been handled in eval block. Though, when I am running the script from the command prompt, everything is fine and the error is getting handled.

Note: From the command line also the script is becoming a daemon

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Kallol
  • 302
  • 4
  • 16
  • correction : If there is a die called from any module it is using, the script is getting killed although it has been handled in eval block. – Kallol Dec 09 '11 at 14:12

1 Answers1

0

Sorry, no real answer here, but some things to look into...

If you're spawning a job from mod_perl remember its more complicated than usual. You need to close the file descriptors, httpd/mod_perl will have more than just 0, 1, and 2 open. We ended up writing a loops which just closed 0 through 255. Also I think stdout is not 1 from memory.

But not sure why eval would not be working. Are you spawning you script using exec? In which case it should be the same as running it from the shell. When you say its "getting killed" do you mean the die is causing the scirpt to exit (as if there was no eval)? Or something else. If its something else could you possibly be inheriting signal handlers from the httpd process which mod_perl is running in?

Sodved
  • 8,428
  • 2
  • 31
  • 43
  • stdin, stdout, and stderr are file descriptors 0, 1, and 2, respectively – Keith Thompson Dec 10 '11 at 03:46
  • For calling the script from the cgi I have used system call.. system("script_to_daemonize"); In the script I have daemonized it like: my $pid; if ($pid = fork()) { exit 0; } fatal("Couldn't fork!: $!") unless defined $pid; ## trying to set independent session setsid() != -1 or fatal("Couldn't setsid(): $!\n"); $pid = fork and exit; fatal("Couldn't fork!: $!") unless defined $pid; – Kallol Dec 10 '11 at 17:35
  • That looks fine, sorry no idea what your issue is then. – Sodved Dec 11 '11 at 08:02