HowTo tell if from cmd_line || httpd

I

ipellew

Hi all;

Whats a sure fire way to tell I am executed from either httpd or
command line? At the moment, I decide on HTTP_USER_AGENT having a
value to say I am from httpd.
This needs to work whatever the platform / server.

Regards
Ian
 
A

Alan J. Flavell

Whats a sure fire way to tell I am executed from either httpd or
command line?

You can't, really, since anything you care to test could equally be
faked from the command line.
At the moment, I decide on HTTP_USER_AGENT having a
value to say I am from httpd.

There's no absolute mandate to set that to a non-null value, so I'd
have to advise against that...

Seems to me that the closest specified item to what you're
asking for would be the GATEWAY_INTERFACE :

http://cgi-spec.golux.com/draft-coar-cgi-v11-03-clean.html#6.1.4
This needs to work whatever the platform / server.

Indeed. If you'd suggested otherwise, you'd have found yourself
contradicted ;-)

GATEWAY_INTERFACE -is- a bona fide feature of the CGI specification,
right from way back: http://hoohoo.ncsa.uiuc.edu/cgi/env.html

Any so-called CGI interface which fails to provide it would be
seriously deficient. Of course, it could be faked from the command
line, as I mentioned before: but anyone who does that gets,
presumably, just what they asked for.
 
G

Gregory Toomey

Hi all;

Whats a sure fire way to tell I am executed from either httpd or
command line? At the moment, I decide on HTTP_USER_AGENT having a
value to say I am from httpd.
This needs to work whatever the platform / server.

Regards
Ian

You could do that, or use the following (may not work in some platforms):

sub batch() {
open(TTY, "/dev/tty");
return 0 if tcgetpgrp(fileno(*TTY)) == getpgrp();
return 1;
}

sub interactive {
return !batch();
}

gtoomey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top