Skip to content
This repository
tree: bde37b0d84
Fetching contributors…

Cannot retrieve contributors at this time

file 202 lines (174 sloc) 5.078 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
# Vend::Control - Routines that alter the running Interchange daemon
#
# $Id: Control.pm,v 2.3 2002-06-27 22:24:10 jon Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
# This program was originally based on Vend 0.2 and 0.3
# Copyright 1995 by Andrew M. Wilcox <amw@wilcoxsolutions.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA.

package Vend::Control;

require Exporter;
@ISA = qw/ Exporter /;
@EXPORT = qw/
signal_reconfig
signal_add
signal_remove
control_interchange
change_catalog_directive
change_global_directive
remove_catalog
add_catalog
/;

use strict;
use Vend::Util;

sub signal_reconfig {
my (@cats) = @_;
for(@cats) {
my $ref = $Global::Catalog{$_}
or die ::errmsg("Unknown catalog '%s'. Stopping.\n", $_);
Vend::Util::writefile("$Global::RunDir/reconfig", "$ref->{script}\n");
}
}

sub signal_remove {
shift;
$Vend::mode = 'reconfig';
my $cat = shift;
Vend::Util::writefile("$Global::RunDir/restart", "remove catalog $cat\n");
control_interchange('remove', 'HUP');
}

sub signal_add {
$Vend::mode = 'reconfig';
Vend::Util::writefile("$Global::RunDir/restart", <>);
control_interchange('add', 'HUP');
}

sub control_interchange {
my ($mode, $sig, $restart) = @_;

$Vend::ControllingInterchange = 1;
unless(-f $Global::PIDfile) {
warn errmsg(
"The Interchange server was not running (%s).\n",
$Global::PIDfile,
) unless $Vend::Quiet;
exit 1 unless $restart;
return;
}
my $pidh = Vend::Server::open_pid()
or die errmsg(
"Couldn't open PID file %s: %s\n",
$Global::PIDfile,
$!,
);
my $pid = Vend::Server::grab_pid($pidh);
if(! $pid) {
warn errmsg(<<EOF);
The previous Interchange server was not running and probably
terminated with an error.
EOF
return if $restart;
}
if(! $sig) {
$sig = $mode ne 'kill' ? 'TERM' : 'KILL';
}
print "Killing Interchange server $pid with $sig.\n"
unless $Vend::Quiet;
kill $sig, $pid
or die errmsg("Interchange server would not stop.\n");
exit 0 unless $restart;
}

sub remove_catalog {
my($name) = @_;
my $g = $Global::Catalog{$name};
my @aliases;

unless(defined $g) {
::logGlobal( {level => 'error'}, "Attempt to remove non-existant catalog %s." , $name );
return undef;
}

if($g->{alias}) {
@aliases = @{$g->{alias}};
}

for(@aliases) {
delete $Global::Selector{$_};
delete $Global::SelectorAlias{$_};
}

delete $Global::Selector{$g->{script}};
delete $Global::Catalog{$name};
logGlobal("Removed catalog %s (%s)", $name, $g->{script});
}


sub add_catalog {
my($line) = @_;
$line =~ s/^\s+//;
my ($var, $name, $val) = split /\s+/, $line, 3;
Vend::Config::parse_catalog($var,"$name $val")
or die "Bad catalog line '$line'\n";

my $g = $Global::Catalog{$name}
or die "Catalog '$name' not parsed.\n";

my $c = $Global::Selector{$g->{script}} ||
$Global::SelectorAlias{$g->{script}} ||
{};

$c->{CatalogName} = $name;

my $dir = $g->{'dir'};
my $script = $g->{'script'};

if(defined $g->{'alias'}) {
for(@{$g->{alias}}) {
if (exists $Global::Selector{$_}
and $Global::SelectorAlias{$_} ne $g->{'script'})
{
logGlobal({level => 'notice'}, "Catalog ScriptAlias %s used a second time, skipping.", $_);
next;
}
elsif (m![^-\w_\~:#/.]!) {
logGlobal( "Bad alias %s, skipping.", $_,);
}
$Global::Selector{$_} = $c;
$Global::SelectorAlias{$_} = $g->{'script'};
}
}

Vend::Util::writefile("$Global::RunDir/reconfig", "$script\n");
my $msg = <<EOF;
Added/changed catalog %s:

Directory: %s
Script: %s
EOF

logGlobal({level => 'notice'}, $msg, $name, $dir, $script);

$Global::Selector{$g->{script}} = $c;
}

sub change_catalog_directive {
my($cat, $line) = @_;
$line =~ s/^\s+//;
my($dir,$val) = split /\s+/, $line, 2;
my $ref = Vend::Config::set_directive($dir,$val);
die "Bad directive '$line'.\n" unless defined $ref;
$cat->{$ref->[0]} = $ref->[1];
return 1;
}

sub change_global_directive {
my($line) = @_;
chomp $line;
$line =~ s/^\s+//;
my($dir,$val) = split /\s+/, $line, 2;
my $ref = Vend::Config::set_directive($dir,$val,1);
die "Bad directive '$line'.\n" unless defined $ref;
no strict 'refs';
${"Global::" . $ref->[0]} = $ref->[1];
$Global::Structure->{$ref->[0]} = $ref->[1]
if $Global::DumpStructure;

dump_structure($Global::Structure, "$Global::RunDir/$Global::ExeName")
if $Global::DumpStructure;
return 1;
}

1;
Something went wrong with that request. Please try again.