Skip to content

Commit

Permalink
New Vend::Server::set_process_name sub which is used to change the st…
Browse files Browse the repository at this point in the history
…atus of

the process name indicator.  This respects the MV_DOLLAR_ZERO settings.
  • Loading branch information
pajamian committed Aug 12, 2007
1 parent d9b41d4 commit db5649c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 52 deletions.
3 changes: 3 additions & 0 deletions WHATSNEW-5.5
Expand Up @@ -120,6 +120,9 @@ Core
* Pass applylocale option into Vend::Form::options_to_array in order to
localize option labels (#80).

* New set_process_name sub which is used to change the status in the process
name indicator.

UserDB
------

Expand Down
20 changes: 10 additions & 10 deletions lib/Vend/Dispatch.pm
@@ -1,6 +1,6 @@
# Vend::Dispatch - Handle Interchange page requests
#
# $Id: Dispatch.pm,v 1.85 2007-08-10 08:42:09 pajamian Exp $
# $Id: Dispatch.pm,v 1.86 2007-08-12 07:00:43 pajamian Exp $
#
# Copyright (C) 2002-2007 Interchange Development Group
# Copyright (C) 2002 Mike Heins <mike@perusion.net>
Expand All @@ -26,7 +26,7 @@
package Vend::Dispatch;

use vars qw($VERSION);
$VERSION = substr(q$Revision: 1.85 $, 10);
$VERSION = substr(q$Revision: 1.86 $, 10);

use POSIX qw(strftime);
use Vend::Util;
Expand Down Expand Up @@ -1215,12 +1215,12 @@ sub dispatch {
## If returns false then was a 404 no catalog or a delivered image
open_cat() or return 1;

$0 = "interchange: $Vend::Cat $CGI::host";
Vend::Server::set_process_name("$Vend::Cat $CGI::host");

$CGI::user = Vend::Util::check_authorization($CGI::authorization)
if defined $CGI::authorization;

my($sessionid, $seed);
my($sessionid, $seed);

$sessionid = $CGI::values{mv_session_id} || undef
and $sessionid =~ s/\0.*//s;
Expand Down Expand Up @@ -1262,7 +1262,7 @@ sub dispatch {
$Vend::CookieID = $Vend::Cookie = 1;
}

$0 = "interchange: $Vend::Cat $CGI::host $sessionid";
Vend::Server::set_process_name("$Vend::Cat $CGI::host $sessionid");

$::Instance->{CookieName} = 'MV_SESSION_ID' if ! $::Instance->{CookieName};

Expand Down Expand Up @@ -1462,7 +1462,7 @@ EOF

$Vend::Session->{'user'} = $CGI::user;

$0 = "interchange: $Vend::Cat $CGI::host $sessionid " . $Vend::Session->{username} || '-';
Vend::Server::set_process_name("$Vend::Cat $CGI::host $sessionid " . $Vend::Session->{username} || '-');

$CGI::pragma = 'no-cache'
if delete $::Scratch->{mv_no_cache};
Expand All @@ -1478,12 +1478,12 @@ EOF
if delete $Vend::Session->{one_time_path_alias}{$Vend::FinalPath};
}

url_history($Vend::FinalPath) if $Vend::Cfg->{History};
url_history($Vend::FinalPath) if $Vend::Cfg->{History};

$0 = "interchange: $Vend::Cat $CGI::host $sessionid " . ($Vend::Session->{username} || '-') . " $Vend::FinalPath";
Vend::Server::set_process_name("$Vend::Cat $CGI::host $sessionid " . ($Vend::Session->{username} || '-') . " $Vend::FinalPath");

# TRACK
$Vend::Track = new Vend::Track
$Vend::Track = new Vend::Track
if $Vend::Cfg->{UserTrack} and not ($Vend::admin and ! $::Variable->{MV_TRACK_ADMIN});
# END TRACK

Expand Down Expand Up @@ -1712,7 +1712,7 @@ EOF

close_cat();

$0 = 'interchange: done';
Vend::Server::set_process_name('done');

undef $H;

Expand Down
67 changes: 45 additions & 22 deletions lib/Vend/Server.pm
@@ -1,6 +1,6 @@
# Vend::Server - Listen for Interchange CGI requests as a background server
#
# $Id: Server.pm,v 2.79 2007-08-10 16:59:25 jon Exp $
# $Id: Server.pm,v 2.80 2007-08-12 07:00:43 pajamian Exp $
#
# Copyright (C) 2002-2007 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
Expand All @@ -26,7 +26,7 @@
package Vend::Server;

use vars qw($VERSION);
$VERSION = substr(q$Revision: 2.79 $, 10);
$VERSION = substr(q$Revision: 2.80 $, 10);

use Cwd;
use POSIX qw(setsid strftime);
Expand Down Expand Up @@ -872,40 +872,40 @@ sub read_cgi_data {
sub connection {
my (%env, $entity);

my $show_in_ps = shift;
my $show_in_ps = shift;

$0 = 'interchange: connection';
set_process_name('connection');

### This resets all $Vend::variable settings so we start
### completely initialized. It only affects the Vend package,
### not any Vend::XXX packages.
reset_vars();
### This resets all $Vend::variable settings so we start
### completely initialized. It only affects the Vend package,
### not any Vend::XXX packages.
reset_vars();

if($Global::ShowTimes) {
@Vend::Times = times();
::logDebug ("begin connection. Summary time set to zero");
}
if($Global::ShowTimes) {
@Vend::Times = times();
::logDebug ("begin connection. Summary time set to zero");
}
read_cgi_data(\@Global::argv, \%env, \$entity)
or return 0;
show_times('end cgi read') if $Global::ShowTimes;

my $http = new Vend::Server \*MESSAGE, \%env, \$entity;

# Can log all CGI inputs
log_http_data($http) if $Global::Logging;
# Can log all CGI inputs
log_http_data($http) if $Global::Logging;

$0 = 'interchange: dispatch';
set_process_name('dispatch');

show_times("begin dispatch") if $Global::ShowTimes;
show_times("begin dispatch") if $Global::ShowTimes;
::dispatch($http) if $http;
show_times("end connection") if $Global::ShowTimes;
close $http->{rfh} if $http->{rfh};
undef $Vend::Cfg;
show_times("end connection") if $Global::ShowTimes;
close $http->{rfh} if $http->{rfh};
undef $Vend::Cfg;

my $display = 'interchange: done';
$display .= "($show_in_ps)" if $show_in_ps;
my $display = 'done';
$display .= "($show_in_ps)" if $show_in_ps;

$0 = $display;
set_process_name($display);
}

## Signals
Expand Down Expand Up @@ -2992,6 +2992,29 @@ sub run_server {
}
}

# Set the process name ($0) according to MV_DOLLAR_ZERO and a status indicator.
sub set_process_name {
my $status = shift;
my $base = $Global::Variable->{MV_DOLLAR_ZERO};

# BSD hack which allows us to set MV_DOLLAR_ZERO to '0' to prevent Interchange
# from changing it (and dumping core on FreeBSD 4 stock perl).
return if defined $base && $base eq '0';

# Setting MV_DOLLAR_ZERO to 1 should do the same thing as not setting it for
# backwards compatibility.
$base = 'interchange' if !$base or $base eq '1';

if (defined $status) {
$0 = "$base: $status";
}
else {
$0 = $base;
}

return;
}


1;
__END__
Expand Down
28 changes: 8 additions & 20 deletions scripts/interchange.PL
Expand Up @@ -3,7 +3,7 @@
#
# Interchange version 5.5.0
#
# $Id: interchange.PL,v 2.96 2007-08-09 13:40:57 pajamian Exp $
# $Id: interchange.PL,v 2.97 2007-08-12 07:00:43 pajamian Exp $
#
# Copyright (C) 2002-2007 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
Expand Down Expand Up @@ -957,30 +957,18 @@ EOF
# Set $0 to something pretty for ps(1).
# Won't work on Solaris and IRIX among possibly others.
# Dumps core on FreeBSD 4 stock Perl build.
if (defined $Global::Variable->{MV_DOLLAR_ZERO}) {
if ($Global::Variable->{MV_DOLLAR_ZERO}) {
if (length($Global::Variable->{MV_DOLLAR_ZERO}) > 1) {
$0 = $Global::Variable->{MV_DOLLAR_ZERO};
}
else {
$0 = "interchange --> $Global::VendRoot";
}
}
# do nothing if MV_DOLLAR_ZERO is defined but false
}
else {
$0 = 'interchange';
}
# This is all done in Vend::Server::set_process_name now.
Vend::Server::set_process_name($Global::VendRoot);

# We won't have much output on any of this, but if we get some
# we want it immediately
select STDERR;
$| = 1;
select STDOUT;
$| = 1;
select STDERR;
$| = 1;
select STDOUT;
$| = 1;

# This should never return unless killed or a catastrophic error
Vend::Server::run_server();
Vend::Server::run_server();
}
elsif($Vend::mode eq 'test') {
# Blank by design, this option only tests config files
Expand Down

0 comments on commit db5649c

Please sign in to comment.